Changeset - e28695e6887c
[Not reviewed]
cortex-f0
0 5 0
Ethan Zonca - 9 years ago 2015-06-01 17:09:22
ez@ethanzonca.com
Added temperature offset support
5 files changed with 52 insertions and 2 deletions:
0 comments (0 inline, 0 general)
display.c
Show inline comments
 
@@ -332,40 +332,70 @@ void display_process(therm_settings_t* s
 
            ssd1306_DrawString("Units: ", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            if(set->temp_units == TEMP_UNITS_FAHRENHEIT)
 
                ssd1306_DrawString("Fahrenheit", 1, 60);
 
            else
 
                ssd1306_DrawString("Celsius   ", 1, 60);
 

	
 
            ssd1306_DrawString("Press to accept", 3, 40);
 

	
 
            // Button handler
 
            if(SW_BTN_PRESSED) {
 
                save_settings();
 
                status->state = STATE_IDLE;
 
                status->state = STATE_SETTEMPOFFSET;
 
            }
 
            else if(!HAL_GPIO_ReadPin(SW_UP)) {
 
                set->temp_units = TEMP_UNITS_FAHRENHEIT;
 
            }
 
            else if(!HAL_GPIO_ReadPin(SW_DOWN)) {
 
                set->temp_units = TEMP_UNITS_CELSIUS;
 
            }
 

	
 
            // Event Handler
 
            // N/A
 
 
 
        } break;
 

	
 

	
 
        case STATE_SETTEMPOFFSET:
 
        {
 
            // Write text to OLED
 
            // [ therm :: set temp offset ]
 
            // [ g = 12         ]
 
            ssd1306_DrawString("Thermocouple Offset", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            char tempstr[6];
 
            itoa(set->temp_offset, tempstr, 10);
 
            ssd1306_DrawString("O=", 1, 45);
 
            ssd1306_DrawString("    ", 1, 57);
 
            ssd1306_DrawString(tempstr, 1, 57);
 

	
 
            ssd1306_DrawString("Press to accept", 3, 40);
 

	
 
            // Button handler
 
            if(SW_BTN_PRESSED) {
 
                save_settings();
 
                status->state = STATE_IDLE;
 
            }
 
            else {
 
                user_input_signed(&set->temp_offset);
 
            }
 

	
 
            // Event Handler
 
            // N/A
 
 
 
        } break;
 

	
 

	
 
        case STATE_PREHEAT_BREW:
 
        {
 
            // Write text to OLED
 
            // [ therm : preheating brew ]
 
            // [ 30 => 120 C             ]
 
            ssd1306_DrawString("Preheating...", 0, 0);
 
            //ssd1306_drawlogo();
 
            draw_setpoint(status);
 

	
 
            status->pid_enabled = 1;
 
	    status->setpoint = set->setpoint_brew;
 

	
gpio.c
Show inline comments
 
@@ -11,24 +11,39 @@ void user_input(uint16_t* to_modify)
 
    if(CHANGE_ELAPSED) {
 
        if(!HAL_GPIO_ReadPin(SW_UP) ) {
 
            CHANGE_RESET;
 
            (*to_modify)++;
 
        }
 
        else if(!HAL_GPIO_ReadPin(SW_DOWN) && (*to_modify) > 0) {
 
            CHANGE_RESET;
 
            (*to_modify)--;
 
        }
 
    }
 
}
 

	
 
void user_input_signed(int16_t* to_modify)
 
{
 
    // TODO: Bounds check on int16_t
 
    if(CHANGE_ELAPSED) {
 
        if(!HAL_GPIO_ReadPin(SW_UP) ) {
 
            CHANGE_RESET;
 
            (*to_modify)++;
 
        }
 
        else if(!HAL_GPIO_ReadPin(SW_DOWN)) {
 
            CHANGE_RESET;
 
            (*to_modify)--;
 
        }
 
    }
 
}
 

	
 

	
 
void init_gpio(void) {
 

	
 
  GPIO_InitTypeDef GPIO_InitStruct;
 

	
 
    /* GPIO Ports Clock Enable */
 
  __GPIOF_CLK_ENABLE();
 
  __GPIOA_CLK_ENABLE();
 
  __GPIOB_CLK_ENABLE();
 
  __SPI1_CLK_ENABLE();
 

	
 
   
gpio.h
Show inline comments
 
#ifndef GPIO_H
 
#define GPIO_H
 

	
 
#include <inttypes.h>
 

	
 
#define CHANGE_PERIOD_MS 100
 
#define CHANGE_ELAPSED (HAL_GetTick() - change_time_reset) > CHANGE_PERIOD_MS
 
#define CHANGE_RESET change_time_reset = HAL_GetTick()
 

	
 

	
 
void user_input(uint16_t* to_modify);
 
void user_input_signed(int16_t* to_modify);
 
void init_gpio(void);
 

	
 
#endif
 

	
 
// vim:softtabstop=4 shiftwidth=4 expandtab 
main.c
Show inline comments
 
@@ -197,30 +197,32 @@ void update_temp() {
 
        else {
 
            signint = 1;
 
        }
 
 
        // Convert to Fahrenheit
 
        if(set.temp_units == TEMP_UNITS_FAHRENHEIT)
 
        {
 
            status.temp = signint * ((temp_pre*100) + status.temp_frac);
 
            status.temp = status.temp * 1.8;
 
            status.temp += 3200;
 
            status.temp_frac = status.temp % 100;
 
            status.temp /= 100;
 
            status.temp += set.temp_offset;
 
        }
 
 
        // Use Celsius values
 
        else
 
        {
 
            status.temp = temp_pre * signint;
 
            status.temp += set.temp_offset;
 
        }
 
    }
 
}
 
 
 
// PID implementation
 
// TODO: Make struct that has the last_temp and i_state in it, pass by ref. Make struct that has other input values maybe.
 
int16_t last_pid_temp = 0;
 
uint8_t last_pid_temp_frac = 0;
 
int16_t i_state = 0;
 
 
int16_t update_pid(uint16_t k_p, uint16_t k_i, uint16_t k_d, int16_t temp, uint8_t temp_frac, int16_t setpoint) 
states.h
Show inline comments
 
@@ -8,44 +8,46 @@ typedef struct {
 
    uint8_t state;
 
    int32_t setpoint;
 
    uint8_t pid_enabled;
 
} therm_status_t;
 

	
 
typedef struct {
 
    uint8_t boottobrew;
 
    uint8_t temp_units;
 
    uint16_t windup_guard;
 
    uint16_t k_p;
 
    uint16_t k_i;
 
    uint16_t k_d;
 
    int16_t temp_offset;
 
    uint8_t ignore_tc_error;
 
    int16_t setpoint_brew;
 
    int16_t setpoint_steam;
 
} therm_settings_t;
 

	
 

	
 

	
 
enum tempunits {
 
    TEMP_UNITS_CELSIUS = 0,
 
    TEMP_UNITS_FAHRENHEIT,
 
};
 

	
 
enum state {
 
    STATE_IDLE = 0,
 

	
 
    STATE_SETP,
 
    STATE_SETI,
 
    STATE_SETD,
 
    STATE_SETSTEPS,
 
    STATE_SETWINDUP,
 
    STATE_SETBOOTTOBREW,
 
    STATE_SETUNITS,
 
    STATE_SETTEMPOFFSET,
 

	
 
    STATE_PREHEAT_BREW,
 
    STATE_MAINTAIN_BREW,
 
    STATE_PREHEAT_STEAM,
 
    STATE_MAINTAIN_STEAM,
 

	
 
    STATE_TC_ERROR
 
};
 

	
 
#endif
0 comments (0 inline, 0 general)