120 lines
3.2 KiB
C++
120 lines
3.2 KiB
C++
/*
|
|
* hmi.cpp
|
|
*
|
|
* Created on: 02.03.2016
|
|
* Author: dehottgw
|
|
*/
|
|
|
|
#include "hmi.h"
|
|
#include <Streaming.h>
|
|
|
|
using namespace HmiNS;
|
|
|
|
Hmi::Hmi() : m_tft(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST, TFT_MISO), // m_tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET),
|
|
m_ctp(),
|
|
m_backLightPin(TFT_BACKLIGHT),
|
|
m_backLightEnable(true),
|
|
m_displayIdentifier(0),
|
|
m_alarmMessageAvailable(false),
|
|
m_seconds(0),
|
|
m_lightOn(LIGHT_ON),
|
|
m_lightOff(LIGHT_OFF)
|
|
{
|
|
|
|
for (uint8_t i = 0; i < NUM_OF_MESSAGESLOTS; i++) {
|
|
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;
|
|
}
|
|
|
|
}
|
|
|
|
void Hmi::begin() {
|
|
pinMode(5, OUTPUT);
|
|
digitalWrite(5, HIGH);
|
|
|
|
m_tft.begin();
|
|
m_tft.setRotation(1);
|
|
m_tft.setTextSize(2);
|
|
m_tft.fillScreen(BLACK);
|
|
|
|
if (! m_ctp.begin(40)) { // pass in 'sensitivity' coefficient
|
|
Serial.println("Couldn't start FT6206 touchscreen controller");
|
|
while (1);
|
|
}
|
|
|
|
}
|
|
|
|
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_messageSlots[index].updateRequired = true;
|
|
}
|
|
}
|
|
|
|
void Hmi::toggleAlarmState() {
|
|
m_alarmMessageAvailable = ! m_alarmMessageAvailable;
|
|
}
|
|
|
|
void Hmi::drawMessages() {
|
|
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 (l < 10) { // prefix numbers with only one digit with a leading 0
|
|
m_tft << " ";
|
|
}
|
|
m_tft << l << ": ";
|
|
if (strlen(m_messageSlots[i].header) > 0) {
|
|
m_tft << m_messageSlots[i].header;
|
|
for (uint8_t spaces = 0; spaces < (BUFFERLEN_MESSAGESLOT - strlen(m_messageSlots[i].header)); spaces++) {
|
|
m_tft << " ";
|
|
}
|
|
m_tft << " : " << m_messageSlots[i].body;
|
|
m_tft << endl;
|
|
} else {
|
|
m_tft << endl;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void Hmi::setSeconds(uint32_t seconds) {
|
|
m_seconds = seconds;
|
|
}
|
|
|
|
void Hmi::exec() {
|
|
drawMessages();
|
|
|
|
static uint32_t oldSeconds = 0;
|
|
if (m_seconds != oldSeconds) {
|
|
oldSeconds = m_seconds;
|
|
Serial << "LIGHT_OFF: " << m_lightOff << endl;
|
|
Serial << "LIGHT_ON: " << m_lightOn << endl;
|
|
Serial << "enable: " << m_backLightEnable << endl;
|
|
Serial << "Seconds: " << m_seconds << endl;
|
|
}
|
|
|
|
if (((m_seconds > m_lightOff) || (m_seconds < m_lightOn)) && !m_ctp.touched() && m_backLightEnable) {
|
|
m_backLightEnable = false;
|
|
digitalWrite(m_backLightPin, LOW);
|
|
Serial << "lights off" << endl;
|
|
}
|
|
|
|
if ((((m_seconds < m_lightOff) && (m_seconds > m_lightOn)) || m_ctp.touched()) && !m_backLightEnable) {
|
|
m_backLightEnable = true;
|
|
digitalWrite(m_backLightPin, HIGH);
|
|
Serial << "lights on" << endl;
|
|
}
|
|
}
|