/*
* command.c
*
* Functions to evaluate and run commands sent via USART.
*
* Created on: 02.05.2015
* Author: dode@luniks.net
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include "sensors.h"
#include "display.h"
#include "alert.h"
#include "command.h"
#include "strings.h"
static bool simulation = false;
static bool logging = false;
bool isSimulation(void) {
return simulation;
}
bool isLogging(void) {
return logging;
}
void runCommand(char* const data) {
size_t fieldCount = 8;
char* fields[fieldCount];
split(data, " ", fields, fieldCount);
if (strcmp_P(fields[0], PSTR("se")) == 0) {
// simulation enable
resetMeas();
simulation = true;
beep(1, 2);
}
else if (strcmp_P(fields[0], PSTR("sd")) == 0) {
// simulation disable
resetMeas();
simulation = false;
beep(1, 2);
}
else if (strcmp_P(fields[0], PSTR("le")) == 0) {
// logging enable
logging = true;
beep(1, 2);
}
else if (strcmp_P(fields[0], PSTR("ld")) == 0) {
// logging disable
logging = false;
beep(1, 2);
}
else if (strcmp_P(fields[0], PSTR("cm")) == 0) {
// cycle menu
cycleDisplay();
}
else if (strcmp_P(fields[0], PSTR("ta")) == 0) {
// test alert
char buf[16];
strcpy_P(buf, PSTR("Beep Beep Beep!"));
alert(3, 10, buf, fields[1]);
}
else if (simulation) {
Measurement meas = readMeas(fields, fieldCount);
updateMeas(meas);
}
}