diff options
Diffstat (limited to 'watch-library/watch')
-rw-r--r-- | watch-library/watch/watch_slcd.c | 5 | ||||
-rw-r--r-- | watch-library/watch/watch_utility.c | 21 | ||||
-rw-r--r-- | watch-library/watch/watch_utility.h | 16 |
3 files changed, 42 insertions, 0 deletions
diff --git a/watch-library/watch/watch_slcd.c b/watch-library/watch/watch_slcd.c index 63ba7988..05c0bf97 100644 --- a/watch-library/watch/watch_slcd.c +++ b/watch-library/watch/watch_slcd.c @@ -214,6 +214,11 @@ void watch_display_string(char *string, uint8_t position) { i++; if (i >= Num_Chars) break; } + // uncomment this line to see screen output on terminal, i.e. + // FR 29 + // 11 50 23 + // note that for partial displays (positon > 0) it will only show the characters that were updated. + // printf("________\n %c%c %c%c\n%c%c %c%c %c%c\n--------\n", (position > 0) ? ' ' : string[0], (position > 1) ? ' ' : string[1 - position], (position > 2) ? ' ' : string[2 - position], (position > 3) ? ' ' : string[3 - position], (position > 4) ? ' ' : string[4 - position], (position > 5) ? ' ' : string[5 - position], (position > 6) ? ' ' : string[6 - position], (position > 7) ? ' ' : string[7 - position], (position > 8) ? ' ' : string[8 - position], (position > 9) ? ' ' : string[9 - position]); } inline void watch_set_colon() { diff --git a/watch-library/watch/watch_utility.c b/watch-library/watch/watch_utility.c index a0f361b4..bfa3073a 100644 --- a/watch-library/watch/watch_utility.c +++ b/watch-library/watch/watch_utility.c @@ -22,6 +22,7 @@ * SOFTWARE. */ +#include <math.h> #include "watch_utility.h" const char * watch_utility_get_weekday(watch_date_time date_time) { @@ -33,3 +34,23 @@ const char * watch_utility_get_weekday(watch_date_time date_time) { } return weekdays[(date_time.unit.day + 13 * (date_time.unit.month + 1) / 5 + date_time.unit.year + date_time.unit.year / 4 + 525) % 7]; } + +float watch_utility_thermistor_temperature(uint16_t value, bool highside, float b_coefficient, float nominal_temperature, float nominal_resistance, float series_resistance) { + float reading = (float)value; + + if (highside) { + reading = (1023.0 * series_resistance) / (reading / 64.0); + reading -= series_resistance; + } else { + reading = series_resistance / (65535.0 / value - 1.0); + } + + reading = reading / nominal_resistance; + reading = log(reading); + reading /= b_coefficient; + reading += 1.0 / (nominal_temperature + 273.15); + reading = 1.0 / reading; + reading -= 273.15; + + return reading; +} diff --git a/watch-library/watch/watch_utility.h b/watch-library/watch/watch_utility.h index e8808923..aada783f 100644 --- a/watch-library/watch/watch_utility.h +++ b/watch-library/watch/watch_utility.h @@ -38,4 +38,20 @@ */ const char * watch_utility_get_weekday(watch_date_time date_time); +/** @brief Returns a temperature in degrees Celsius for a given thermistor voltage divider circuit. + * @param value The raw analog reading from the thermistor pin (0-65535) + * @param highside True if the thermistor is connected to VCC and the series resistor is connected + * to GND; false if the thermistor is connected to GND and the series resistor is + * connected to VCC. + * @param b_coefficient From your thermistor's data sheet, the B25/85 coefficient. A typical value + * will be between 2000 and 5000. + * @param nominal_temperature From your thermistor's data sheet, the temperature (in Celsius) at + * which the thermistor's resistance is at its nominal value. + * @param nominal_resistance The thermistor's resistance at the nominal temperature. + * @param series_resistance The value of the other resistor in the voltage divider. + * @note Ported from Adafruit's MIT-licensed CircuitPython thermistor code, (c) 2017 Scott Shawcroft: + * https://github.com/adafruit/Adafruit_CircuitPython_Thermistor/blob/main/adafruit_thermistor.py + */ +float watch_utility_thermistor_temperature(uint16_t value, bool highside, float b_coefficient, float nominal_temperature, float nominal_resistance, float series_resistance); + #endif |