message displaying works

This commit is contained in:
hg 2016-03-04 14:30:30 +01:00
parent c520e7731c
commit c04b24a1f0
6 changed files with 60 additions and 19 deletions

View File

@ -2,4 +2,6 @@
syntax: glob
.DS_Store
syntax: regexp
.DS_Store
.DS_Store
syntax: regexp
^Release$

View File

@ -154,10 +154,10 @@ environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA
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.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=1457047039
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.LOCAL/value=1457087444
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=1457043439
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.UTC/value=1457083844
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.usbmodem32
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/JANTJE.COM_PORT/value=/dev/tty.usbmodem33
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

@ -13,14 +13,12 @@ void setup() {
Serial.begin(9600);
hmi.begin();
hmi.updateMessage();
MqttClientNS::begin();
}
void loop() {
if (tick.check()) {
hmi.toggleAlarmState();
Serial << "tick" << endl;
}

17
hmi.cpp
View File

@ -25,14 +25,8 @@ Hmi::Hmi() : m_tft(6, 9, 11, 13, -1, 12), // m_tft(LCD_CS, LCD_CD, LCD_WR, LCD_R
}
void Hmi::begin() {
// m_tft.reset();
// m_displayIdentifier = m_tft.readID();
// Serial << "display id: " << m_displayIdentifier << endl;
// m_tft.begin(m_displayIdentifier);
m_tft.begin();
Serial << "tft begin done" << endl;
m_tft.setRotation(1);
}
void Hmi::updateMessage() {
@ -47,6 +41,15 @@ void Hmi::updateMessage() {
strcpy(m_messageSlots[5].body, "123456789");
}
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;
}
}
void Hmi::toggleAlarmState() {
m_alarmMessageAvailable = ! m_alarmMessageAvailable;
@ -79,7 +82,7 @@ void Hmi::drawMessages() {
m_tft << l << ": ";
if (strlen(m_messageSlots[i].header) > 0) {
m_tft << m_messageSlots[i].header;
for (uint8_t spaces = 0; spaces < (BUFFERLEN_MESSAGESLOT - 1 - strlen(m_messageSlots[i].header)); spaces++) {
for (uint8_t spaces = 0; spaces < (BUFFERLEN_MESSAGESLOT - strlen(m_messageSlots[i].header)); spaces++) {
m_tft << " ";
}
m_tft << " : " << m_messageSlots[i].body;

9
hmi.h
View File

@ -31,14 +31,14 @@ namespace HmiNS {
const static uint16_t YELLOW = 0xFFE0;
const static uint16_t WHITE = 0xFFFF;
const static uint8_t BUFFERLEN_MESSAGESLOT = 10;
const static uint8_t NUM_OF_MESSAGESLOTS = 12;
const static uint8_t BUFFERLEN_MESSAGESLOT = 9;
const static uint8_t NUM_OF_MESSAGESLOTS = 13;
}
struct MessageSlot {
char header[HmiNS::BUFFERLEN_MESSAGESLOT];
char body[HmiNS::BUFFERLEN_MESSAGESLOT];
char header[HmiNS::BUFFERLEN_MESSAGESLOT+1];
char body[HmiNS::BUFFERLEN_MESSAGESLOT+1];
uint32_t timestamp;
};
@ -48,6 +48,7 @@ public:
void begin();
void exec();
void updateMessage();
void updateMessage(uint8_t slot, char* header, char* body);
void toggleAlarmState(); // only for debug
private:
void drawMessages();

View File

@ -11,8 +11,14 @@
#include <Ethernet.h>
#include <Metro.h>
#include <PubSubClient.h>
#include "hmi.h"
extern Hmi hmi;
static const char MESSAGE_TOPIC[] = "IoT/Message/Monitor";
static const char ALARM_TOPIC[] = "IoT/Alarm/Monitor";
void callback(char* topic, byte* payload, unsigned int length);
@ -36,6 +42,37 @@ void callback(char* topic, byte* payload, unsigned int length) {
memcpy(buffer, payload, length);
*(buffer + length) = 0;
Serial << "Received message: " << length << ", " << String(topic) << ", " << String(buffer) << endl;
if (!(strcmp(topic, MESSAGE_TOPIC) && strcmp(topic, ALARM_TOPIC))) {
char *paramPtr = buffer;
char *slotStr = 0;
char *headerStr = 0;
char *bodyStr = 0;
if ((paramPtr != 0) && (*paramPtr != 0)){
slotStr = strsep(&paramPtr, " ");
}
if ((paramPtr != 0) && (*paramPtr != 0)){
headerStr = strsep(&paramPtr, " ");
}
if ((paramPtr != 0) && (*paramPtr != 0)){
bodyStr = strsep(&paramPtr, " ");
}
if ((slotStr != 0) && (*slotStr != 0) &&
(headerStr != 0) && (*headerStr != 0) &&
(bodyStr != 0) && (*bodyStr != 0)) {
uint8_t slot = atoi(slotStr);
if (! strcmp(topic, ALARM_TOPIC)) {
Serial << "Alarm" << endl;
} else if (! strcmp(topic, MESSAGE_TOPIC)) {
hmi.updateMessage(slot, headerStr, bodyStr);
}
}
} else {
Serial << "Strange, unknown topic received" << endl;
}
}
}
@ -80,8 +117,8 @@ void MqttClientNS::exec() {
case 3:
Serial.println("discState 3");
if (mqttClient.connect("Monitor")) {
mqttClient.subscribe("IoT/Message/Monitor");
mqttClient.subscribe("IoT/Alarm/Monitor");
mqttClient.subscribe(MESSAGE_TOPIC);
mqttClient.subscribe(ALARM_TOPIC);
disconnectTime = millis();
disconnectState = 0;
} else {