diff options
author | Christian Franke <nobody@nowhere.ws> | 2013-12-10 07:01:52 +0100 |
---|---|---|
committer | Christian Franke <nobody@nowhere.ws> | 2013-12-10 07:01:52 +0100 |
commit | 4265af272a962ce1df1f6a975fdc8210f889760a (patch) | |
tree | 5aa10060c5c76ad99d5ab6e36fd81413d72a24cb /command.c | |
parent | ee3f9c98681127496101900d65d05c8520b16732 (diff) |
Luckily, this ATMega is grossly oversized, so we can
just throw in floating point arithmetic.
Diffstat (limited to 'command.c')
-rw-r--r-- | command.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -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); } |