From 4265af272a962ce1df1f6a975fdc8210f889760a Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Tue, 10 Dec 2013 07:01:52 +0100 Subject: Add some conversions from celsius to adc values Luckily, this ATMega is grossly oversized, so we can just throw in floating point arithmetic. --- command.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'command.c') diff --git a/command.c b/command.c index 7d8c515..09b91ec 100644 --- a/command.c +++ b/command.c @@ -14,7 +14,7 @@ static void handle_set(char *buffer, uint16_t len) const char *success_msg = "OK Temperature set.\r\n"; const char *input; char *endptr; - long temperature; + double temperature; if (len < 2) { serial_send(error_msg, strlen(error_msg), 0); @@ -22,7 +22,7 @@ static void handle_set(char *buffer, uint16_t len) } input = buffer + 1; - temperature = strtol(input, &endptr, 10); + temperature = strtod(input, &endptr); if (input[0] == '\r' || input[0] == '\n' || (endptr[0] != '\r' && endptr[0] != '\n')) { serial_send(error_msg, strlen(error_msg), 0); @@ -48,8 +48,10 @@ static void handle_off(char *buffer, uint16_t len) static void handle_get(char *buffer, uint16_t len) { char response[128]; + long temp = 10 * controller_get(); - snprintf(response, sizeof(response), "OK t=%ld\r\n", controller_get()); + /* printf won't print doubles on avr */ + snprintf(response, sizeof(response), "OK t=%ld.%ld\r\n", temp/10, temp%10); serial_send(response, strlen(response), 0); } -- cgit v1.2.1