diff --git a/display.c b/display.c --- a/display.c +++ b/display.c @@ -24,6 +24,7 @@ static uint8_t sw_right_last = 0; // States static uint8_t trigger_drawsetpoint = 1; static int16_t last_temp = 21245; +static int16_t last_temp_frac = 21245; static int16_t last_state = STATE_IDLE; static uint8_t goto_mode = MODE_HEAT; static uint8_t reset_mode = RESET_REBOOT; @@ -36,8 +37,9 @@ void display_process(therm_settings_t* s uint8_t state_changed = status->state != last_state; last_state = status->state; - uint8_t temp_changed = status->temp != last_temp; + uint8_t temp_changed = status->temp != last_temp || status->temp_frac != last_temp_frac; last_temp = status->temp; + last_temp_frac = status->temp_frac; uint8_t sw_btn = !HAL_GPIO_ReadPin(SW_BTN); uint8_t sw_up = !HAL_GPIO_ReadPin(SW_UP); @@ -540,12 +542,13 @@ void display_process(therm_settings_t* s static int32_t temp_last = 43002; +static int32_t temp_frac_last = 43002; static int32_t setpoint_last = 10023; // Draw current setpoint on display static void draw_setpoint(therm_status_t* status) { // FIXME: need to do this when switching modes too - if(status->temp != temp_last || trigger_drawsetpoint) { + if(status->temp != temp_last || status->temp_frac != temp_frac_last || trigger_drawsetpoint) { char tempstr[3]; itoa_fp(status->temp, status->temp_frac, tempstr); ssd1306_drawstringbig(" ", 3, 0); @@ -565,6 +568,7 @@ static void draw_setpoint(therm_status_t trigger_drawsetpoint = 0; setpoint_last = status->setpoint; temp_last = status->temp; + temp_frac_last = status->temp_frac; } void display_startup_screen() { diff --git a/max31865.c b/max31865.c --- a/max31865.c +++ b/max31865.c @@ -107,15 +107,15 @@ void max31865_readtemp(SPI_HandleTypeDef //convert adc to resistance //Rrtd = adc / range * Rref - status->temp = adc_count * 9830 * 10; - status->temp /= 32768; + status->temp = (int32_t) adc_count * 48600L; + status->temp /= 32768L; //resistance to temp //(x - in1) * (cal2 - cal1) / (in2 - in1) + cal1 - status->temp = ((status->temp * 100) - 100000) * (39200 - 3200) / (175860 - 100000) + 3200; + status->temp = ((status->temp) - 10000L) * (39200L - 3200L) / (17586L - 10000L) + 3200L; //grab the fraction - status->temp_frac = (status->temp / 10) % 10; + status->temp_frac = (status->temp / 10) % 10L; //scale back to degrees - status->temp = status->temp / 100; + status->temp = status->temp / 100L; //add in the offset status->temp += set->val.temp_offset; } @@ -127,15 +127,15 @@ void max31865_readtemp(SPI_HandleTypeDef //convert adc to resistance //Rrtd = adc / range * Rref - status->temp = adc_count * 9830 * 10; - status->temp /= 32768; + status->temp = (int32_t) adc_count * 48600L; + status->temp /= 32768L; //resistance to temp //(x - in1) * (cal2 - cal1) / (in2 - in1) + cal1 - status->temp = ((status->temp * 10) - 10000) * (20000 - 0) / (17586 - 10000) + 0; + status->temp = (((status->temp) - 10000L) * (20000L- 0L)) / (17586L - 10000L) + 0L; //grab the fraction - status->temp_frac = (status->temp / 10) % 10; + status->temp_frac = (status->temp / 10) % 100L; //scale back to degrees - status->temp = status->temp / 100; + status->temp = status->temp / 100L; //add in the offset status->temp += set->val.temp_offset; } diff --git a/system/stringhelpers.c b/system/stringhelpers.c --- a/system/stringhelpers.c +++ b/system/stringhelpers.c @@ -1,8 +1,9 @@ #include +char const digit[] = "0123456789"; + char* zitoa(int16_t i, char b[]){ - char const digit[] = "0123456789"; char* p = b; if(i<0){ *p++ = '-'; @@ -22,7 +23,6 @@ char* zitoa(int16_t i, char b[]){ } char* itoa_fp(int16_t i, uint8_t frac, char b[]){ - char const digit[] = "0123456789"; // set p to beginning of char array char* p = b;