summaryrefslogtreecommitdiff
path: root/command.c
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2013-12-10 07:01:52 +0100
committerChristian Franke <nobody@nowhere.ws>2013-12-10 07:01:52 +0100
commit4265af272a962ce1df1f6a975fdc8210f889760a (patch)
tree5aa10060c5c76ad99d5ab6e36fd81413d72a24cb /command.c
parentee3f9c98681127496101900d65d05c8520b16732 (diff)
Add some conversions from celsius to adc valuesHEADmaster
Luckily, this ATMega is grossly oversized, so we can just throw in floating point arithmetic.
Diffstat (limited to 'command.c')
-rw-r--r--command.c8
1 files changed, 5 insertions, 3 deletions
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);
}