add draw screen and sleepmode

This commit is contained in:
stubbfelnewpc
2020-06-11 18:33:30 +02:00
parent 7a2a0fba48
commit 9623edbb71
2 changed files with 54 additions and 45 deletions

View File

@@ -12,5 +12,6 @@
platform = espressif8266
board = esp12e
framework = arduino
monitor_speed = 115200
lib_deps =
EspMQTTClient

View File

@@ -1,3 +1,4 @@
#include <Arduino.h>
#include <DEV_Config.h>
#include <EspMQTTClient.h>
@@ -9,6 +10,9 @@
#include "StackPanel.hpp"
#include "TextBlock.hpp"
extern "C" {
#include "user_interface.h"
}
EspMQTTClient client(
"08151234711-Gast",
@@ -22,11 +26,7 @@ EspMQTTClient client(
UBYTE *BlackImage;
sFONT * font = &Font8;
PositionalProperties current_msg_pos = {0, 0 , 0, 0};
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);
bool tests = true;
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);
}
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()
{
// Subscribe to "mytopic/test" and display received message to Serial
client.subscribe("myink/test", [](const String & payload) {
Serial.println(payload);
cleaner.draw(current_msg_pos);
PositionalProperties msg_pos = {0, 300 , 300, 300};
Serial.println(payload);
EPD_7IN5_V2_Init();
draw_srceen([&payload](){
PositionalProperties msg_pos = {0, 300 , 300, 300};
draw_meeting("1", payload.c_str(), "msg", msg_pos, Font12);
});
Paint_Clear(WHITE);
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();
EPD_7IN5_V2_Sleep();
});
// Subscribe to "mytopic/wildcardtest/#" and display received message to Serial
client.subscribe("myink/wildcardtest/#", [](const String & topic, const String & payload) {
Serial.println(topic + ": " + payload);
});
if(tests) {
// Publish a message to "mytopic/test"
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"
client.publish("myink/test", "This is a message"); // You can activate the retain flag by setting the third parameter to true
// Execute delayed instructions
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() {
wifi_set_sleep_type(LIGHT_SLEEP_T);
// put your setup code here, to run once:
DEV_Module_Init();
EPD_7IN5_V2_Init();
Serial.begin(9600);
EPD_7IN5_V2_Sleep();
// Optionnal functionnalities of EspMQTTClient :
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
/* 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;
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_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();
Paint_SelectImage(BlackImage);
}
void loop() {
//Serial.println("loop");
client.loop();
//EPD_7IN5_V2_Sleep();
client.loop();
if(!tests && (WiFi.status() == WL_CONNECTED))
{
delay(8000);
}
}