ready so far
This commit is contained in:
parent
627656e7b6
commit
cb9483e6ff
@ -151,13 +151,13 @@ environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.CONFI
|
|||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.CONFIG.PATH/value=${A.TOOLS.AVRDUDE.CONFIG.PATH}
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.CONFIG.PATH/value=${A.TOOLS.AVRDUDE.CONFIG.PATH}
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.DTS/delimiter=\:
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.DTS/delimiter=\:
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.DTS/operation=replace
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.DTS/operation=replace
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.DTS/value=0
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.DTS/value=3600
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.LOCAL/delimiter=\:
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.LOCAL/delimiter=\:
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.LOCAL/operation=replace
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.LOCAL/operation=replace
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.LOCAL/value=1457279065
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.LOCAL/value=1468171079
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.UTC/delimiter=\:
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.UTC/delimiter=\:
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.UTC/operation=replace
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.UTC/operation=replace
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.UTC/value=1457275465
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.UTC/value=1468163879
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.ZONE/delimiter=\:
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.ZONE/delimiter=\:
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.ZONE/operation=replace
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.ZONE/operation=replace
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.ZONE/value=3600
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.ZONE/value=3600
|
||||||
@ -370,7 +370,7 @@ environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/JANTJE.
|
|||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/JANTJE.BUILD_VARIANT/value=mega
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/JANTJE.BUILD_VARIANT/value=mega
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/JANTJE.COM_PORT/delimiter=\:
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/JANTJE.COM_PORT/delimiter=\:
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/JANTJE.COM_PORT/operation=replace
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/JANTJE.COM_PORT/operation=replace
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/JANTJE.COM_PORT/value=/dev/tty.usbmodem36
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/JANTJE.COM_PORT/value=/dev/tty.usbmodemFD111
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/JANTJE.COM_PROGMR/delimiter=\:
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/JANTJE.COM_PROGMR/delimiter=\:
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/JANTJE.COM_PROGMR/operation=replace
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/JANTJE.COM_PROGMR/operation=replace
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/JANTJE.COM_PROGMR/value=Default
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/JANTJE.COM_PROGMR/value=Default
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <Metro.h>
|
#include <Metro.h>
|
||||||
#include <Streaming.h>
|
#include <Streaming.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
|
||||||
|
|
||||||
#include "hmi.h"
|
#include "hmi.h"
|
||||||
#include "mqttClient.h"
|
#include "mqttClient.h"
|
||||||
@ -19,9 +21,15 @@ void setup() {
|
|||||||
|
|
||||||
hmi.tft()->println("Running");
|
hmi.tft()->println("Running");
|
||||||
delay(10000);
|
delay(10000);
|
||||||
|
|
||||||
|
hmi.clear();
|
||||||
|
|
||||||
|
wdt_enable(WDTO_8S);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
wdt_reset();
|
||||||
|
|
||||||
if (tick.check()) {
|
if (tick.check()) {
|
||||||
Serial << "tick" << endl;
|
Serial << "tick" << endl;
|
||||||
}
|
}
|
||||||
|
40
hmi.cpp
40
hmi.cpp
@ -12,7 +12,6 @@ using namespace HmiNS;
|
|||||||
|
|
||||||
Hmi::Hmi() : m_tft(6, 9, 11, 13, -1, 12), // m_tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET),
|
Hmi::Hmi() : m_tft(6, 9, 11, 13, -1, 12), // m_tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET),
|
||||||
m_displayIdentifier(0),
|
m_displayIdentifier(0),
|
||||||
m_messageDrawUpdateRequired(true),
|
|
||||||
m_alarmMessageAvailable(false)
|
m_alarmMessageAvailable(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -20,6 +19,7 @@ Hmi::Hmi() : m_tft(6, 9, 11, 13, -1, 12), // m_tft(LCD_CS, LCD_CD, LCD_WR, LCD_R
|
|||||||
memset(m_messageSlots[i].header, 0, BUFFERLEN_MESSAGESLOT);
|
memset(m_messageSlots[i].header, 0, BUFFERLEN_MESSAGESLOT);
|
||||||
memset(m_messageSlots[i].body, 0, BUFFERLEN_MESSAGESLOT);
|
memset(m_messageSlots[i].body, 0, BUFFERLEN_MESSAGESLOT);
|
||||||
m_messageSlots[i].timestamp = 0;
|
m_messageSlots[i].timestamp = 0;
|
||||||
|
m_messageSlots[i].updateRequired = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -28,55 +28,33 @@ void Hmi::begin() {
|
|||||||
m_tft.begin();
|
m_tft.begin();
|
||||||
m_tft.setRotation(1);
|
m_tft.setRotation(1);
|
||||||
m_tft.setTextSize(2);
|
m_tft.setTextSize(2);
|
||||||
|
m_tft.fillScreen(BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hmi::updateMessage() {
|
void Hmi::clear() {
|
||||||
m_messageDrawUpdateRequired = true;
|
m_tft.fillScreen(BLACK);
|
||||||
strcpy(m_messageSlots[0].header, "abc");
|
|
||||||
strcpy(m_messageSlots[0].body, "123");
|
|
||||||
strcpy(m_messageSlots[1].header, "abcdefghi");
|
|
||||||
strcpy(m_messageSlots[1].body, "123456789");
|
|
||||||
strcpy(m_messageSlots[2].header, "abcdefghi");
|
|
||||||
strcpy(m_messageSlots[2].body, "123456789");
|
|
||||||
strcpy(m_messageSlots[5].header, "abcdefghi");
|
|
||||||
strcpy(m_messageSlots[5].body, "123456789");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hmi::updateMessage(uint8_t slot, char* header, char* body) {
|
void Hmi::updateMessage(uint8_t slot, char* header, char* body) {
|
||||||
uint8_t index = slot - 1; // slots start at 1, the index starts at 0
|
uint8_t index = slot - 1; // slots start at 1, the index starts at 0
|
||||||
if (index < NUM_OF_MESSAGESLOTS) {
|
if (index < NUM_OF_MESSAGESLOTS) {
|
||||||
strncpy(m_messageSlots[index].header, header, BUFFERLEN_MESSAGESLOT);
|
strncpy(m_messageSlots[index].header, header, BUFFERLEN_MESSAGESLOT);
|
||||||
strncpy(m_messageSlots[index].body, body, BUFFERLEN_MESSAGESLOT);
|
strncpy(m_messageSlots[index].body, body, BUFFERLEN_MESSAGESLOT);
|
||||||
m_messageSlots[index].timestamp = millis();
|
m_messageSlots[index].timestamp = millis();
|
||||||
m_messageDrawUpdateRequired = true;
|
m_messageSlots[index].updateRequired = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hmi::toggleAlarmState() {
|
void Hmi::toggleAlarmState() {
|
||||||
m_alarmMessageAvailable = ! m_alarmMessageAvailable;
|
m_alarmMessageAvailable = ! m_alarmMessageAvailable;
|
||||||
m_messageDrawUpdateRequired = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hmi::drawMessages() {
|
void Hmi::drawMessages() {
|
||||||
if (m_messageDrawUpdateRequired) {
|
|
||||||
m_messageDrawUpdateRequired = false;
|
|
||||||
m_tft.setTextSize(2);
|
|
||||||
m_tft.setCursor(0,0);
|
|
||||||
if (m_alarmMessageAvailable) {
|
|
||||||
m_tft.fillScreen(RED);
|
|
||||||
// m_tft.invertDisplay(false);
|
|
||||||
} else {
|
|
||||||
m_tft.fillScreen(GREEN);
|
|
||||||
// m_tft.invertDisplay(true);
|
|
||||||
}
|
|
||||||
m_tft << endl;
|
|
||||||
for (uint8_t i = 0; i < NUM_OF_MESSAGESLOTS; i++) {
|
for (uint8_t i = 0; i < NUM_OF_MESSAGESLOTS; i++) {
|
||||||
|
if (m_messageSlots[i].updateRequired) {
|
||||||
|
m_messageSlots[i].updateRequired = false;
|
||||||
|
m_tft.setCursor(0, 5+i*22);
|
||||||
|
m_tft.fillRect(0, 5+i*22, 320, 22, BLACK);
|
||||||
uint8_t l = i + 1;
|
uint8_t l = i + 1;
|
||||||
if (i % 2 == 0) {
|
|
||||||
m_tft.setTextColor(WHITE);
|
|
||||||
} else {
|
|
||||||
m_tft.setTextColor(YELLOW);
|
|
||||||
}
|
|
||||||
if (l < 10) { // prefix numbers with only one digit with a leading 0
|
if (l < 10) { // prefix numbers with only one digit with a leading 0
|
||||||
m_tft << " ";
|
m_tft << " ";
|
||||||
}
|
}
|
||||||
|
6
hmi.h
6
hmi.h
@ -32,13 +32,14 @@ namespace HmiNS {
|
|||||||
const static uint16_t WHITE = 0xFFFF;
|
const static uint16_t WHITE = 0xFFFF;
|
||||||
|
|
||||||
const static uint8_t BUFFERLEN_MESSAGESLOT = 9;
|
const static uint8_t BUFFERLEN_MESSAGESLOT = 9;
|
||||||
const static uint8_t NUM_OF_MESSAGESLOTS = 13;
|
const static uint8_t NUM_OF_MESSAGESLOTS = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct MessageSlot {
|
struct MessageSlot {
|
||||||
char header[HmiNS::BUFFERLEN_MESSAGESLOT+1];
|
char header[HmiNS::BUFFERLEN_MESSAGESLOT+1];
|
||||||
char body[HmiNS::BUFFERLEN_MESSAGESLOT+1];
|
char body[HmiNS::BUFFERLEN_MESSAGESLOT+1];
|
||||||
|
bool updateRequired;
|
||||||
uint32_t timestamp;
|
uint32_t timestamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -48,14 +49,13 @@ public:
|
|||||||
void begin();
|
void begin();
|
||||||
void exec();
|
void exec();
|
||||||
Print *tft() { return &m_tft; };
|
Print *tft() { return &m_tft; };
|
||||||
void updateMessage();
|
|
||||||
void updateMessage(uint8_t slot, char* header, char* body);
|
void updateMessage(uint8_t slot, char* header, char* body);
|
||||||
void toggleAlarmState(); // only for debug
|
void toggleAlarmState(); // only for debug
|
||||||
|
void clear();
|
||||||
private:
|
private:
|
||||||
void drawMessages();
|
void drawMessages();
|
||||||
Adafruit_ILI9341 m_tft;
|
Adafruit_ILI9341 m_tft;
|
||||||
uint16_t m_displayIdentifier;
|
uint16_t m_displayIdentifier;
|
||||||
bool m_messageDrawUpdateRequired;
|
|
||||||
bool m_alarmMessageAvailable;
|
bool m_alarmMessageAvailable;
|
||||||
MessageSlot m_messageSlots[HmiNS::NUM_OF_MESSAGESLOTS];
|
MessageSlot m_messageSlots[HmiNS::NUM_OF_MESSAGESLOTS];
|
||||||
};
|
};
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
|
|
||||||
extern Hmi hmi;
|
extern Hmi hmi;
|
||||||
|
|
||||||
static const char MESSAGE_TOPIC[] = "IoT/Message/Monitor";
|
static const char MESSAGE_TOPIC[] = "IoT/Monitor/Message";
|
||||||
static const char ALARM_TOPIC[] = "IoT/Alarm/Monitor";
|
static const char ALARM_TOPIC[] = "IoT/Monitor/Alarm";
|
||||||
|
|
||||||
|
|
||||||
void callback(char* topic, byte* payload, unsigned int length);
|
void callback(char* topic, byte* payload, unsigned int length);
|
||||||
@ -137,12 +137,12 @@ void MqttClientNS::begin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MqttClientNS::exec() {
|
void MqttClientNS::exec() {
|
||||||
// if (minute.check() == 1) {
|
// if (minute.check() == 1) {
|
||||||
// byte r = Ethernet.maintain();
|
// byte r = Ethernet.maintain();
|
||||||
// Serial << "Ethernet.maintain: " << r << endl;
|
// Serial << "Ethernet.maintain: " << r << endl;
|
||||||
// if ((r == DHCP_CHECK_REBIND_FAIL) || (r == DHCP_CHECK_RENEW_FAIL)) {
|
// if ((r == DHCP_CHECK_REBIND_FAIL) || (r == DHCP_CHECK_RENEW_FAIL)) {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if ((disconnectState == 0) && (! mqttClient.loop())) {
|
if ((disconnectState == 0) && (! mqttClient.loop())) {
|
||||||
disconnectState = 1;
|
disconnectState = 1;
|
||||||
@ -171,6 +171,7 @@ void MqttClientNS::exec() {
|
|||||||
mqttClient.subscribe(MESSAGE_TOPIC);
|
mqttClient.subscribe(MESSAGE_TOPIC);
|
||||||
mqttClient.subscribe(ALARM_TOPIC);
|
mqttClient.subscribe(ALARM_TOPIC);
|
||||||
disconnectTime = millis();
|
disconnectTime = millis();
|
||||||
|
mqttClient.publish("IoT/Monitor/Started", "monitor started");
|
||||||
disconnectState = 0;
|
disconnectState = 0;
|
||||||
} else {
|
} else {
|
||||||
disconnectState = 1;
|
disconnectState = 1;
|
||||||
@ -188,7 +189,7 @@ void MqttClientNS::exec() {
|
|||||||
|
|
||||||
if (disconnectState == 0) {
|
if (disconnectState == 0) {
|
||||||
String msg = String("{ \"metadata\": { \"device\": \"Monitor\" }, \"data\": { \"uptime\": ") + uptime + String("}}");
|
String msg = String("{ \"metadata\": { \"device\": \"Monitor\" }, \"data\": { \"uptime\": ") + uptime + String("}}");
|
||||||
mqttClient.publish("IoT/Heartbeat/Monitor", (char*)msg.c_str());
|
mqttClient.publish("IoT/Monitor/Heartbeat", (char*)msg.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user