ready so far

This commit is contained in:
hg 2016-07-10 18:38:53 +02:00
parent 627656e7b6
commit cb9483e6ff
5 changed files with 35 additions and 48 deletions

View File

@ -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.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/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/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/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/operation=replace
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.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/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/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/JANTJE.COM_PROGMR/value=Default

View File

@ -2,6 +2,8 @@
#include <Metro.h>
#include <Streaming.h>
#include <avr/wdt.h>
#include "hmi.h"
#include "mqttClient.h"
@ -19,9 +21,15 @@ void setup() {
hmi.tft()->println("Running");
delay(10000);
hmi.clear();
wdt_enable(WDTO_8S);
}
void loop() {
wdt_reset();
if (tick.check()) {
Serial << "tick" << endl;
}

42
hmi.cpp
View File

@ -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),
m_displayIdentifier(0),
m_messageDrawUpdateRequired(true),
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].body, 0, BUFFERLEN_MESSAGESLOT);
m_messageSlots[i].timestamp = 0;
m_messageSlots[i].updateRequired = false;
}
}
@ -28,55 +28,33 @@ void Hmi::begin() {
m_tft.begin();
m_tft.setRotation(1);
m_tft.setTextSize(2);
m_tft.fillScreen(BLACK);
}
void Hmi::updateMessage() {
m_messageDrawUpdateRequired = true;
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::clear() {
m_tft.fillScreen(BLACK);
}
void Hmi::updateMessage(uint8_t slot, char* header, char* body) {
uint8_t index = slot - 1; // slots start at 1, the index starts at 0
if (index < NUM_OF_MESSAGESLOTS) {
strncpy(m_messageSlots[index].header, header, BUFFERLEN_MESSAGESLOT);
strncpy(m_messageSlots[index].body, body, BUFFERLEN_MESSAGESLOT);
m_messageSlots[index].timestamp = millis();
m_messageDrawUpdateRequired = true;
m_messageSlots[index].updateRequired = true;
}
}
void Hmi::toggleAlarmState() {
m_alarmMessageAvailable = ! m_alarmMessageAvailable;
m_messageDrawUpdateRequired = true;
}
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;
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
m_tft << " ";
}

6
hmi.h
View File

@ -32,13 +32,14 @@ namespace HmiNS {
const static uint16_t WHITE = 0xFFFF;
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 {
char header[HmiNS::BUFFERLEN_MESSAGESLOT+1];
char body[HmiNS::BUFFERLEN_MESSAGESLOT+1];
bool updateRequired;
uint32_t timestamp;
};
@ -48,14 +49,13 @@ public:
void begin();
void exec();
Print *tft() { return &m_tft; };
void updateMessage();
void updateMessage(uint8_t slot, char* header, char* body);
void toggleAlarmState(); // only for debug
void clear();
private:
void drawMessages();
Adafruit_ILI9341 m_tft;
uint16_t m_displayIdentifier;
bool m_messageDrawUpdateRequired;
bool m_alarmMessageAvailable;
MessageSlot m_messageSlots[HmiNS::NUM_OF_MESSAGESLOTS];
};

View File

@ -18,8 +18,8 @@
extern Hmi hmi;
static const char MESSAGE_TOPIC[] = "IoT/Message/Monitor";
static const char ALARM_TOPIC[] = "IoT/Alarm/Monitor";
static const char MESSAGE_TOPIC[] = "IoT/Monitor/Message";
static const char ALARM_TOPIC[] = "IoT/Monitor/Alarm";
void callback(char* topic, byte* payload, unsigned int length);
@ -137,12 +137,12 @@ void MqttClientNS::begin() {
}
void MqttClientNS::exec() {
// if (minute.check() == 1) {
// byte r = Ethernet.maintain();
// Serial << "Ethernet.maintain: " << r << endl;
// if ((r == DHCP_CHECK_REBIND_FAIL) || (r == DHCP_CHECK_RENEW_FAIL)) {
// }
// }
// if (minute.check() == 1) {
// byte r = Ethernet.maintain();
// Serial << "Ethernet.maintain: " << r << endl;
// if ((r == DHCP_CHECK_REBIND_FAIL) || (r == DHCP_CHECK_RENEW_FAIL)) {
// }
// }
if ((disconnectState == 0) && (! mqttClient.loop())) {
disconnectState = 1;
@ -171,6 +171,7 @@ void MqttClientNS::exec() {
mqttClient.subscribe(MESSAGE_TOPIC);
mqttClient.subscribe(ALARM_TOPIC);
disconnectTime = millis();
mqttClient.publish("IoT/Monitor/Started", "monitor started");
disconnectState = 0;
} else {
disconnectState = 1;
@ -188,7 +189,7 @@ void MqttClientNS::exec() {
if (disconnectState == 0) {
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());
}
}