Made the physical led entries private in the UI class, now they are shielded by logical functions.
This commit is contained in:
parent
fd1363dd45
commit
578c0aa626
|
@ -11,28 +11,19 @@ namespace Dough
|
||||||
App::App() : config(),
|
App::App() : config(),
|
||||||
ui(),
|
ui(),
|
||||||
wifi(),
|
wifi(),
|
||||||
mqtt(
|
mqtt(&wifi, mqttOnConnectCallback, mqttOnMessageCallback),
|
||||||
&wifi,
|
|
||||||
mqttOnConnectCallback,
|
|
||||||
mqttOnMessageCallback),
|
|
||||||
temperatureSensor(
|
temperatureSensor(
|
||||||
&mqtt,
|
&mqtt, "temperature", TemperatureSensor::Instance(),
|
||||||
"temperature",
|
|
||||||
TemperatureSensor::Instance(),
|
|
||||||
TEMPERATURE_AVERAGE_STORAGE,
|
TEMPERATURE_AVERAGE_STORAGE,
|
||||||
TEMPERATURE_MEASURE_INTERVAL, sensorOnMeasureCallback,
|
TEMPERATURE_MEASURE_INTERVAL, sensorOnMeasureCallback,
|
||||||
MINIMUM_PUBLISH_INTERVAL, sensorOnPublishCallback),
|
MINIMUM_PUBLISH_INTERVAL, sensorOnPublishCallback),
|
||||||
humiditySensor(
|
humiditySensor(
|
||||||
&mqtt,
|
&mqtt, "humidity", HumiditySensor::Instance(),
|
||||||
"humidity",
|
|
||||||
HumiditySensor::Instance(),
|
|
||||||
HUMIDITY_AVERAGE_STORAGE,
|
HUMIDITY_AVERAGE_STORAGE,
|
||||||
HUMIDITY_MEASURE_INTERVAL, sensorOnMeasureCallback,
|
HUMIDITY_MEASURE_INTERVAL, sensorOnMeasureCallback,
|
||||||
MINIMUM_PUBLISH_INTERVAL, sensorOnPublishCallback),
|
MINIMUM_PUBLISH_INTERVAL, sensorOnPublishCallback),
|
||||||
distanceSensor(
|
distanceSensor(
|
||||||
&mqtt,
|
&mqtt, "distance", DistanceSensor::Instance(),
|
||||||
"distance",
|
|
||||||
DistanceSensor::Instance(),
|
|
||||||
DISTANCE_AVERAGE_STORAGE,
|
DISTANCE_AVERAGE_STORAGE,
|
||||||
DISTANCE_MEASURE_INTERVAL, sensorOnMeasureCallback,
|
DISTANCE_MEASURE_INTERVAL, sensorOnMeasureCallback,
|
||||||
MINIMUM_PUBLISH_INTERVAL, sensorOnPublishCallback),
|
MINIMUM_PUBLISH_INTERVAL, sensorOnPublishCallback),
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define DOUGH_APP_H
|
#define DOUGH_APP_H
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include "UI/UI.h"
|
||||||
#include "App/Configuration.h"
|
#include "App/Configuration.h"
|
||||||
#include "Data/SensorController.h"
|
#include "Data/SensorController.h"
|
||||||
#include "Sensors/TemperatureSensor.h"
|
#include "Sensors/TemperatureSensor.h"
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include "Sensors/SensorBase.h"
|
#include "Sensors/SensorBase.h"
|
||||||
#include "Data/Measurement.h"
|
#include "Data/Measurement.h"
|
||||||
#include "Network/MQTT.h"
|
#include "Network/MQTT.h"
|
||||||
#include "UI/UI.h"
|
|
||||||
|
|
||||||
namespace Dough
|
namespace Dough
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,10 +4,10 @@ namespace Dough
|
||||||
{
|
{
|
||||||
UI::UI() : onoffButton(ONOFF_BUTTON_PIN),
|
UI::UI() : onoffButton(ONOFF_BUTTON_PIN),
|
||||||
setupButton(SETUP_BUTTON_PIN),
|
setupButton(SETUP_BUTTON_PIN),
|
||||||
ledBuiltin(LED_BUILTIN),
|
_ledBuiltin(LED_BUILTIN),
|
||||||
led1(LED1_PIN),
|
_led1(LED1_PIN),
|
||||||
led2(LED2_PIN),
|
_led2(LED2_PIN),
|
||||||
led3(LED3_PIN) {}
|
_led3(LED3_PIN) {}
|
||||||
|
|
||||||
void UI::setup()
|
void UI::setup()
|
||||||
{
|
{
|
||||||
|
@ -16,10 +16,10 @@ namespace Dough
|
||||||
setupButton.setup();
|
setupButton.setup();
|
||||||
|
|
||||||
// Setup the LEDs.
|
// Setup the LEDs.
|
||||||
ledBuiltin.setup();
|
_ledBuiltin.setup();
|
||||||
led1.setup();
|
_led1.setup();
|
||||||
led2.setup();
|
_led2.setup();
|
||||||
led3.setup();
|
_led3.setup();
|
||||||
|
|
||||||
// Setup a timer interrupt that is used to update the
|
// Setup a timer interrupt that is used to update the
|
||||||
// user interface (a.k.a. "LEDs") in parallel to other activities.
|
// user interface (a.k.a. "LEDs") in parallel to other activities.
|
||||||
|
@ -104,66 +104,73 @@ namespace Dough
|
||||||
// something else.
|
// something else.
|
||||||
void UI::updateLEDs()
|
void UI::updateLEDs()
|
||||||
{
|
{
|
||||||
ledBuiltin.loop();
|
_ledBuiltin.loop();
|
||||||
led1.loop();
|
_led1.loop();
|
||||||
led2.loop();
|
_led2.loop();
|
||||||
led3.loop();
|
_led3.loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::notifyConnectingToWifi()
|
void UI::notifyConnectingToWifi()
|
||||||
{
|
{
|
||||||
led1.blink()->slow();
|
_led1.blink()->slow();
|
||||||
led2.off();
|
_led2.off();
|
||||||
led3.off();
|
_led3.off();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::notifyConnectingToMQTT()
|
void UI::notifyConnectingToMQTT()
|
||||||
{
|
{
|
||||||
led1.blink()->fast();
|
_led1.blink()->fast();
|
||||||
led2.off();
|
_led2.off();
|
||||||
led3.off();
|
_led3.off();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UI::notifyConnected()
|
||||||
|
{
|
||||||
|
_led1.on();
|
||||||
|
_led2.off();
|
||||||
|
_led3.off();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::notifyWaitingForConfiguration()
|
void UI::notifyWaitingForConfiguration()
|
||||||
{
|
{
|
||||||
led1.on();
|
_led1.on();
|
||||||
led2.blink()->slow();
|
_led2.blink()->slow();
|
||||||
led3.off();
|
_led3.off();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::notifyCalibrating()
|
void UI::notifyCalibrating()
|
||||||
{
|
{
|
||||||
led1.on();
|
_led1.on();
|
||||||
led2.blink()->fast();
|
_led2.blink()->fast();
|
||||||
led3.off();
|
_led3.off();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::notifyMeasurementsActive()
|
void UI::notifyMeasurementsActive()
|
||||||
{
|
{
|
||||||
led1.on();
|
_led1.on();
|
||||||
led2.on();
|
_led2.on();
|
||||||
led3.on();
|
_led3.on();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::notifyMeasurementsPaused()
|
void UI::notifyMeasurementsPaused()
|
||||||
{
|
{
|
||||||
led1.on();
|
_led1.on();
|
||||||
led2.on();
|
_led2.on();
|
||||||
led3.pulse();
|
_led3.pulse();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::notifySensorActivity()
|
void UI::notifySensorActivity()
|
||||||
{
|
{
|
||||||
led3.off();
|
_led3.off();
|
||||||
delay(50);
|
delay(50);
|
||||||
led3.on();
|
_led3.on();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::notifyNetworkActivity()
|
void UI::notifyNetworkActivity()
|
||||||
{
|
{
|
||||||
led1.off();
|
_led1.off();
|
||||||
delay(50);
|
delay(50);
|
||||||
led1.on();
|
_led1.on();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flash all LEDs, one at a time in a synchroneous manner, making
|
// Flash all LEDs, one at a time in a synchroneous manner, making
|
||||||
|
@ -171,17 +178,17 @@ namespace Dough
|
||||||
// as a "Hey, I'm awake!" signal from the device after booting up.
|
// as a "Hey, I'm awake!" signal from the device after booting up.
|
||||||
void UI::_flash_all_leds()
|
void UI::_flash_all_leds()
|
||||||
{
|
{
|
||||||
ledBuiltin.on();
|
_ledBuiltin.on();
|
||||||
delay(100);
|
delay(100);
|
||||||
ledBuiltin.off();
|
_ledBuiltin.off();
|
||||||
led1.on();
|
_led1.on();
|
||||||
delay(100);
|
delay(100);
|
||||||
led1.off();
|
_led1.off();
|
||||||
led2.on();
|
_led2.on();
|
||||||
delay(100);
|
delay(100);
|
||||||
led2.off();
|
_led2.off();
|
||||||
led3.on();
|
_led3.on();
|
||||||
delay(100);
|
delay(100);
|
||||||
led3.off();
|
_led3.off();
|
||||||
}
|
}
|
||||||
} // namespace Dough
|
} // namespace Dough
|
|
@ -20,10 +20,6 @@ namespace Dough
|
||||||
static void setupButtonISR();
|
static void setupButtonISR();
|
||||||
Button onoffButton;
|
Button onoffButton;
|
||||||
Button setupButton;
|
Button setupButton;
|
||||||
LED ledBuiltin;
|
|
||||||
LED led1;
|
|
||||||
LED led2;
|
|
||||||
LED led3;
|
|
||||||
void processButtonEvents();
|
void processButtonEvents();
|
||||||
void clearButtonEvents();
|
void clearButtonEvents();
|
||||||
void updateLEDs();
|
void updateLEDs();
|
||||||
|
@ -31,6 +27,7 @@ namespace Dough
|
||||||
void suspend();
|
void suspend();
|
||||||
void notifyConnectingToWifi();
|
void notifyConnectingToWifi();
|
||||||
void notifyConnectingToMQTT();
|
void notifyConnectingToMQTT();
|
||||||
|
void notifyConnected();
|
||||||
void notifyWaitingForConfiguration();
|
void notifyWaitingForConfiguration();
|
||||||
void notifyCalibrating();
|
void notifyCalibrating();
|
||||||
void notifyMeasurementsActive();
|
void notifyMeasurementsActive();
|
||||||
|
@ -39,6 +36,10 @@ namespace Dough
|
||||||
void notifyNetworkActivity();
|
void notifyNetworkActivity();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
LED _ledBuiltin;
|
||||||
|
LED _led1;
|
||||||
|
LED _led2;
|
||||||
|
LED _led3;
|
||||||
void _setupTimerInterrupt();
|
void _setupTimerInterrupt();
|
||||||
static UI *_instance;
|
static UI *_instance;
|
||||||
void _flash_all_leds();
|
void _flash_all_leds();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
// TOOD: implement the calibration logic
|
// TOOD: implement the calibration logic
|
||||||
// TODO: don't make sensors instances
|
// TODO: don't make sensors instances anymore, now they are handled by App as the only singleton
|
||||||
// TODO: see what more stuff can be moved to the UI code. Maybe state to UI state translation ought to be there as well
|
// TODO: see what more stuff can be moved to the UI code. Maybe state to UI state translation ought to be there as well
|
||||||
|
|
||||||
DoughBoyState state = CONFIGURING;
|
DoughBoyState state = CONFIGURING;
|
||||||
|
|
Loading…
Reference in New Issue