Merge branch 'f/read-temp'
This commit is contained in:
commit
dbc0eb7703
@ -12,16 +12,20 @@
|
|||||||
#define BRIGHTNESS_STEP 1
|
#define BRIGHTNESS_STEP 1
|
||||||
#define BRIGHTNESS_NIGHT BRIGHTNESS_MIN
|
#define BRIGHTNESS_NIGHT BRIGHTNESS_MIN
|
||||||
#define BRIGHTNESS_DAY 11
|
#define BRIGHTNESS_DAY 11
|
||||||
#define DISPLAY_TIME 2000
|
#define SECONDS(value) value*1000
|
||||||
#define DISPLAY_TEMP_TIME 5000
|
|
||||||
|
|
||||||
namespace Display {
|
namespace Display {
|
||||||
|
|
||||||
void display();
|
void displayTime();
|
||||||
Task tDisplay(500, TASK_FOREVER, display, &ts, true);
|
void drawTime();
|
||||||
|
void drawColon(bool);
|
||||||
|
Task tDisplayTime(500, TASK_FOREVER, displayTime, &ts, false, []() {
|
||||||
|
drawTime();
|
||||||
|
return true;
|
||||||
|
}, []() {
|
||||||
|
drawColon(false);
|
||||||
|
});
|
||||||
|
|
||||||
int currentHour = -1;
|
|
||||||
int currentMin = -1;
|
|
||||||
bool hourFormat24 = false;
|
bool hourFormat24 = false;
|
||||||
void (*hourFormatChangedCallback)();
|
void (*hourFormatChangedCallback)();
|
||||||
void onHourFormatChanged(void (*f)()) {
|
void onHourFormatChanged(void (*f)()) {
|
||||||
@ -71,6 +75,7 @@ namespace Display {
|
|||||||
|
|
||||||
void drawColon(bool colonOn) {
|
void drawColon(bool colonOn) {
|
||||||
if (colonOn) {
|
if (colonOn) {
|
||||||
|
static int currentHour = -1;
|
||||||
if (currentHour != hour()) {
|
if (currentHour != hour()) {
|
||||||
currentHour = hour();
|
currentHour = hour();
|
||||||
if (currentHour == 8) {
|
if (currentHour == 8) {
|
||||||
@ -81,6 +86,7 @@ namespace Display {
|
|||||||
Brightness::set(BRIGHTNESS_NIGHT);
|
Brightness::set(BRIGHTNESS_NIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static int currentMin = -1;
|
||||||
if (currentMin != minute()) {
|
if (currentMin != minute()) {
|
||||||
currentMin = minute();
|
currentMin = minute();
|
||||||
drawTime();
|
drawTime();
|
||||||
@ -89,8 +95,8 @@ namespace Display {
|
|||||||
clockDisplay.drawColon(colonOn);
|
clockDisplay.drawColon(colonOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void display() {
|
void displayTime() {
|
||||||
static bool colonOn = false;
|
static bool colonOn = true;
|
||||||
|
|
||||||
drawColon(colonOn);
|
drawColon(colonOn);
|
||||||
clockDisplay.writeDisplay();
|
clockDisplay.writeDisplay();
|
||||||
@ -99,30 +105,24 @@ namespace Display {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void displayTemp(float value) {
|
void displayTemp(float value) {
|
||||||
tDisplay.disable();
|
tDisplayTime.disable();
|
||||||
drawColon(false);
|
|
||||||
clockDisplay.printFloat(value, 1);
|
clockDisplay.printFloat(value, 1);
|
||||||
clockDisplay.writeDisplay();
|
clockDisplay.writeDisplay();
|
||||||
drawTime();
|
tDisplayTime.enableDelayed(SECONDS(10));
|
||||||
tDisplay.enableDelayed(DISPLAY_TEMP_TIME);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayValue(uint8_t value) {
|
void displayValue(uint8_t value) {
|
||||||
tDisplay.disable();
|
tDisplayTime.disable();
|
||||||
drawColon(false);
|
|
||||||
clockDisplay.print(value, HEX);
|
clockDisplay.print(value, HEX);
|
||||||
clockDisplay.writeDisplay();
|
clockDisplay.writeDisplay();
|
||||||
drawTime();
|
tDisplayTime.enableDelayed(SECONDS(2));
|
||||||
tDisplay.enableDelayed(DISPLAY_TIME);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayText(const char c[]) {
|
void displayText(const char c[]) {
|
||||||
tDisplay.disable();
|
tDisplayTime.disable();
|
||||||
drawColon(false);
|
|
||||||
clockDisplay.println(c);
|
clockDisplay.println(c);
|
||||||
clockDisplay.writeDisplay();
|
clockDisplay.writeDisplay();
|
||||||
drawTime();
|
tDisplayTime.enableDelayed(SECONDS(2));
|
||||||
tDisplay.enableDelayed(DISPLAY_TIME);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeHourFormat24(bool format24) {
|
void changeHourFormat24(bool format24) {
|
||||||
@ -134,7 +134,5 @@ namespace Display {
|
|||||||
void setup() {
|
void setup() {
|
||||||
clockDisplay.begin(DISPLAY_ADDRESS);
|
clockDisplay.begin(DISPLAY_ADDRESS);
|
||||||
clockDisplay.setBrightness(Brightness::current);
|
clockDisplay.setBrightness(Brightness::current);
|
||||||
drawTime();
|
|
||||||
display();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,7 +19,6 @@ namespace Mqtt {
|
|||||||
void disconnect();
|
void disconnect();
|
||||||
Task tReConnect(5 * TASK_MINUTE, TASK_FOREVER, connect, &ts);
|
Task tReConnect(5 * TASK_MINUTE, TASK_FOREVER, connect, &ts);
|
||||||
Task tPublishInit(TASK_IMMEDIATE, TASK_ONCE, publishInit, &ts);
|
Task tPublishInit(TASK_IMMEDIATE, TASK_ONCE, publishInit, &ts);
|
||||||
Task tPublishBmp(5 * TASK_MINUTE, TASK_FOREVER, publishBmp280, &ts);
|
|
||||||
Task tPublishCommand(TASK_SECOND, TASK_FOREVER, publishCommand, &ts);
|
Task tPublishCommand(TASK_SECOND, TASK_FOREVER, publishCommand, &ts);
|
||||||
|
|
||||||
AsyncMqttClient client;
|
AsyncMqttClient client;
|
||||||
@ -120,7 +119,6 @@ namespace Mqtt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void publishBmp280() {
|
void publishBmp280() {
|
||||||
Bmp::data.readAll();
|
|
||||||
StaticJsonDocument<255> jsonDoc;
|
StaticJsonDocument<255> jsonDoc;
|
||||||
jsonDoc["temperature"] = Bmp::data.temp;
|
jsonDoc["temperature"] = Bmp::data.temp;
|
||||||
jsonDoc["pressure"] = Bmp::data.pressure;
|
jsonDoc["pressure"] = Bmp::data.pressure;
|
||||||
@ -159,7 +157,6 @@ namespace Mqtt {
|
|||||||
Display::onHourFormatChanged(hourFormatMqtt->publishState);
|
Display::onHourFormatChanged(hourFormatMqtt->publishState);
|
||||||
client.onConnect([](bool sessionPresent) {
|
client.onConnect([](bool sessionPresent) {
|
||||||
tPublishInit.enable();
|
tPublishInit.enable();
|
||||||
tPublishBmp.enableIfNot();
|
|
||||||
tPublishCommand.enableDelayed();
|
tPublishCommand.enableDelayed();
|
||||||
client.subscribe(espClockTopic, 0);
|
client.subscribe(espClockTopic, 0);
|
||||||
tReConnect.disable();
|
tReConnect.disable();
|
||||||
@ -168,7 +165,6 @@ namespace Mqtt {
|
|||||||
client.onDisconnect([](AsyncMqttClientDisconnectReason reason) {
|
client.onDisconnect([](AsyncMqttClientDisconnectReason reason) {
|
||||||
tReConnect.enableDelayed();
|
tReConnect.enableDelayed();
|
||||||
tPublishCommand.disable();
|
tPublishCommand.disable();
|
||||||
tPublishBmp.disable();
|
|
||||||
Serial.println("Disconnected from MQTT");
|
Serial.println("Disconnected from MQTT");
|
||||||
});
|
});
|
||||||
client.onMessage(onMessage);
|
client.onMessage(onMessage);
|
||||||
|
|||||||
@ -27,6 +27,17 @@ Task tButton(TASK_IMMEDIATE, TASK_ONCE, []() {
|
|||||||
Task tLed(TASK_IMMEDIATE, TASK_ONCE, []() {
|
Task tLed(TASK_IMMEDIATE, TASK_ONCE, []() {
|
||||||
Mqtt::ledMqtt->publishState();
|
Mqtt::ledMqtt->publishState();
|
||||||
}, &ts);
|
}, &ts);
|
||||||
|
Task tReadBmp(TASK_MINUTE, TASK_FOREVER, []() {
|
||||||
|
static float lastTemp = 0;
|
||||||
|
float temp = Bmp::data.temp;
|
||||||
|
Bmp::data.readAll();
|
||||||
|
if (temp == Bmp::data.temp) return;
|
||||||
|
Mqtt::publishBmp280();
|
||||||
|
if (abs(lastTemp - Bmp::data.temp) > 0.2) {
|
||||||
|
lastTemp = Bmp::data.temp;
|
||||||
|
Display::displayTemp(Bmp::data.temp);
|
||||||
|
}
|
||||||
|
}, &ts);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
@ -47,6 +58,8 @@ void setup() {
|
|||||||
pinMode(BUTTON, INPUT_PULLUP);
|
pinMode(BUTTON, INPUT_PULLUP);
|
||||||
attachInterrupt(digitalPinToInterrupt(BUTTON), onButtonPressed, FALLING);
|
attachInterrupt(digitalPinToInterrupt(BUTTON), onButtonPressed, FALLING);
|
||||||
attachInterrupt(digitalPinToInterrupt(LED_BUILTIN), onLed, CHANGE);
|
attachInterrupt(digitalPinToInterrupt(LED_BUILTIN), onLed, CHANGE);
|
||||||
|
|
||||||
|
tReadBmp.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user