Browse Source

LCD-Init Status in Displaymethoden abfragen/kontrollieren

Tobias Müller 5 years ago
parent
commit
b3b8667f11
2 changed files with 52 additions and 22 deletions
  1. 35 12
      HSA_LCD_Shield.cpp
  2. 17 10
      HSA_LCD_Shield.h

+ 35 - 12
HSA_LCD_Shield.cpp

@@ -225,7 +225,7 @@ HSA_LCD_Shield::HSA_LCD_Shield(const char config[CONFIG_SIZE]){
 
 }
 
-HSA_LCD_Shield::HSA_LCD_Shield(){
+HSA_LCD_Shield::HSA_LCD_Shield(void){
 
   // Save LCD-Shield version
   this->__version = LCD_VERSION_6;
@@ -254,8 +254,11 @@ HSA_LCD_Shield::~HSA_LCD_Shield(void) {
 
 bool HSA_LCD_Shield::begin(void) {
 
-  // Configure GPIOs and exit
-  return __gpioConfig();
+  // Configure GPIOs
+  this->__lcd = __gpioConfig();
+  
+  // Exit function
+  return this->__lcd;
   
 }
 
@@ -264,26 +267,35 @@ bool HSA_LCD_Shield::begin(byte address) {
   // Save I²C-Address of LC-Display
   this->__i2cAddress = address;
 
-  // Configure GPIOs and exit
-  return __gpioConfig();
+  // Configure GPIOs
+  this->__lcd = __gpioConfig();
+
+  // Exit function
+  return this->__lcd;
   
 }
 
 ////////////////////             LCD-Backlight              ////////////////////
 
-void HSA_LCD_Shield::lcdBacklight(bool value) {
+bool HSA_LCD_Shield::lcdBacklight(bool value) {
+
+  // check, whether LCD is configured
+  if(this->__lcd == false) return false;
 
   // Turning on/off LCD-Backlight
   digitalWrite(this->__lcdBacklight,value);
 
   // Exit function
-  return;
+  return true;
 
 }
 
 ////////////////////             Clear Display              ////////////////////
 
-void HSA_LCD_Shield::clearDisplay(void) {
+bool HSA_LCD_Shield::clearDisplay(void) {
+
+  // check, whether LCD is configured
+  if(this->__lcd == false) return false;
 
   // Define an array of Bytes for clearing the Display
   byte buffer[] = {CONTROL_BYTE_CB,
@@ -293,7 +305,7 @@ void HSA_LCD_Shield::clearDisplay(void) {
   _sendMessage(buffer, sizeof(buffer));
 
   // Exit function
-  return;
+  return true;
 
 }
 
@@ -354,8 +366,10 @@ bool HSA_LCD_Shield::controlLED(byte ledPin, bool state) {
 bool HSA_LCD_Shield::getLED(byte ledPin) {
 
   // 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);
+  if(ledPin == LED_GREEN && this->__leds) 
+    return !digitalRead(this->__ledGreen);
+  else if(ledPin == LED_RED && this->__leds) 
+    return !digitalRead(this->__ledRed);
   else return false;
 
 }
@@ -406,6 +420,9 @@ byte HSA_LCD_Shield::getButton() {
 
 bool HSA_LCD_Shield::writeRow(byte row, const char* text) {
 
+  // check, whether LCD is configured
+  if(this->__lcd == false) return false;
+
   // If chosen Row does not exist, exit function with error
   if(!(row >= 0x01 && row <= 0x04)) return false;
 
@@ -462,7 +479,10 @@ bool HSA_LCD_Shield::writeRow(byte row, const char* text) {
 
 bool HSA_LCD_Shield::writeRow(const char* text) {
 
-    // Define buffer for test Message
+  // check, whether LCD is configured
+  if(this->__lcd == false) return false;
+
+  // Define buffer for test Message
   char buffer[ARRAY_SIZE_ROW] = ""; 
 
   // Define variable to store the actual row position
@@ -677,6 +697,9 @@ bool HSA_LCD_Shield::writeRow(const char* text) {
 
 bool HSA_LCD_Shield::writeXY(byte row, byte column, const char* text) {
 
+  // check, whether LCD is configured
+  if(this->__lcd == false) return false;
+
   // If chosen Row does not exist, exit function with error
   if(!(row >= 0x01 && row <= 0x04)) return false;
 

+ 17 - 10
HSA_LCD_Shield.h

@@ -342,8 +342,9 @@ byte __version;             //! @brief Store used LCD-Shield version
 byte __i2cAddress;          //! @brief Store the I²C-Address of the LC-Display
 char __config[CONFIG_SIZE]; //! @brief Store the Buttons/LEDs-Configuration
 
-bool __buttons;     //! @brief Store the value "true", if the buttons configured
-bool __leds;        //! @brief Store the value "true", if the LEDs configured
+bool __buttons;     //! @brief Store the value "true", if buttons are configured
+bool __leds;        //! @brief Store the value "true", if LEDs are configured
+bool __lcd;         //! @brief Store the value "true", if the lcd is configured
 
 byte __buttonUp;    //! @brief Store address of button up
 byte __buttonDown;  //! @brief Store address of button down
@@ -392,7 +393,7 @@ public:
 /**
  * @brief Construct a new HSA_LCD_Shield object with default Shield-ver./Config
  */
-HSA_LCD_Shield();
+HSA_LCD_Shield(void);
 
 /**
  * @brief Construct a new HSA_LCD_Shield object with different Shield version
@@ -449,15 +450,21 @@ bool begin(byte address);
  * @brief Turning on/off the LCD-Backlight
  * 
  * @param value Boolean value for turning on/off the LCD-Backlight
+ * 
+ * @return true control LCD_Backlight successful
+ * @return false LCD_Backlight was not configured
  */
-void lcdBacklight(bool value);
+bool lcdBacklight(bool value);
 
 ////////////////////             Clear Display              ////////////////////
 
 /**
  * @brief Clear the LC-Display
+ * 
+ * @return true clear LC-Display successful
+ * @return false LCD was not configured
  */
-void clearDisplay(void);
+bool clearDisplay(void);
 
 ///////////////////             Return Version              ////////////////////
 
@@ -516,12 +523,12 @@ bool getLED(byte ledPin);
 /**
  * @brief Return the number of the button, which is pressed
  * 
- * @return char 0x00, if no or more than one button is pressed or buttons are 
+ * @return byte 0x00, if no or more than one button is pressed or buttons are 
  *              not configured
- * @return char 0x01, if only button "Up" is pressed
- * @return char 0x02, if only button "Right" is pressed
- * @return char 0x03, if only button "Down" is pressed
- * @return char 0x04, if only button "Left" is pressed
+ * @return byte 0x01, if only button "Up" is pressed
+ * @return byte 0x02, if only button "Right" is pressed
+ * @return byte 0x03, if only button "Down" is pressed
+ * @return byte 0x04, if only button "Left" is pressed
  */
 byte getButton();