#include #include #define END_CHAR '\n' #include "settings.h" #define handleInt(var,value) value!=-1? var = value : value = var //setup value Settings settings; char buffer[9]; void setup() { // set up serial comunication Serial.begin(9600); Serial.println("SeedlingNursery0.1 enter ? for help"); // set up EEPROM for testing EEPROM.get(0, settings); } void loop() { handleMenu(); } void handleMenu(){ int bytesReceived = Serial.readBytesUntil(END_CHAR,buffer,8); //Read from the bluetooth serial port buffer[bytesReceived+1] = '\0'; //ensure that the bytes received are formatted as C string if(bytesReceived > 0){ // if there is a char command int value = -1; if(bytesReceived>1){ // there is a value value = atoi(&buffer[1]); //prase int from substring } //Handle each menu case //Code defined on the settings .h file switch (buffer[0]) { case LIGHT_VALUE: handleInt(settings.light, value); break; case SOIL_VALUE: handleInt(settings.soil, value); break; case LEVEL_VAlUE: handleInt(settings.level, value); break; case SETTINGS_BRIGHTNESS: handleInt(settings.brightness, value); break; case SETTINGS_DAY: handleInt(settings.dayValue, value); break; case SETTINGS_SUN: handleInt(settings.sunValue, value); break; case SETTINGS_INTERVAL: handleInt(settings.irrigationInterval, value); break; case SETTINGS_SKIP: handleInt(settings.skipIrrigation, value); break; case SETTINGS_UNTIL: handleInt(settings.irrigationUntil, value); break; case SAVE: EEPROM.put(0, settings); break; //Error caching code default: Serial.println("Command not found"); return; } //send back the current value of the menu option Serial.println(value); } }