|
@@ -1,7 +1,7 @@
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
// //
|
|
|
// Programname: HSA_LCD_Shield - Code //
|
|
|
-// Date: 23.04.2018 //
|
|
|
+// Date: 16.11.2018 //
|
|
|
// Description: Code-File of the LCD-Shield, which was designed and built in //
|
|
|
// the Modul "Elektronikdesign". In this file you can find the //
|
|
|
// code of all functions mentioned in the Header-File of the //
|
|
@@ -18,113 +18,60 @@
|
|
|
#include "HSA_LCD_Shield.h"
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
-//////////////////// Privat Functions ////////////////////
|
|
|
+//////////////////// Protected Functions ////////////////////
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-//////////////////// Send Message ////////////////////
|
|
|
+//////////////////// GPIO Configuration ////////////////////
|
|
|
|
|
|
-void HSA_LCD_Shield::_sendMessage(byte* bytes, byte sizeBytes){
|
|
|
+bool HSA_LCD_Shield::__gpioConfig(void) {
|
|
|
|
|
|
- // Small timeout before access the I²C-Bus
|
|
|
- delayMicroseconds(DELAY_TRANS_US);
|
|
|
+ // Save Pin configuration, depending of LCD-Shield version
|
|
|
+ if(this->__version == LCD_VERSION_5) {
|
|
|
|
|
|
- // Start I²C transmission
|
|
|
- Wire.beginTransmission(this->__i2cAddress);
|
|
|
+ // Save Pin configuration for buttons
|
|
|
+ this->__buttonUp = BUTTON_UP_V5;
|
|
|
+ this->__buttonRight = BUTTON_RIGHT_V5;
|
|
|
+ this->__buttonDown = BUTTON_DOWN_V5;
|
|
|
+ this->__buttonLeft = BUTTON_LEFT_V5;
|
|
|
|
|
|
- // Send an array of Bytes over I²C, depending of its size
|
|
|
- for(byte i = 0x00; i < sizeBytes; i++) Wire.write(bytes[i]);
|
|
|
-
|
|
|
- // Stop I²C transmission
|
|
|
- Wire.endTransmission();
|
|
|
+ // Save Pin configuration for LEDs
|
|
|
+ this->__ledGreen = LED_GREEN_V5;
|
|
|
+ this->__ledRed = LED_RED_V5;
|
|
|
|
|
|
- // Small timeout after access the I²C-Bus
|
|
|
- delayMicroseconds(DELAY_TRANS_US);
|
|
|
-
|
|
|
- // Exit function
|
|
|
- return;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-////////////////////////////////////////////////////////////////////////////////
|
|
|
-//////////////////// Public Functions ////////////////////
|
|
|
-////////////////////////////////////////////////////////////////////////////////
|
|
|
-
|
|
|
-//////////////////// Constructor ////////////////////
|
|
|
-
|
|
|
-HSA_LCD_Shield::HSA_LCD_Shield(char address, const char config[0x05]) {
|
|
|
-
|
|
|
- // Save I²C-Address
|
|
|
- this->__i2cAddress = address;
|
|
|
-
|
|
|
- // Save the configuration of Buttons/LEDs
|
|
|
- strcpy(this->__config,config);
|
|
|
-
|
|
|
- // Exit Constructor
|
|
|
- return;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-HSA_LCD_Shield::HSA_LCD_Shield(char address) {
|
|
|
-
|
|
|
- // Save I²C-Address
|
|
|
- this->__i2cAddress = address;
|
|
|
-
|
|
|
- // Save the configuration of Buttons/LEDs
|
|
|
- strcpy(this->__config,CONFIG_L1B1);
|
|
|
+ // Save Pin configuration for LCD-Backlight
|
|
|
+ this->__lcdBacklight = LCD_BACKLIGHT_V5;
|
|
|
|
|
|
- // Exit Constructor
|
|
|
- return;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-HSA_LCD_Shield::HSA_LCD_Shield(const char config[0x05]){
|
|
|
-
|
|
|
- // Save I²C-Address
|
|
|
- this->__i2cAddress = I2C_ADDRESS;
|
|
|
-
|
|
|
- // Save the configuration of Buttons/LEDs
|
|
|
- strcpy(this->__config,config);
|
|
|
-
|
|
|
- // Exit Constructor
|
|
|
- return;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-HSA_LCD_Shield::HSA_LCD_Shield(){
|
|
|
-
|
|
|
- // Save I²C-Address
|
|
|
- this->__i2cAddress = I2C_ADDRESS;
|
|
|
-
|
|
|
- // Save the configuration of Buttons/LEDs
|
|
|
- strcpy(this->__config,CONFIG_L1B1);
|
|
|
-
|
|
|
- // Exit Constructor
|
|
|
- return;
|
|
|
+ }
|
|
|
|
|
|
-}
|
|
|
+ else if(this->__version == LCD_VERSION_6) {
|
|
|
|
|
|
-//////////////////// Deconstructor ////////////////////
|
|
|
-
|
|
|
-HSA_LCD_Shield::~HSA_LCD_Shield(void) {
|
|
|
+ // Save Pin configuration for buttons
|
|
|
+ this->__buttonUp = BUTTON_UP_V6;
|
|
|
+ this->__buttonRight = BUTTON_RIGHT_V6;
|
|
|
+ this->__buttonDown = BUTTON_DOWN_V6;
|
|
|
+ this->__buttonLeft = BUTTON_LEFT_V6;
|
|
|
|
|
|
- // Exit function
|
|
|
- return;
|
|
|
+ // Save Pin configuration for LEDs
|
|
|
+ this->__ledGreen = LED_GREEN_V6;
|
|
|
+ this->__ledRed = LED_RED_V6;
|
|
|
|
|
|
-}
|
|
|
+ // Save Pin configuration for LCD-Backlight
|
|
|
+ this->__lcdBacklight = LCD_BACKLIGHT_V6;
|
|
|
|
|
|
-//////////////////// Start Configuration ////////////////////
|
|
|
+ }
|
|
|
|
|
|
-bool HSA_LCD_Shield::begin(void) {
|
|
|
+ // If LCD-Shield version is unknown, exit function with error
|
|
|
+ else return false;
|
|
|
|
|
|
// Check config-value and setup the LEDs, depending of config-value
|
|
|
if(strcmp(this->__config,CONFIG_L1B0) == false ||
|
|
|
strcmp(this->__config,CONFIG_L1B1) == false) {
|
|
|
|
|
|
// Setup LEDs
|
|
|
- pinMode(LED_GREEN,OUTPUT);
|
|
|
- pinMode(LED_RED,OUTPUT);
|
|
|
- digitalWrite(LED_GREEN,HIGH);
|
|
|
- digitalWrite(LED_RED,HIGH);
|
|
|
+ pinMode(this->__ledGreen,OUTPUT);
|
|
|
+ pinMode(this->__ledRed,OUTPUT);
|
|
|
+ digitalWrite(this->__ledGreen,HIGH);
|
|
|
+ digitalWrite(this->__ledRed,HIGH);
|
|
|
|
|
|
// Store the value "true", if LEDs are configured
|
|
|
this->__leds = true;
|
|
@@ -142,10 +89,10 @@ bool HSA_LCD_Shield::begin(void) {
|
|
|
strcmp(this->__config,CONFIG_L1B1) == false) {
|
|
|
|
|
|
// Setup Buttons
|
|
|
- pinMode(BUTTON_UP,INPUT);
|
|
|
- pinMode(BUTTON_RIGHT,INPUT);
|
|
|
- pinMode(BUTTON_DOWN,INPUT);
|
|
|
- pinMode(BUTTON_LEFT,INPUT);
|
|
|
+ pinMode(this->__buttonUp,INPUT);
|
|
|
+ pinMode(this->__buttonRight,INPUT);
|
|
|
+ pinMode(this->__buttonDown,INPUT);
|
|
|
+ pinMode(this->__buttonLeft,INPUT);
|
|
|
|
|
|
// Store the value "true", if buttons are configured
|
|
|
this->__buttons = true;
|
|
@@ -158,23 +105,18 @@ bool HSA_LCD_Shield::begin(void) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- // If config-value is unknown, quit configuration, otherwise configure I²C
|
|
|
+ // If config-value is unknown, quit configuration, otherwise configure Display
|
|
|
if(strcmp(this->__config,CONFIG_L1B1) != false &&
|
|
|
strcmp(this->__config,CONFIG_L0B1) != false &&
|
|
|
strcmp(this->__config,CONFIG_L1B0) != false &&
|
|
|
- strcmp(this->__config,CONFIG_L0B0) != false) {
|
|
|
-
|
|
|
- // Store the value false for buttons and LEDs are not configured
|
|
|
- this->__buttons = false;
|
|
|
- this->__leds = false;
|
|
|
-
|
|
|
- // If config-value unknown, exit function with negative feedback
|
|
|
- return false;
|
|
|
+ strcmp(this->__config,CONFIG_L0B0) != false) return false;
|
|
|
|
|
|
- }
|
|
|
else {
|
|
|
|
|
|
- // Initialize I²C
|
|
|
+ // Setup LCD-Backlight
|
|
|
+ pinMode(this->__lcdBacklight,OUTPUT);
|
|
|
+
|
|
|
+ // Initialize I²C as Master
|
|
|
Wire.begin();
|
|
|
|
|
|
// Define an array of Bytes for configure the Display
|
|
@@ -201,269 +143,262 @@ bool HSA_LCD_Shield::begin(void) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-//////////////////// LCD-Backlight ////////////////////
|
|
|
+////////////////////////////////////////////////////////////////////////////////
|
|
|
+//////////////////// Privat Functions ////////////////////
|
|
|
+////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-void HSA_LCD_Shield::lcdBacklight(bool value) {
|
|
|
+//////////////////// Send Message ////////////////////
|
|
|
|
|
|
- // Turning on/off LCD-Backlight
|
|
|
- digitalWrite(LCD_BACKLIGHT,value);
|
|
|
+void HSA_LCD_Shield::_sendMessage(byte* bytes, byte sizeBytes) {
|
|
|
|
|
|
- // Exit function
|
|
|
- return;
|
|
|
+ // Small timeout before access the I²C-Bus
|
|
|
+ delayMicroseconds(DELAY_TRANS_US);
|
|
|
|
|
|
-}
|
|
|
+ // Start I²C transmission
|
|
|
+ Wire.beginTransmission(this->__i2cAddress);
|
|
|
|
|
|
-//////////////////// Clear Display ////////////////////
|
|
|
+ // Send an array of Bytes over I²C, depending of its size
|
|
|
+ for(byte i = 0x00; i < sizeBytes; i++) Wire.write(bytes[i]);
|
|
|
|
|
|
-void HSA_LCD_Shield::clearDisplay(void) {
|
|
|
+ // Stop I²C transmission
|
|
|
+ Wire.endTransmission();
|
|
|
|
|
|
- // Define an array of Bytes for clearing the Display
|
|
|
- byte buffer[] = {CONTROL_BYTE_CB,
|
|
|
- LCD_PARA_CLR_DIS};
|
|
|
-
|
|
|
- // Send array of bytes
|
|
|
- _sendMessage(buffer, sizeof(buffer));
|
|
|
+ // Small timeout after access the I²C-Bus
|
|
|
+ delayMicroseconds(DELAY_TRANS_US);
|
|
|
|
|
|
// Exit function
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////////////////
|
|
|
+//////////////////// Public Functions ////////////////////
|
|
|
+////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-//////////////////// Return Config ////////////////////
|
|
|
+//////////////////// Constructor ////////////////////
|
|
|
|
|
|
-char* HSA_LCD_Shield::returnConfig(void) {
|
|
|
+HSA_LCD_Shield::HSA_LCD_Shield(byte version, const char config[CONFIG_SIZE]) {
|
|
|
+
|
|
|
+ // Save LCD-Shield version
|
|
|
+ this->__version = version;
|
|
|
|
|
|
- // Exit function and return the configuration value
|
|
|
- return this->__config;
|
|
|
+ // Save the configuration of Buttons/LEDs
|
|
|
+ strcpy(this->__config,config);
|
|
|
+
|
|
|
+ // Exit Constructor
|
|
|
+ return;
|
|
|
|
|
|
}
|
|
|
|
|
|
-//////////////////// Return I²C-Address ////////////////////
|
|
|
+HSA_LCD_Shield::HSA_LCD_Shield(byte version) {
|
|
|
|
|
|
-char HSA_LCD_Shield::returnAddress(void){
|
|
|
+ // Save LCD-Shield version
|
|
|
+ this->__version = version;
|
|
|
|
|
|
- // Exit function and return the value of the I²C-Address
|
|
|
- return this->__i2cAddress;
|
|
|
+ // Save the configuration of Buttons/LEDs
|
|
|
+ strcpy(this->__config,CONFIG_L1B1);
|
|
|
+
|
|
|
+ // Exit Constructor
|
|
|
+ return;
|
|
|
|
|
|
}
|
|
|
|
|
|
-//////////////////// Control LEDs ////////////////////
|
|
|
+HSA_LCD_Shield::HSA_LCD_Shield(const char config[CONFIG_SIZE]){
|
|
|
|
|
|
-void HSA_LCD_Shield::controlLed(char ledPin, bool state) {
|
|
|
+ // Save LCD-Shield version
|
|
|
+ this->__version = LCD_VERSION_6;
|
|
|
|
|
|
- // Change state of a LED, if they are configured
|
|
|
- if(this->__leds) digitalWrite(ledPin,!state);
|
|
|
+ // Save the configuration of Buttons/LEDs
|
|
|
+ strcpy(this->__config,config);
|
|
|
|
|
|
- // Exit function
|
|
|
+ // Exit Constructor
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
-//////////////////// Get the pressed Button ////////////////////
|
|
|
-
|
|
|
-char HSA_LCD_Shield::getButton() {
|
|
|
-
|
|
|
- // return 1, if only button "Up" is pressed and configured
|
|
|
- if(digitalRead(BUTTON_UP) &&
|
|
|
- !digitalRead(BUTTON_RIGHT) &&
|
|
|
- !digitalRead(BUTTON_DOWN) &&
|
|
|
- !digitalRead(BUTTON_LEFT) &&
|
|
|
- this->__buttons)
|
|
|
- return BUTTON_UP;
|
|
|
-
|
|
|
- // return 2, if only button "Right" is pressed and configured
|
|
|
- if(!digitalRead(BUTTON_UP) &&
|
|
|
- digitalRead(BUTTON_RIGHT) &&
|
|
|
- !digitalRead(BUTTON_DOWN) &&
|
|
|
- !digitalRead(BUTTON_LEFT) &&
|
|
|
- this->__buttons)
|
|
|
- return BUTTON_RIGHT;
|
|
|
+HSA_LCD_Shield::HSA_LCD_Shield(){
|
|
|
|
|
|
- // return 3, if only button "Down" is pressed and configured
|
|
|
- if(!digitalRead(BUTTON_UP) &&
|
|
|
- !digitalRead(BUTTON_RIGHT) &&
|
|
|
- digitalRead(BUTTON_DOWN) &&
|
|
|
- !digitalRead(BUTTON_LEFT) &&
|
|
|
- this->__buttons)
|
|
|
- return BUTTON_DOWN;
|
|
|
+ // Save LCD-Shield version
|
|
|
+ this->__version = LCD_VERSION_6;
|
|
|
|
|
|
- // return 4, if only button "Left" is pressed and configured
|
|
|
- if(!digitalRead(BUTTON_UP) &&
|
|
|
- !digitalRead(BUTTON_RIGHT) &&
|
|
|
- !digitalRead(BUTTON_DOWN) &&
|
|
|
- digitalRead(BUTTON_LEFT) &&
|
|
|
- this->__buttons)
|
|
|
- return BUTTON_LEFT;
|
|
|
+ // Save the configuration of Buttons/LEDs
|
|
|
+ strcpy(this->__config,CONFIG_L1B1);
|
|
|
|
|
|
- // return false, if no button or more than one button is pressed
|
|
|
- return false;
|
|
|
+ // Exit Constructor
|
|
|
+ return;
|
|
|
|
|
|
}
|
|
|
|
|
|
-//////////////////// Write Row 1 ////////////////////
|
|
|
-
|
|
|
-void HSA_LCD_Shield::writeRow1(const char* bytes) {
|
|
|
-
|
|
|
- // Define buffer for test Message
|
|
|
- byte buffer[ARRAY_SIZE_ROW] = "";
|
|
|
+//////////////////// Deconstructor ////////////////////
|
|
|
|
|
|
- // Define variable to store a boolean value, if a control-byte was found
|
|
|
- bool controlByte = false;
|
|
|
+HSA_LCD_Shield::~HSA_LCD_Shield(void) {
|
|
|
|
|
|
- // Create data-array with message and send the message at the end
|
|
|
- for(byte i = 0x00; i <= ARRAY_SIZE_ROW; i++){
|
|
|
+ // Exit function
|
|
|
+ return;
|
|
|
|
|
|
- // Set control-byte for changing parameter in the first iteration
|
|
|
- if(i == 0x00) buffer[i] = CONTROL_BYTE_CB;
|
|
|
+}
|
|
|
|
|
|
- // Change the cursor position to row 1 in the second iteration
|
|
|
- if(i == 0x01) buffer[i] = LCD_PARA_DIS_ROW1;
|
|
|
+//////////////////// Start Configuration ////////////////////
|
|
|
|
|
|
- // Set control-byte for writing to the display in the third iteration
|
|
|
- if(i == 0x02) buffer[i] = CONTROL_BYTE_DCB;
|
|
|
+bool HSA_LCD_Shield::begin(void) {
|
|
|
|
|
|
- // Copy bytes into the buffer between iteration 2 to 13
|
|
|
- if(i > 0x02 && i < ARRAY_SIZE_ROW) {
|
|
|
+ // Save standard I²C-Address of LC-Display
|
|
|
+ this->__i2cAddress = I2C_ADDRESS;
|
|
|
|
|
|
- // If no control-byte was found, copy byte into buffer
|
|
|
- if(!controlByte) {
|
|
|
+ // Configure GPIOs and exit
|
|
|
+ return __gpioConfig();
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
- // Check byte for control-byte, if not, copy byte into buffer
|
|
|
- if(isControl(bytes[i - 0x03])) controlByte = true;
|
|
|
- else buffer[i] = bytes[i - 0x03];
|
|
|
+bool HSA_LCD_Shield::begin(byte address) {
|
|
|
|
|
|
- }
|
|
|
+ // Save I²C-Address of LC-Display
|
|
|
+ this->__i2cAddress = address;
|
|
|
|
|
|
- // If control-byte was found, fill message with free space
|
|
|
- if(controlByte) {
|
|
|
-
|
|
|
- // Fill Buffer with free space
|
|
|
- buffer[i] = FREE_SPACE;
|
|
|
+ // Configure GPIOs and exit
|
|
|
+ return __gpioConfig();
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
- }
|
|
|
- }
|
|
|
+//////////////////// LCD-Backlight ////////////////////
|
|
|
|
|
|
- // Send message in the last iteration
|
|
|
- if(i == ARRAY_SIZE_ROW) _sendMessage(buffer,sizeof(buffer));
|
|
|
+void HSA_LCD_Shield::lcdBacklight(bool value) {
|
|
|
|
|
|
- }
|
|
|
+ // Turning on/off LCD-Backlight
|
|
|
+ digitalWrite(this->__lcdBacklight,value);
|
|
|
|
|
|
// Exit function
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
-//////////////////// Write Row 2 ////////////////////
|
|
|
-
|
|
|
-void HSA_LCD_Shield::writeRow2(const char* bytes) {
|
|
|
+//////////////////// Clear Display ////////////////////
|
|
|
|
|
|
- // Define buffer for test Message
|
|
|
- byte buffer[ARRAY_SIZE_ROW] = "";
|
|
|
+void HSA_LCD_Shield::clearDisplay(void) {
|
|
|
|
|
|
- // Define variable to store a boolean value, if a control-byte was found
|
|
|
- bool controlByte = false;
|
|
|
+ // Define an array of Bytes for clearing the Display
|
|
|
+ byte buffer[] = {CONTROL_BYTE_CB,
|
|
|
+ LCD_PARA_CLR_DIS};
|
|
|
+
|
|
|
+ // Send array of bytes
|
|
|
+ _sendMessage(buffer, sizeof(buffer));
|
|
|
|
|
|
- // Create data-array with message and send the message at the end
|
|
|
- for(byte i = 0x00; i <= ARRAY_SIZE_ROW; i++){
|
|
|
+ // Exit function
|
|
|
+ return;
|
|
|
|
|
|
- // Set control-byte for changing parameter in the first iteration
|
|
|
- if(i == 0x00) buffer[i] = CONTROL_BYTE_CB;
|
|
|
+}
|
|
|
|
|
|
- // Change the cursor position to row 2 in the second iteration
|
|
|
- if(i == 0x01) buffer[i] = LCD_PARA_DIS_ROW2;
|
|
|
+/////////////////// Return Version ////////////////////
|
|
|
|
|
|
- // Set control-byte for writing to the display in the third iteration
|
|
|
- if(i == 0x02) buffer[i] = CONTROL_BYTE_DCB;
|
|
|
+byte HSA_LCD_Shield::returnVersion(void) {
|
|
|
|
|
|
- // Copy bytes into the buffer between iteration 2 to 13
|
|
|
- if(i > 0x02 && i < ARRAY_SIZE_ROW) {
|
|
|
+ // Exit function and return the configured Version for the LCD-Shield
|
|
|
+ return this->__version;
|
|
|
|
|
|
- // If no control-byte was found, copy byte into buffer
|
|
|
- if(!controlByte) {
|
|
|
+}
|
|
|
|
|
|
- // Check byte for control-byte, if not, copy byte into buffer
|
|
|
- if(isControl(bytes[i - 0x03])) controlByte = true;
|
|
|
- else buffer[i] = bytes[i - 0x03];
|
|
|
+//////////////////// Return Config ////////////////////
|
|
|
|
|
|
- }
|
|
|
+char* HSA_LCD_Shield::returnConfig(void) {
|
|
|
|
|
|
- // If control-byte was found, fill message with free space
|
|
|
- if(controlByte) {
|
|
|
-
|
|
|
- // Fill Buffer with free space
|
|
|
- buffer[i] = FREE_SPACE;
|
|
|
+ // Exit function and return the configuration value
|
|
|
+ return this->__config;
|
|
|
|
|
|
- }
|
|
|
- }
|
|
|
+}
|
|
|
|
|
|
- // Send message in the last iteration
|
|
|
- if(i == ARRAY_SIZE_ROW) _sendMessage(buffer,sizeof(buffer));
|
|
|
+//////////////////// Return I²C-Address ////////////////////
|
|
|
|
|
|
- }
|
|
|
+byte HSA_LCD_Shield::returnAddress(void){
|
|
|
|
|
|
- // Exit function
|
|
|
- return;
|
|
|
+ // Exit function and return the value of the I²C-Address
|
|
|
+ return this->__i2cAddress;
|
|
|
|
|
|
}
|
|
|
|
|
|
-//////////////////// Write Row 3 ////////////////////
|
|
|
-
|
|
|
-void HSA_LCD_Shield::writeRow3(const char* bytes) {
|
|
|
+//////////////////// Control LEDs ////////////////////
|
|
|
|
|
|
- // Define buffer for test Message
|
|
|
- byte buffer[ARRAY_SIZE_ROW] = "";
|
|
|
+bool HSA_LCD_Shield::controlLED(char ledPin, bool state) {
|
|
|
|
|
|
- // Define variable to store a boolean value, if a control-byte was found
|
|
|
- bool controlByte = false;
|
|
|
+ // Checks, whether LED-Pins are configured
|
|
|
+ if(this->__leds) {
|
|
|
|
|
|
- // Create data-array with message and send the message at the end
|
|
|
- for(byte i = 0x00; i <= ARRAY_SIZE_ROW; i++){
|
|
|
+ // Checks, whether LED-Color is known and control LED
|
|
|
+ if(ledPin == LED_GREEN) {
|
|
|
+ digitalWrite(this->__ledGreen,!state);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- // Set control-byte for changing parameter in the first iteration
|
|
|
- if(i == 0x00) buffer[i] = CONTROL_BYTE_CB;
|
|
|
+ if(ledPin == LED_RED) {
|
|
|
+ digitalWrite(this->__ledRed,!state);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Exit function with error, if LED-Pins are not configured or LED-Color is
|
|
|
+ // unknown
|
|
|
+ return false;
|
|
|
|
|
|
- // Change the cursor position to row 3 in the second iteration
|
|
|
- if(i == 0x01) buffer[i] = LCD_PARA_DIS_ROW3;
|
|
|
+}
|
|
|
|
|
|
- // Set control-byte for writing to the display in the third iteration
|
|
|
- if(i == 0x02) buffer[i] = CONTROL_BYTE_DCB;
|
|
|
+//////////////////// Get LED state ////////////////////
|
|
|
|
|
|
- // Copy bytes into the buffer between iteration 2 to 13
|
|
|
- if(i > 0x02 && i < ARRAY_SIZE_ROW) {
|
|
|
+bool HSA_LCD_Shield::getLED(char ledPin) {
|
|
|
|
|
|
- // If no control-byte was found, copy byte into buffer
|
|
|
- if(!controlByte) {
|
|
|
+ // Exit function and return the value of chosen LED
|
|
|
+ if(ledPin == LED_GREEN) return !digitalRead(this->__ledGreen);
|
|
|
+ else if(ledPin == LED_RED) return !digitalRead(this->__ledRed);
|
|
|
+ else return false;
|
|
|
|
|
|
- // Check byte for control-byte
|
|
|
- if(isControl(bytes[i - 0x03])) controlByte = true;
|
|
|
+}
|
|
|
|
|
|
- // If not, copy byte into buffer
|
|
|
- else buffer[i] = bytes[i - 0x03];
|
|
|
+//////////////////// Get the pressed Button ////////////////////
|
|
|
|
|
|
- }
|
|
|
+byte HSA_LCD_Shield::getButton() {
|
|
|
|
|
|
- // If control-byte was found, fill message with free space
|
|
|
- if(controlByte) {
|
|
|
-
|
|
|
- // Fill Buffer with free space
|
|
|
- buffer[i] = FREE_SPACE;
|
|
|
+ // return 1, if only button "Up" is pressed and configured
|
|
|
+ if(digitalRead(this->__buttonUp) &&
|
|
|
+ !digitalRead(this->__buttonRight) &&
|
|
|
+ !digitalRead(this->__buttonDown) &&
|
|
|
+ !digitalRead(this->__buttonLeft) &&
|
|
|
+ this->__buttons)
|
|
|
+ return BUTTON_UP;
|
|
|
+
|
|
|
+ // return 2, if only button "Right" is pressed and configured
|
|
|
+ if(!digitalRead(this->__buttonUp) &&
|
|
|
+ digitalRead(this->__buttonRight) &&
|
|
|
+ !digitalRead(this->__buttonDown) &&
|
|
|
+ !digitalRead(this->__buttonLeft) &&
|
|
|
+ this->__buttons)
|
|
|
+ return BUTTON_RIGHT;
|
|
|
|
|
|
- }
|
|
|
- }
|
|
|
+ // return 3, if only button "Down" is pressed and configured
|
|
|
+ if(!digitalRead(this->__buttonUp) &&
|
|
|
+ !digitalRead(this->__buttonRight) &&
|
|
|
+ digitalRead(this->__buttonDown) &&
|
|
|
+ !digitalRead(this->__buttonLeft) &&
|
|
|
+ this->__buttons)
|
|
|
+ return BUTTON_DOWN;
|
|
|
|
|
|
- // Send message in the last iteration
|
|
|
- if(i == ARRAY_SIZE_ROW) _sendMessage(buffer,sizeof(buffer));
|
|
|
+ // return 4, if only button "Left" is pressed and configured
|
|
|
+ if(!digitalRead(this->__buttonUp) &&
|
|
|
+ !digitalRead(this->__buttonRight) &&
|
|
|
+ !digitalRead(this->__buttonDown) &&
|
|
|
+ digitalRead(this->__buttonLeft) &&
|
|
|
+ this->__buttons)
|
|
|
+ return BUTTON_LEFT;
|
|
|
|
|
|
- }
|
|
|
+ // return false, if no button or more than one button is pressed or
|
|
|
+ // buttons are not configured
|
|
|
+ return false;
|
|
|
|
|
|
- // Exit function
|
|
|
- return;
|
|
|
}
|
|
|
|
|
|
-//////////////////// Write Row 4 ////////////////////
|
|
|
+//////////////////// Write Row ////////////////////
|
|
|
+
|
|
|
+bool HSA_LCD_Shield::writeRow(byte row, const char* text) {
|
|
|
|
|
|
-void HSA_LCD_Shield::writeRow4(const char* bytes) {
|
|
|
+ // If chosen Row does not exist, exit function with error
|
|
|
+ if(!(row >= 0x01 && row <= 0x04)) return false;
|
|
|
|
|
|
// Define buffer for test Message
|
|
|
byte buffer[ARRAY_SIZE_ROW] = "";
|
|
@@ -472,29 +407,31 @@ void HSA_LCD_Shield::writeRow4(const char* bytes) {
|
|
|
bool controlByte = false;
|
|
|
|
|
|
// Create data-array with message and send the message at the end
|
|
|
- for(byte i = 0x00; i <= ARRAY_SIZE_ROW; i++){
|
|
|
+ for(byte i = 0x00; i < ARRAY_SIZE_ROW; i++) {
|
|
|
|
|
|
// Set control-byte for changing parameter in the first iteration
|
|
|
if(i == 0x00) buffer[i] = CONTROL_BYTE_CB;
|
|
|
|
|
|
- // Change the cursor position to row 4 in the second iteration
|
|
|
- if(i == 0x01) buffer[i] = LCD_PARA_DIS_ROW4;
|
|
|
+ // Change the cursor position to row in the second iteration.
|
|
|
+ if(i == 0x01 && row == 0x01) buffer[i] = LCD_PARA_DIS_ROW1;
|
|
|
+ if(i == 0x01 && row == 0x02) buffer[i] = LCD_PARA_DIS_ROW2;
|
|
|
+ if(i == 0x01 && row == 0x03) buffer[i] = LCD_PARA_DIS_ROW3;
|
|
|
+ if(i == 0x01 && row == 0x04) buffer[i] = LCD_PARA_DIS_ROW4;
|
|
|
|
|
|
// Set control-byte for writing to the display in the third iteration
|
|
|
if(i == 0x02) buffer[i] = CONTROL_BYTE_DCB;
|
|
|
|
|
|
- // Copy bytes into the buffer between iteration 2 to 13
|
|
|
+ // Copy text into the buffer between iteration 2 to 13
|
|
|
if(i > 0x02 && i < ARRAY_SIZE_ROW) {
|
|
|
|
|
|
// If no control-byte was found, copy byte into buffer
|
|
|
if(!controlByte) {
|
|
|
|
|
|
// Check byte for control-byte
|
|
|
- if(isControl(bytes[i - 0x03])) controlByte = true;
|
|
|
+ if(isControl(text[i - 0x03])) controlByte = true;
|
|
|
|
|
|
// if not, copy byte into buffer
|
|
|
- else buffer[i] = bytes[i - 0x03];
|
|
|
-
|
|
|
+ else buffer[i] = text[i - 0x03];
|
|
|
}
|
|
|
|
|
|
// If control-byte was found, fill message with free space
|
|
@@ -502,25 +439,21 @@ void HSA_LCD_Shield::writeRow4(const char* bytes) {
|
|
|
|
|
|
// Fill Buffer with free space
|
|
|
buffer[i] = FREE_SPACE;
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // Send message in the last iteration
|
|
|
- if(i == ARRAY_SIZE_ROW) _sendMessage(buffer,sizeof(buffer));
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- // Exit function
|
|
|
- return;
|
|
|
+ // Send message
|
|
|
+ _sendMessage(buffer,sizeof(buffer));
|
|
|
|
|
|
-}
|
|
|
+ // Exit function with success
|
|
|
+ return true;
|
|
|
|
|
|
-//////////////////// Write 4 Rows ////////////////////
|
|
|
+}
|
|
|
|
|
|
-void HSA_LCD_Shield::write4Rows(const char* bytes) {
|
|
|
+bool HSA_LCD_Shield::writeRow(const char* text) {
|
|
|
|
|
|
- // Define buffer for test Message
|
|
|
+ // Define buffer for test Message
|
|
|
char buffer[ARRAY_SIZE_ROW] = "";
|
|
|
|
|
|
// Define variable to store the actual row position
|
|
@@ -539,20 +472,20 @@ void HSA_LCD_Shield::write4Rows(const char* bytes) {
|
|
|
if(rowPosition == LCD_PARA_DIS_ROW1) {
|
|
|
|
|
|
// If counted bytes has not reach max value, copy byte into buffer
|
|
|
- if(countBytes < 0x0A) buffer[countBytes] = bytes[i];
|
|
|
+ if(countBytes < 0x0A) buffer[countBytes] = text[i];
|
|
|
|
|
|
// Check, if copied byte was control-byte
|
|
|
- if(isControl(bytes[i])) {
|
|
|
+ if(isControl(text[i])) {
|
|
|
|
|
|
// Check if control-byte was \n or \r or end of string,
|
|
|
// set counted bytes to max value
|
|
|
- if(bytes[i] == BACKSLASH_N ||
|
|
|
- bytes[i] == BACKSLASH_R ||
|
|
|
- bytes[i] == STRING_END)
|
|
|
+ if(text[i] == BACKSLASH_N ||
|
|
|
+ text[i] == BACKSLASH_R ||
|
|
|
+ text[i] == STRING_END)
|
|
|
countBytes = 0x0A;
|
|
|
|
|
|
// Check if control-byte was end of the string, deactivate row position
|
|
|
- if(bytes[i] == STRING_END) rowPosition = false;
|
|
|
+ if(text[i] == STRING_END) rowPosition = false;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -566,15 +499,15 @@ void HSA_LCD_Shield::write4Rows(const char* bytes) {
|
|
|
countBytes = 0x00;
|
|
|
|
|
|
// write first row
|
|
|
- writeRow1(buffer);
|
|
|
+ writeRow(0x01, buffer);
|
|
|
|
|
|
// If row position is deactivated
|
|
|
if(rowPosition == false) {
|
|
|
|
|
|
// clear following rows
|
|
|
- writeRow2(&bytes[i]);
|
|
|
- writeRow3(&bytes[i]);
|
|
|
- writeRow4(&bytes[i]);
|
|
|
+ writeRow(0x02, &text[i]);
|
|
|
+ writeRow(0x03, &text[i]);
|
|
|
+ writeRow(0x04, &text[i]);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -591,20 +524,20 @@ void HSA_LCD_Shield::write4Rows(const char* bytes) {
|
|
|
if(rowPosition == LCD_PARA_DIS_ROW2) {
|
|
|
|
|
|
// If counted bytes has not reach max value, copy byte into buffer
|
|
|
- if(countBytes < 0x0A) buffer[countBytes] = bytes[i];
|
|
|
+ if(countBytes < 0x0A) buffer[countBytes] = text[i];
|
|
|
|
|
|
// Check, if copied byte was control-byte
|
|
|
- if(isControl(bytes[i])) {
|
|
|
+ if(isControl(text[i])) {
|
|
|
|
|
|
// Check if control-byte was \n or \r or end of string,
|
|
|
// set counted bytes to max value
|
|
|
- if(bytes[i] == BACKSLASH_N ||
|
|
|
- bytes[i] == BACKSLASH_R ||
|
|
|
- bytes[i] == STRING_END)
|
|
|
+ if(text[i] == BACKSLASH_N ||
|
|
|
+ text[i] == BACKSLASH_R ||
|
|
|
+ text[i] == STRING_END)
|
|
|
countBytes = 0x0A;
|
|
|
|
|
|
// Check if control-byte was end of the string, deactivate row position
|
|
|
- if(bytes[i] == STRING_END) rowPosition = false;
|
|
|
+ if(text[i] == STRING_END) rowPosition = false;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -618,14 +551,14 @@ void HSA_LCD_Shield::write4Rows(const char* bytes) {
|
|
|
countBytes = 0x00;
|
|
|
|
|
|
// write second row
|
|
|
- writeRow2(buffer);
|
|
|
+ writeRow(0x02, buffer);
|
|
|
|
|
|
// If row position is deactivated
|
|
|
if(rowPosition == false) {
|
|
|
|
|
|
// clear following rows
|
|
|
- writeRow3(&bytes[i]);
|
|
|
- writeRow4(&bytes[i]);
|
|
|
+ writeRow(0x03, &text[i]);
|
|
|
+ writeRow(0x04, &text[i]);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -642,20 +575,20 @@ void HSA_LCD_Shield::write4Rows(const char* bytes) {
|
|
|
if(rowPosition == LCD_PARA_DIS_ROW3) {
|
|
|
|
|
|
// If counted bytes has not reach max value, copy byte into buffer
|
|
|
- if(countBytes < 0x0A) buffer[countBytes] = bytes[i];
|
|
|
+ if(countBytes < 0x0A) buffer[countBytes] = text[i];
|
|
|
|
|
|
// Check, if copied byte was control-byte
|
|
|
- if(isControl(bytes[i])) {
|
|
|
+ if(isControl(text[i])) {
|
|
|
|
|
|
// Check if control-byte was \n or \r or end of string,
|
|
|
// set counted bytes to max value
|
|
|
- if(bytes[i] == BACKSLASH_N ||
|
|
|
- bytes[i] == BACKSLASH_R ||
|
|
|
- bytes[i] == STRING_END)
|
|
|
+ if(text[i] == BACKSLASH_N ||
|
|
|
+ text[i] == BACKSLASH_R ||
|
|
|
+ text[i] == STRING_END)
|
|
|
countBytes = 0x0A;
|
|
|
|
|
|
// Check if control-byte was end of the string, deactivate row position
|
|
|
- if(bytes[i] == STRING_END) rowPosition = false;
|
|
|
+ if(text[i] == STRING_END) rowPosition = false;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -669,10 +602,10 @@ void HSA_LCD_Shield::write4Rows(const char* bytes) {
|
|
|
countBytes = 0x00;
|
|
|
|
|
|
// write third row
|
|
|
- writeRow3(buffer);
|
|
|
+ writeRow(0x03, buffer);
|
|
|
|
|
|
// If row position is deactivated, clear following row
|
|
|
- if(rowPosition == false) writeRow4(&bytes[i]);
|
|
|
+ if(rowPosition == false) writeRow(0x04, &text[i]);
|
|
|
|
|
|
// Otherwise set row position the row 4
|
|
|
else rowPosition = LCD_PARA_DIS_ROW4;
|
|
@@ -687,20 +620,20 @@ void HSA_LCD_Shield::write4Rows(const char* bytes) {
|
|
|
if(rowPosition == LCD_PARA_DIS_ROW4) {
|
|
|
|
|
|
// If counted bytes has not reach max value, copy byte into buffer
|
|
|
- if(countBytes < 0x0A) buffer[countBytes] = bytes[i];
|
|
|
+ if(countBytes < 0x0A) buffer[countBytes] = text[i];
|
|
|
|
|
|
// Check, if copied byte was control-byte
|
|
|
- if(isControl(bytes[i])) {
|
|
|
+ if(isControl(text[i])) {
|
|
|
|
|
|
// Check if control-byte was \n or \r or end of string,
|
|
|
// set counted bytes to max value
|
|
|
- if(bytes[i] == BACKSLASH_N ||
|
|
|
- bytes[i] == BACKSLASH_R ||
|
|
|
- bytes[i] == STRING_END)
|
|
|
+ if(text[i] == BACKSLASH_N ||
|
|
|
+ text[i] == BACKSLASH_R ||
|
|
|
+ text[i] == STRING_END)
|
|
|
countBytes = 0x0A;
|
|
|
|
|
|
// Check if control-byte was end of the string, deactivate row position
|
|
|
- if(bytes[i] == STRING_END) rowPosition = false;
|
|
|
+ if(text[i] == STRING_END) rowPosition = false;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -714,7 +647,7 @@ void HSA_LCD_Shield::write4Rows(const char* bytes) {
|
|
|
countBytes = 0x00;
|
|
|
|
|
|
// write fourth row
|
|
|
- writeRow4(buffer);
|
|
|
+ writeRow(0x04, buffer);
|
|
|
|
|
|
// If row position is not deactivated, deaktivate row position
|
|
|
if(rowPosition != false) rowPosition = false;
|
|
@@ -727,6 +660,52 @@ void HSA_LCD_Shield::write4Rows(const char* bytes) {
|
|
|
}
|
|
|
|
|
|
// Exit function
|
|
|
- return;
|
|
|
+ return true;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//////////////////// Write Position XY ////////////////////
|
|
|
+
|
|
|
+bool HSA_LCD_Shield::writeXY(byte row, byte column, const char* text) {
|
|
|
+
|
|
|
+ // If chosen Row does not exist, exit function with error
|
|
|
+ if(!(row >= 0x01 && row <= 0x04)) return false;
|
|
|
+
|
|
|
+ // If chosen Column does not exist, exit function with error
|
|
|
+ if(!(column >= 0x01 && column <= 0x0A)) return false;
|
|
|
+
|
|
|
+ // create variable to store count of chars
|
|
|
+ byte count = 0x00;
|
|
|
+
|
|
|
+ // Count chars inside of text
|
|
|
+ for(byte i = 0x00; i < 0x0A && !isControl(text[i]); i++) count++;
|
|
|
+
|
|
|
+ // Define buffer for text Message
|
|
|
+ byte buffer[ARRAY_SIZE_ROW - (0x0A - count)] = "";
|
|
|
+
|
|
|
+ // Create data-array with message and send the message at the end
|
|
|
+ for(byte i = 0x00; i < sizeof(buffer); i++) {
|
|
|
+
|
|
|
+ // Set control-byte for changing parameter in the first iteration
|
|
|
+ if(i == 0x00) buffer[i] = CONTROL_BYTE_CB;
|
|
|
+
|
|
|
+ // Change the cursor position to row/column in the second iteration.
|
|
|
+ if(i == 0x01 && row == 0x01) buffer[i] = LCD_PARA_DIS_ROW1 | (column - 0x01);
|
|
|
+ if(i == 0x01 && row == 0x02) buffer[i] = LCD_PARA_DIS_ROW2 | (column - 0x01);
|
|
|
+ if(i == 0x01 && row == 0x03) buffer[i] = LCD_PARA_DIS_ROW3 | (column - 0x01);
|
|
|
+ if(i == 0x01 && row == 0x04) buffer[i] = LCD_PARA_DIS_ROW4 | (column - 0x01);
|
|
|
+
|
|
|
+ // Set control-byte for writing to the display
|
|
|
+ if(i == 0x02) buffer[i] = CONTROL_BYTE_DCB;
|
|
|
+
|
|
|
+ // Copy text into the buffer between iteration 2 to 13
|
|
|
+ if(i >= 0x03 && i < sizeof(buffer)) buffer[i] = text[i - 0x03];
|
|
|
+ }
|
|
|
+
|
|
|
+ // Send message
|
|
|
+ _sendMessage(buffer,sizeof(buffer));
|
|
|
+
|
|
|
+ // Exit function with success
|
|
|
+ return true;
|
|
|
|
|
|
}
|