Changeset - 9ae5559ab974
[Not reviewed]
default
0 6 0
matthewreed - 6 years ago 2018-12-30 21:46:42

Added current setpoint number to heating screens, and a few fixes for floating point numbers and such.
6 files changed with 39 insertions and 12 deletions:
0 comments (0 inline, 0 general)
inc/states.h
Show inline comments
 
@@ -5,13 +5,13 @@
 
#include "config.h"
 

	
 
typedef struct {
 
    float temp;
 
    uint8_t state_resume;
 
    uint8_t state;
 
    int32_t setpoint;
 
    float setpoint;
 
    uint8_t pid_enabled;
 
    uint8_t error_code;
 
    uint8_t setpoint_index;
 
} therm_status_t;
 

	
 
typedef union
 
@@ -20,15 +20,15 @@ typedef union
 
        uint32_t boottobrew;
 
        uint32_t temp_units;
 
        uint32_t windup_guard;
 
        uint32_t k_p;
 
        uint32_t k_i;
 
        uint32_t k_d;
 
        int32_t temp_offset; //TODO: convert to float
 
        float temp_offset;
 
        uint32_t ignore_error;
 
        int32_t setpoints[MAX_SETPOINTS];
 
        float setpoints[MAX_SETPOINTS];
 
        uint32_t control_mode;
 
        uint32_t sensor_type;
 
        uint32_t plant_type;
 
        uint32_t hysteresis;
 
        uint32_t setpoint_count;
 
        uint32_t setpoint_aux_select_enable;
inc/system/gpio.h
Show inline comments
 
@@ -44,11 +44,12 @@
 
#define AUX_RETURN AUX_RETURN_GPIO_Port , AUX_RETURN_Pin
 
 
 
void user_input(uint16_t* to_modify);
 
void user_input_min_max(uint16_t* to_modify, uint16_t min, uint16_t max);
 
void user_input_signed(int32_t* to_modify);
 
void user_input_float(float* to_modify);
 
 
void gpio_init(void);
 
void gpio_led_blueblink(uint8_t num_blinks);
 
 
#endif
src/display.c
Show inline comments
 
@@ -560,24 +560,24 @@ void display_process(void)
 
            ssd1306_drawstring("Temp Cal Offset", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            ssd1306_drawchar(updown(), 1, 52);
 

	
 
            char tempstr[12];
 
            snprintf(tempstr, 12, "O=%ld", set->val.temp_offset);
 
            snprintf(tempstr, 12, "O=%.1f  ", set->val.temp_offset);
 
            ssd1306_drawstring(tempstr, 1, 60);
 

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

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

	
 
            // Event Handler
 
            // N/A
 

	
 
        } break;
 
@@ -586,15 +586,19 @@ void display_process(void)
 
        case STATE_PREHEAT:
 
        {
 
            // Write text to OLED
 
            // [ therm : preheating brew ]
 
            // [ 30 => 120 C             ]
 
            if(set->val.plant_type == PLANT_HEATER)
 
                ssd1306_drawstring("Preheating...", 0, 0);
 
                ssd1306_drawstring("Preheat...", 0, 0);
 
            else
 
                ssd1306_drawstring("Precooling...", 0, 0);
 
                ssd1306_drawstring("Precool...", 0, 0);
 

	
 
            char tempstr[4];
 
            snprintf(tempstr, 4, "#%d  ", (status->setpoint_index + 1));
 
            ssd1306_drawstring(tempstr, 0, 65);
 

	
 
            //ssd1306_drawlogo();
 
            draw_setpoint(status);
 

	
 
            status->pid_enabled = 1;
 
            status->setpoint = set->val.setpoints[status->setpoint_index];
 
@@ -616,13 +620,13 @@ void display_process(void)
 
                if (status->setpoint_index < (set->val.setpoint_count - 1))
 
                {
 
                    status->setpoint_index++;
 
                }
 
            }
 
            else {
 
                user_input_signed(&set->val.setpoints[status->setpoint_index]);
 
                user_input_float(&set->val.setpoints[status->setpoint_index]);
 
            }
 

	
 
            // Event Handler
 
            if(status->temp >= status->setpoint) {
 
                status->state = STATE_MAINTAIN;
 
            }
 
@@ -646,12 +650,16 @@ void display_process(void)
 

	
 
            if(set->val.plant_type == PLANT_HEATER)
 
                ssd1306_drawstring("Preheated!", 0, 0);
 
            else
 
                ssd1306_drawstring("Precooled!", 0, 0);
 

	
 
            char tempstr[4];
 
            snprintf(tempstr, 4, "#%d  ", (status->setpoint_index + 1));
 
            ssd1306_drawstring(tempstr, 0, 65);
 

	
 
            draw_setpoint(status);
 
            status->pid_enabled = 1;
 
            status->setpoint = set->val.setpoints[status->setpoint_index];
 

	
 
            // Button handler
 
            if(SW_BTN_PRESSED) {
 
@@ -670,13 +678,13 @@ void display_process(void)
 
                if (status->setpoint_index < (set->val.setpoint_count - 1))
 
                {
 
                    status->setpoint_index++;
 
                }
 
            }
 
            else {
 
                user_input_signed(&set->val.setpoints[status->setpoint_index]);
 
                user_input_float(&set->val.setpoints[status->setpoint_index]);
 
            }
 

	
 
            // Event Handler
 
            // N/A
 

	
 
        } break;
 
@@ -839,13 +847,13 @@ static void draw_setpoint(therm_status_t
 

	
 
    if(trigger_drawsetpoint) 
 
        ssd1306_drawstringbig(">", 3, 74);
 

	
 
    if(status->setpoint != setpoint_last || trigger_drawsetpoint) {
 
        char tempstr[4];
 
        snprintf(tempstr, 4, "%ld     ", status->setpoint);
 
        snprintf(tempstr, 4, "%3.0f     ", status->setpoint);
 
        ssd1306_drawstringbig(tempstr, 3, 90);
 
    }
 

	
 
    trigger_drawsetpoint = 0;
 
    setpoint_last = status->setpoint;
 
    temp_last = status->temp;
src/main.c
Show inline comments
 
@@ -34,13 +34,13 @@ int main(void)
 
    ssd1306_clearscreen();
 
    //ssd1306_drawlogo();
 
 
    // Default status
 
    runtime_status()->temp = 0.0;
 
    runtime_status()->state_resume = 0;
 
    runtime_status()->setpoint = 70;
 
    runtime_status()->setpoint = 70.0;
 
    runtime_status()->pid_enabled = 0;
 
    runtime_status()->setpoint_index = 0;
 
    if (flash_getsettings()->val.boottobrew)
 
    {
 
        runtime_status()->state = STATE_PREHEAT;
 
    }
 
@@ -48,13 +48,12 @@ int main(void)
 
    {
 
        runtime_status()->state = STATE_IDLE;
 
    }
 
 
    pid_init();
 
    pwmout_init();
 
    flash_init();
 
    watchdog_init();
 
    tempsense_init();
 
 
    // Soft timers
 
    uint32_t last_pid = 0;
 
    uint32_t last_thermostat = 0;
src/system/gpio.c
Show inline comments
 
@@ -106,6 +106,24 @@ void user_input_signed(int32_t* to_modif
 
            CHANGE_RESET;
 
            if (*to_modify >= -32768)
 
                (*to_modify)--;
 
        }
 
    }
 
}
 
 
// Increment/decrement signed variable with up/down buttons
 
void user_input_float(float* to_modify)
 
{
 
    //fixme: need to cast to 16/32 bits correctly
 
    if(CHANGE_ELAPSED) {
 
        if(!HAL_GPIO_ReadPin(SW_UP) ) {
 
            CHANGE_RESET;
 
            if (*to_modify < 32768)
 
                (*to_modify)++;
 
        }
 
        else if(!HAL_GPIO_ReadPin(SW_DOWN)) {
 
            CHANGE_RESET;
 
            if (*to_modify >= -32768)
 
                (*to_modify)--;
 
        }
 
    }
 
}
src/tempsense.c
Show inline comments
 
@@ -38,12 +38,13 @@ void tempsense_readtemp(void)
 
            max31856_process();
 
        } break;
 

	
 
        case SENSOR_NTC:
 
        {
 
            // Read analog value from internal ADC, linearize the reading, etc
 
            //TODO
 
        } break;
 

	
 
    }
 

	
 
    // either return latest reading from DMA loop (NTC, etc)
 
    // or initiate a blocking read and return it.
0 comments (0 inline, 0 general)