void PiLink::receive(void){ if (Serial.available() > 0){ char inByte = Serial.read(); switch(inByte){ case 't': // temperatures requested printTemperatures(); break; case 'C': // Set default constants tempControl.loadDefaultConstants(); display.printStationaryText(); // reprint stationary text to update to right degree unit sendControlConstants(); // update script with new settings debugMessage(PSTR("Default constants loaded.")); break; case 'S': // Set default settings tempControl.loadDefaultSettings(); sendControlSettings(); // update script with new settings debugMessage(PSTR("Default settings loaded.")); break; case 's': // Control settings requested sendControlSettings(); break; case 'c': // Control constants requested sendControlConstants(); break; case 'v': // Control variables requested sendControlVariables(); break; case 'l': // Display content requested print_P(PSTR("L:")); char stringBuffer[21]; for(uint8_t i=0;i<4;i++){ display.lcd.getLine(i, stringBuffer); print_P(PSTR("%s<BR>"), stringBuffer); } print_P(PSTR("\n")); break; case 'j': // Receive settings as json receiveJson(); break; default: debugMessage(PSTR("Invalid command Received by Arduino: %c"), inByte); } //Serial.flush(); Messages can be back to back. Flush should not be necessary. // Functions should not read more than what is meant for that function. } }
void PiLink::receive(void){ while (piStream.available() > 0) { char inByte = piStream.read(); switch(inByte){ case ' ': case '\n': case '\r': break; #if BREWPI_SIMULATE==1 case 'y': parseJson(HandleSimulatorConfig); break; case 'Y': printSimulatorSettings(); break; #endif case 'A': // alarm on soundAlarm(true); break; case 'a': // alarm off soundAlarm(false); break; case 't': // temperatures requested printTemperatures(); break; case 'C': // Set default constants tempControl.loadDefaultConstants(); display.printStationaryText(); // reprint stationary text to update to right degree unit sendControlConstants(); // update script with new settings logInfo(INFO_DEFAULT_CONSTANTS_LOADED); break; case 'S': // Set default settings tempControl.loadDefaultSettings(); sendControlSettings(); // update script with new settings logInfo(INFO_DEFAULT_SETTINGS_LOADED); break; case 's': // Control settings requested sendControlSettings(); break; case 'c': // Control constants requested sendControlConstants(); break; case 'v': // Control variables requested, send Control Object as json sendControlVariables(); break; case 'n': // v version // s shield type // y: simulator // b: board print_P(PSTR( "N:{" "\"v\":\"" PRINTF_PROGMEM "\"," "\"n\":\"" PRINTF_PROGMEM "\"," "\"s\":%d," "\"y\":%d," "\"b\":\"%c\"," "\"l\":\"%d\"" "}"), PSTR(VERSION_STRING), // v: PSTR(stringify(BUILD_NAME)), // n: getShieldVersion(), // s: BREWPI_SIMULATE, // y: BREWPI_BOARD, // b: BREWPI_LOG_MESSAGES_VERSION); // l: printNewLine(); break; case 'l': // Display content requested printResponse('L'); piStream.print('['); char stringBuffer[21]; for(uint8_t i=0;i<4;i++){ display.getLine(i, stringBuffer); print_P(PSTR("\"%s\""), stringBuffer); char close = (i<3) ? ',':']'; piStream.print(close); } printNewLine(); break; case 'j': // Receive settings as json receiveJson(); break; #if BREWPI_EEPROM_HELPER_COMMANDS case 'e': // dump contents of eeprom openListResponse('E'); for (uint16_t i=0; i<1024;) { if (i>0) { piLink.printNewLine(); piLink.print(','); } piLink.print('\"'); for (uint8_t j=0; j<64; j++) { uint8_t d = eepromAccess.readByte(i++); printNibble(d>>4); printNibble(d); } piLink.print('\"'); } closeListResponse(); break; #endif case 'E': // initialize eeprom eepromManager.initializeEeprom(); logInfo(INFO_EEPROM_INITIALIZED); settingsManager.loadSettings(); break; case 'd': // list devices in eeprom order openListResponse('d'); deviceManager.listDevices(piStream); closeListResponse(); break; case 'U': // update device deviceManager.parseDeviceDefinition(piStream); break; case 'h': // hardware query openListResponse('h'); deviceManager.enumerateHardwareToStream(piStream); closeListResponse(); break; #if (BREWPI_DEBUG > 0) case 'Z': // zap eeprom eepromManager.zapEeprom(); logInfo(INFO_EEPROM_ZAPPED); break; #endif case 'R': // reset handleReset(); break; case 'F': // flash firmware flashFirmware(); break; default: logWarningInt(WARNING_INVALID_COMMAND, inByte); } } }