add draw screen and sleepmode
This commit is contained in:
@@ -12,5 +12,6 @@
|
|||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = esp12e
|
board = esp12e
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
monitor_speed = 115200
|
||||||
lib_deps =
|
lib_deps =
|
||||||
EspMQTTClient
|
EspMQTTClient
|
||||||
98
src/main.cpp
98
src/main.cpp
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <DEV_Config.h>
|
#include <DEV_Config.h>
|
||||||
#include <EspMQTTClient.h>
|
#include <EspMQTTClient.h>
|
||||||
@@ -9,6 +10,9 @@
|
|||||||
#include "StackPanel.hpp"
|
#include "StackPanel.hpp"
|
||||||
#include "TextBlock.hpp"
|
#include "TextBlock.hpp"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "user_interface.h"
|
||||||
|
}
|
||||||
|
|
||||||
EspMQTTClient client(
|
EspMQTTClient client(
|
||||||
"08151234711-Gast",
|
"08151234711-Gast",
|
||||||
@@ -22,11 +26,7 @@ EspMQTTClient client(
|
|||||||
|
|
||||||
UBYTE *BlackImage;
|
UBYTE *BlackImage;
|
||||||
sFONT * font = &Font8;
|
sFONT * font = &Font8;
|
||||||
PositionalProperties current_msg_pos = {0, 0 , 0, 0};
|
bool tests = true;
|
||||||
StackPanelStyleProperties sstyle = {WHITE, 0, BLACK, 0, 1};
|
|
||||||
DrawItemCallBack sdraw_items[] ={};
|
|
||||||
DrawItemCallBackList sdraw_list = {0, sdraw_items};
|
|
||||||
StackPanel cleaner = StackPanel(sstyle, sdraw_list, StackPanel::move_down);
|
|
||||||
|
|
||||||
PositionalProperties draw_label(const char * title, const char * value, const PositionalProperties & p, const sFONT & f)
|
PositionalProperties draw_label(const char * title, const char * value, const PositionalProperties & p, const sFONT & f)
|
||||||
{
|
{
|
||||||
@@ -66,53 +66,66 @@ PositionalProperties draw_meeting(const char * date, const char * subject, const
|
|||||||
return meeting_stack.draw(p);
|
return meeting_stack.draw(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void draw_srceen(std::function<void()> draw)
|
||||||
|
{
|
||||||
|
Paint_Clear(WHITE);
|
||||||
|
Paint.WidthOffset = 0;
|
||||||
|
Paint.HeightOffset = 0;
|
||||||
|
draw();
|
||||||
|
EPD_7IN5_V2_SendHalfImage(0, BlackImage);
|
||||||
|
|
||||||
|
Paint_Clear(WHITE);
|
||||||
|
if(Paint.Rotate == ROTATE_0 || Paint.Rotate == ROTATE_180) {
|
||||||
|
Paint.WidthOffset = EPD_7IN5_V2_WIDTH - Paint.Width;
|
||||||
|
Paint.HeightOffset = EPD_7IN5_V2_HEIGHT - Paint.Height;
|
||||||
|
} else {
|
||||||
|
Paint.WidthOffset = EPD_7IN5_V2_HEIGHT - Paint.Width;
|
||||||
|
Paint.HeightOffset = EPD_7IN5_V2_WIDTH - Paint.Height;
|
||||||
|
}
|
||||||
|
|
||||||
|
draw();
|
||||||
|
EPD_7IN5_V2_SendHalfImage(1, BlackImage);
|
||||||
|
|
||||||
|
EPD_7IN5_V2_TurnOnDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
void onConnectionEstablished()
|
void onConnectionEstablished()
|
||||||
{
|
{
|
||||||
// Subscribe to "mytopic/test" and display received message to Serial
|
// Subscribe to "mytopic/test" and display received message to Serial
|
||||||
client.subscribe("myink/test", [](const String & payload) {
|
client.subscribe("myink/test", [](const String & payload) {
|
||||||
Serial.println(payload);
|
Serial.println(payload);
|
||||||
cleaner.draw(current_msg_pos);
|
EPD_7IN5_V2_Init();
|
||||||
PositionalProperties msg_pos = {0, 300 , 300, 300};
|
draw_srceen([&payload](){
|
||||||
|
PositionalProperties msg_pos = {0, 300 , 300, 300};
|
||||||
|
draw_meeting("1", payload.c_str(), "msg", msg_pos, Font12);
|
||||||
|
});
|
||||||
|
|
||||||
Paint_Clear(WHITE);
|
EPD_7IN5_V2_Sleep();
|
||||||
Paint.WidthOffset = 0;
|
|
||||||
Paint.HeightOffset = 0;
|
|
||||||
current_msg_pos = draw_meeting("1", payload.c_str(), "msg", msg_pos, Font12);
|
|
||||||
EPD_7IN5_V2_SendHalfImage(0, BlackImage);
|
|
||||||
|
|
||||||
Paint_Clear(WHITE);
|
|
||||||
Paint.WidthOffset = 240;
|
|
||||||
Paint.HeightOffset = 0;
|
|
||||||
current_msg_pos = draw_meeting("1", payload.c_str(), "msg", msg_pos, Font12);
|
|
||||||
EPD_7IN5_V2_SendHalfImage(1, BlackImage);
|
|
||||||
EPD_7IN5_V2_TurnOnDisplay();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Subscribe to "mytopic/wildcardtest/#" and display received message to Serial
|
if(tests) {
|
||||||
client.subscribe("myink/wildcardtest/#", [](const String & topic, const String & payload) {
|
// Publish a message to "mytopic/test"
|
||||||
Serial.println(topic + ": " + payload);
|
client.publish("myink/test", "This is a message"); // You can activate the retain flag by setting the third parameter to true
|
||||||
});
|
|
||||||
|
|
||||||
// Publish a message to "mytopic/test"
|
// Execute delayed instructions
|
||||||
client.publish("myink/test", "This is a message"); // You can activate the retain flag by setting the third parameter to true
|
client.executeDelayed(5 * 1000, []() {
|
||||||
|
client.publish("myink/test", "This is a message sent 5 seconds later");
|
||||||
// Execute delayed instructions
|
});
|
||||||
client.executeDelayed(5 * 1000, []() {
|
}
|
||||||
client.publish("myink/test", "This is a message sent 5 seconds later");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
wifi_set_sleep_type(LIGHT_SLEEP_T);
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
DEV_Module_Init();
|
DEV_Module_Init();
|
||||||
|
|
||||||
EPD_7IN5_V2_Init();
|
EPD_7IN5_V2_Init();
|
||||||
Serial.begin(9600);
|
EPD_7IN5_V2_Sleep();
|
||||||
|
|
||||||
// Optionnal functionnalities of EspMQTTClient :
|
// Optionnal functionnalities of EspMQTTClient :
|
||||||
client.enableDebuggingMessages(); // Enable debugging messages sent to serial output
|
client.enableDebuggingMessages(); // Enable debugging messages sent to serial output
|
||||||
client.enableHTTPWebUpdater(); // Enable the web updater. User and password default to values of MQTTUsername and MQTTPassword. These can be overrited with enableHTTPWebUpdater("user", "password").
|
|
||||||
client.enableLastWillMessage("TestClient/lastwill", "I am going offline"); // You can activate the retain flag by setting the third parameter to true
|
client.enableLastWillMessage("TestClient/lastwill", "I am going offline"); // You can activate the retain flag by setting the third parameter to true
|
||||||
|
|
||||||
|
|
||||||
/* you have to edit the startup_stm32fxxx.s file and set a big enough heap size */
|
/* you have to edit the startup_stm32fxxx.s file and set a big enough heap size */
|
||||||
UWORD Imagesize = ((EPD_7IN5_V2_WIDTH % 8 == 0) ? (EPD_7IN5_V2_WIDTH / 8 ) : (EPD_7IN5_V2_WIDTH / 8 + 1)) * EPD_7IN5_V2_HEIGHT;
|
UWORD Imagesize = ((EPD_7IN5_V2_WIDTH % 8 == 0) ? (EPD_7IN5_V2_WIDTH / 8 ) : (EPD_7IN5_V2_WIDTH / 8 + 1)) * EPD_7IN5_V2_HEIGHT;
|
||||||
if ((BlackImage = (UBYTE *)malloc(Imagesize / 2)) == NULL) {
|
if ((BlackImage = (UBYTE *)malloc(Imagesize / 2)) == NULL) {
|
||||||
@@ -121,18 +134,13 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Paint_NewImage(BlackImage, EPD_7IN5_V2_WIDTH , EPD_7IN5_V2_HEIGHT / 2, 90, WHITE);
|
Paint_NewImage(BlackImage, EPD_7IN5_V2_WIDTH , EPD_7IN5_V2_HEIGHT / 2, 90, WHITE);
|
||||||
Paint_SelectImage(BlackImage);
|
Paint_SelectImage(BlackImage);
|
||||||
Paint_Clear(WHITE);
|
|
||||||
|
|
||||||
draw_meeting("Monday", "boring meeting\nbooring", "home", {0, 0 , 300, 300}, Font12);
|
|
||||||
|
|
||||||
EPD_7IN5_V2_SendHalfImage(0, BlackImage);
|
|
||||||
EPD_7IN5_V2_SendHalfImage(1, BlackImage);
|
|
||||||
EPD_7IN5_V2_TurnOnDisplay();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
//Serial.println("loop");
|
client.loop();
|
||||||
client.loop();
|
if(!tests && (WiFi.status() == WL_CONNECTED))
|
||||||
//EPD_7IN5_V2_Sleep();
|
{
|
||||||
|
delay(8000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user