Changeset - 9ae5559ab974
[Not reviewed]
default
0 6 0
matthewreed - 5 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
 
@@ -8,7 +8,7 @@ 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;
 
@@ -23,9 +23,9 @@ typedef union
 
        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;
inc/system/gpio.h
Show inline comments
 
@@ -47,6 +47,7 @@
 
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);
src/display.c
Show inline comments
 
@@ -563,7 +563,7 @@ void display_process(void)
 
            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);
 
@@ -574,7 +574,7 @@ void display_process(void)
 
                status->state = STATE_IDLE;
 
            }
 
            else {
 
                user_input_signed(&set->val.temp_offset);
 
                user_input_float(&set->val.temp_offset);
 
            }
 

	
 
            // Event Handler
 
@@ -589,9 +589,13 @@ void display_process(void)
 
            // [ 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);
 
@@ -619,7 +623,7 @@ void display_process(void)
 
                }
 
            }
 
            else {
 
                user_input_signed(&set->val.setpoints[status->setpoint_index]);
 
                user_input_float(&set->val.setpoints[status->setpoint_index]);
 
            }
 

	
 
            // Event Handler
 
@@ -649,6 +653,10 @@ void display_process(void)
 
            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];
 
@@ -673,7 +681,7 @@ void display_process(void)
 
                }
 
            }
 
            else {
 
                user_input_signed(&set->val.setpoints[status->setpoint_index]);
 
                user_input_float(&set->val.setpoints[status->setpoint_index]);
 
            }
 

	
 
            // Event Handler
 
@@ -842,7 +850,7 @@ static void draw_setpoint(therm_status_t
 

	
 
    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);
 
    }
 

	
src/main.c
Show inline comments
 
@@ -37,7 +37,7 @@ int main(void)
 
    // 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)
 
@@ -51,7 +51,6 @@ int main(void)
 
 
    pid_init();
 
    pwmout_init();
 
    flash_init();
 
    watchdog_init();
 
    tempsense_init();
 
src/system/gpio.c
Show inline comments
 
@@ -109,3 +109,21 @@ void user_input_signed(int32_t* to_modif
 
        }
 
    }
 
}
 
 
// 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
 
@@ -41,6 +41,7 @@ void tempsense_readtemp(void)
 
        case SENSOR_NTC:
 
        {
 
            // Read analog value from internal ADC, linearize the reading, etc
 
            //TODO
 
        } break;
 

	
 
    }
0 comments (0 inline, 0 general)