/* * hmi.cpp * * Created on: 02.03.2016 * Author: dehottgw */ #include "hmi.h" #include 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_alarmMessageAvailable(false) { 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() { m_tft.begin(); m_tft.setRotation(1); m_tft.setTextSize(2); m_tft.fillScreen(BLACK); } 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::exec() { drawMessages(); }