void onDataReturnQueryInt() { cmdMessenger.sendCmd(kRDataQueryInt, sysDataPushInterval); }
void onReturnTempQuery() { cmdMessenger.sendCmd(kRTemp, temperature); }
void onDataReturnPushMode() { cmdMessenger.sendCmd(kRDataPushMode, sysDataPushMode); }
void onDataSetQueryInt() { sysDataPushInterval = (uint32_t)cmdMessenger.readDoubleArg(); onDataReturnQueryInt(); }
//Command Functions void onReturnStatus() { cmdMessenger.sendCmd(kRStatus, sysStatus); }
void onDataSetPushMode() { sysDataPushMode = cmdMessenger.readBoolArg(); onDataReturnPushMode(); }
void attachCommandCallbacks() { cmdMessenger.attach(kQStatus, onReturnStatus); cmdMessenger.attach(kQDeviceInfo, onReturnDeviceInfo); cmdMessenger.attach(kSSaveSettings, onSaveSettings); cmdMessenger.attach(kSDataPushMode, onDataSetPushMode); cmdMessenger.attach(kQDataPushMode, onDataReturnPushMode); cmdMessenger.attach(kSDataQueryInt, onDataSetQueryInt); cmdMessenger.attach(kQDataQueryInt, onDataReturnQueryInt); cmdMessenger.attach(kQTemp, onReturnTempQuery); cmdMessenger.attach(kQHumi, onReturnHumiQuery); cmdMessenger.attach(kQPres, onReturnPresQuery); cmdMessenger.attach(kQLux, onReturnLuxQuery); cmdMessenger.attach(kQPS, onReturnPSQuery); cmdMessenger.attach(kSLedMode, onLedSetMode); cmdMessenger.attach(kQLedMode, onLedReturnMode); cmdMessenger.attach(kSLedModeRestore, onLedRestoreMode); cmdMessenger.attach(kSLedFadeMinMax, onLedSetFadeLimits); cmdMessenger.attach(kQLedFadeMinMax, onLedReturnFadeLimits); cmdMessenger.attach(kSLedCmdFadeTo, onLedFadeTo); cmdMessenger.attach(kSCalibratePS, onCalibratePS); cmdMessenger.attach(kSReset, onSoftReset); }
void processCommands() { cmdMessenger.feedinSerialData(); }
void onSetAverage() { bool _mustUseAverage = cmdMessenger.readBoolArg(); mustUseAverage = _mustUseAverage; cmdMessenger.sendCmd(kStatus, "Use of average toggled"); }
void loop() { cmdMessenger.feedinSerialData(); warning_blink(); }
void readLimitsArgs(float *lMin, float *lMax) { *lMin = cmdMessenger.readFloatArg(); *lMax = cmdMessenger.readFloatArg(); }
void readTuningArgs(float *Kp, float *Ki, float *Kd) { *Kp = cmdMessenger.readFloatArg(); *Ki = cmdMessenger.readFloatArg(); *Kd = cmdMessenger.readFloatArg(); }
void onUnknownCommand() { Serial.println("Receiving unknown command..."); cmdMessenger.sendCmd(kStatus, "Command without attached callback"); }
void onReturnHumiQuery() { cmdMessenger.sendCmd(kRHumi, humidity); }
//Tasker Functions void sysTaskProcessor(void) { switch (sysTaskFlag) { case SYS_TASK_DEFAULT: { sensorDataReady = false; if (!sensorDataReady) { if (sensorPollALS) { lux = alsSensor.lux(); } if (sensorPollPS) { ps = alsSensor.ps(); } temperature = climateSensor.readTempC(); humidity = climateSensor.readHumidity(); pressure = climateSensor.readPressure(); } sensorDataReady = true; switch (ledControlMode){ case LED_CONTROL_MODE_ALS: if(!sensorPollALS) { sensorPollALS = true; } if (lux <= sensorALSTriggerL) { ledFadeTarget = ledFadeTargetMax; } else if (lux >= sensorALSTriggerH) { ledFadeTarget = ledFadeTargetMin; } break; case LED_CONTROL_MODE_PS: ledPSControl(); break; case LED_CONTROL_MODE_ALS_PS: if (lux <= sensorALSTriggerL) { ledPSControl(); } break; case LED_CONTROL_MODE_OFF: ledFadeTarget = 0; break; default: break; } break; } case SYS_TASK_PUSH_DATA: { if (sensorDataPushed == false) { if (sensorDataReady) { sensorDataPushed = true; cmdMessenger.sendCmd(kRTemp, temperature); cmdMessenger.sendCmd(kRHumi, humidity); cmdMessenger.sendCmd(kRPres, pressure); cmdMessenger.sendCmd(kRLux, lux); if (sensorPsCalibrated) { cmdMessenger.sendCmd(kRPS, ps); } } } sysTaskFlag = SYS_TASK_DEFAULT; break; } case SYS_TASK_NL_CONTROL: { switch (ledControlMode) { case LED_CONTROL_MODE_PS: sensorPollALS = false; ledFadeTarget = ledFadeTargetMax; ledPSTimeoutStart = true; ledPSTimedout = false; break; case LED_CONTROL_MODE_ALS_PS: if (lux <= sensorALSTriggerL) { sensorPollALS = false; ledFadeTarget = ledFadeTargetMax; ledPSTimeoutStart = true; ledPSTimedout = false; } break; default: break; } sysTaskFlag = SYS_TASK_DEFAULT; break; } case SYS_TASK_SAVE_SETTINGS: { sysSaveSettings(); cmdMessenger.sendCmd(kRStatus, SYS_SETTINGS_SAVED); sysTaskFlag = SYS_TASK_DEFAULT; break; } case SYS_TASK_CALIBRATE: { sensorPsCalibrated = false; uint16_t psCalFactor; if(alsSensor.psSetCanc(0)) { delay(500); psCalFactor = alsSensor.psCalibrate(); if (alsSensor.psSetCanc(psCalFactor)) { psCal = psCalFactor; sensorPsCalibrated = true; cmdMessenger.sendCmd(kRCalibratePS, SYS_PS_CALIBRATED); sysTaskFlag = SYS_TASK_SAVE_SETTINGS; } else { cmdMessenger.sendCmd(kRCalibratePS, SYS_PS_CALIBRATE_FAIL); sysTaskFlag = SYS_TASK_DEFAULT; } } else { cmdMessenger.sendCmd(kRCalibratePS, SYS_PS_CALIBRATE_FAIL); sysTaskFlag = SYS_TASK_DEFAULT; } break; } default: { sysTaskFlag = SYS_TASK_DEFAULT; break; } } }
void onReturnPresQuery() { cmdMessenger.sendCmd(kRPres, pressure); }
void onRecalibrate() { angleSetpoint = calibrateSensor(); cmdMessenger.sendCmd(kStatus, "Calibration done"); }