Changeset - 31284ec8ec2c
[Not reviewed]
default
0 1 0
Ethan Zonca - 10 years ago 2014-09-03 22:45:13
ez@ethanzonca.com
Added setpoint saving. Need to do modification checks to reduce number of writes.
1 file changed with 42 insertions and 14 deletions:
main.c
42
14
0 comments (0 inline, 0 general)
main.c
Show inline comments
 
@@ -29,6 +29,9 @@ uint16_t k_p = 1;
 
uint16_t k_i = 1;
 
uint16_t k_d = 1;
 
 
int16_t setpoint_brew = 0;
 
int16_t setpoint_steam = 0;
 
 
// State definition
 
enum state {
 
    STATE_IDLE = 0,
 
@@ -57,6 +60,7 @@ void machine();
 
void delay(__IO uint32_t nTime);
 
void restore_settings();
 
void save_settings();
 
void save_setpoints();
 
 
int main(void)
 
{
 
@@ -307,6 +311,10 @@ uint16_t k_d = 1;*/
 
#define EEPROM_ADDR_K_I			0x8080028
 
#define EEPROM_ADDR_K_D			0x808002C
 
 
#define EEPROM_ADDR_BREWTEMP		0x8080030
 
#define EEPROM_ADDR_STEAMTEMP		0x8080034
 
 
 
void save_settings()
 
{
 
    DATA_EEPROM_Unlock();
 
@@ -317,8 +325,15 @@ void save_settings()
 
    DATA_EEPROM_ProgramWord(EEPROM_ADDR_K_I, k_i);
 
    DATA_EEPROM_ProgramWord(EEPROM_ADDR_K_D, k_d);
 
    DATA_EEPROM_Lock();
 
}
 
void save_setpoints()
 
{
 
    DATA_EEPROM_Unlock();
 
    DATA_EEPROM_ProgramWord(EEPROM_ADDR_BREWTEMP, setpoint_brew);
 
    DATA_EEPROM_ProgramWord(EEPROM_ADDR_STEAMTEMP, setpoint_steam); 
 
    DATA_EEPROM_Lock();
 
}
 
 
}
 
 
// TODO: Save/restore temperature setpoint settings
 
void restore_settings()
 
@@ -339,6 +354,12 @@ void restore_settings()
 
    while(FLASH_GetStatus()==FLASH_BUSY);
 
    k_d = (*(__IO uint32_t*)EEPROM_ADDR_K_D);
 
    
 
    while(FLASH_GetStatus()==FLASH_BUSY);
 
    setpoint_brew = (*(__IO uint32_t*)EEPROM_ADDR_BREWTEMP);
 
 
    while(FLASH_GetStatus()==FLASH_BUSY);
 
    setpoint_steam = (*(__IO uint32_t*)EEPROM_ADDR_STEAMTEMP);    
 
    
 
    DATA_EEPROM_Lock();
 
}
 
 
@@ -591,16 +612,18 @@ void machine()
 
            ssd1306_drawlogo();
 
            draw_setpoint();
 
            pid_enabled = 1;
 
	    setpoint = setpoint_brew;
 
 
            // Button handler
 
            if(SW_BTN_PRESSED) {
 
		save_setpoints(); // TODO: Check for mod
 
                state = STATE_IDLE;
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_UP)) {
 
               setpoint++; 
 
               setpoint_brew++; 
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_DOWN) && setpoint > 0) {
 
                setpoint--;
 
            else if(!GPIO_ReadInputDataBit(SW_DOWN) && setpoint_brew > 0) {
 
                setpoint_brew--;
 
            }
 
 
 
@@ -620,16 +643,18 @@ void machine()
 
            ssd1306_drawlogo();
 
            draw_setpoint();
 
            pid_enabled = 1;
 
	    setpoint = setpoint_brew;
 
 
            // Button handler
 
            if(SW_BTN_PRESSED) {
 
		save_setpoints(); // TODO: Check for mod
 
                state = STATE_IDLE;
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_UP)) {
 
               setpoint++; 
 
               setpoint_brew++; 
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_DOWN) && setpoint > 0) {
 
                setpoint--;
 
            else if(!GPIO_ReadInputDataBit(SW_DOWN) && setpoint_brew > 0) {
 
                setpoint_brew--;
 
            }
 
 
 
@@ -647,19 +672,20 @@ void machine()
 
            ssd1306_drawlogo();
 
            draw_setpoint();
 
            pid_enabled = 1;
 
	    setpoint = setpoint_steam;
 
 
            // Button handler
 
            if(SW_BTN_PRESSED) {
 
                state = STATE_IDLE;
 
		save_setpoints(); // TODO: Check for mod
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_UP)) {
 
               setpoint++; 
 
               setpoint_steam++; 
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_DOWN) && setpoint > 0) {
 
                setpoint--;
 
            else if(!GPIO_ReadInputDataBit(SW_DOWN) && setpoint_steam > 0) {
 
                setpoint_steam--;
 
            }
 
 
 
            // Event Handler
 
            if(temp >= setpoint) {
 
                state = STATE_MAINTAIN_STEAM;
 
@@ -676,16 +702,18 @@ void machine()
 
            ssd1306_drawlogo();
 
            draw_setpoint();
 
            pid_enabled = 1;
 
	    setpoint = setpoint_steam;
 
 
            // Button handler
 
            if(SW_BTN_PRESSED) {
 
                state = STATE_IDLE;
 
		save_setpoints(); // TODO: Check for mod
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_UP)) {
 
               setpoint++; 
 
               setpoint_steam++; 
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_DOWN) && setpoint > 0) {
 
                setpoint--;
 
            else if(!GPIO_ReadInputDataBit(SW_DOWN) && setpoint_steam > 0) {
 
                setpoint_steam--;
 
            }
 
 
0 comments (0 inline, 0 general)