Lcm1602: clean up API and use maa_result_t
authorBrendan Le Foll <brendan.le.foll@intel.com>
Fri, 23 May 2014 13:21:10 +0000 (14:21 +0100)
committerBrendan Le Foll <brendan.le.foll@intel.com>
Fri, 23 May 2014 13:21:10 +0000 (14:21 +0100)
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
src/lcm1602/lcm1602.cxx
src/lcm1602/lcm1602.h

index 31324ad..0c9d49c 100644 (file)
@@ -68,12 +68,15 @@ using namespace upm;
 
 Lcm1602::Lcm1602(int bus_in, int addr_in)
 {
-    address = addr_in;
-    bus = bus_in;
-    maa_init();
-    m_i2c = maa_i2c_init(bus);
+    m_address = addr_in;
+    m_bus = bus_in;
 
-    maa_i2c_address(m_i2c, address);
+    m_i2c = maa_i2c_init(m_bus);
+
+    maa_result_t ret = maa_i2c_address(m_i2c, m_address);
+    if (ret != MAA_SUCCESS) {
+        fprintf(stderr, "Messed up i2c bus\n");
+    }
 
     usleep(50000);
     expandWrite(LCD_BACKLIGHT);
@@ -98,7 +101,6 @@ Lcm1602::Lcm1602(int bus_in, int addr_in)
     send(LCD_ENTRYMODESET | LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT, 0);
 
     home();
-
 }
 
 int
@@ -122,53 +124,53 @@ Lcm1602::cursor(int row, int column)
     return send(LCD_SETDDRAMADDR | ((column % 16) + row_addr[row]),0);
 }
 
-int
+maa_result_t
 Lcm1602::write(std::string msg)
 {
-    int ret = 0;
+    maa_result_t ret = MAA_SUCCESS;
     for(std::string::size_type i = 0; i < msg.size(); ++i) {
         ret = send(msg[i], LCD_RS);
     }
-    return 0;
+    return ret;
 }
 
-int
+maa_result_t
 Lcm1602::close()
 {
     return maa_i2c_stop(m_i2c);
 }
 
-int
-Lcm1602::send(char value, int mode)
+maa_result_t
+Lcm1602::send(uint8_t value, int mode)
 {
-    int ret = 0;
-    char h = value & 0xf0;
-    char l = (value << 4) & 0xf0;
+    maa_result_t ret = MAA_SUCCESS;
+    uint8_t h = value & 0xf0;
+    uint8_t l = (value << 4) & 0xf0;
     ret = write4bits(h | mode);
     ret = write4bits(l | mode);
     return ret;
 }
 
-int
-Lcm1602::write4bits(char value)
+maa_result_t
+Lcm1602::write4bits(uint8_t value)
 {
-    int ret = 0;
+    maa_result_t ret = MAA_SUCCESS;
     ret = expandWrite(value);
     ret = pulseEnable(value);
-    return 0;
+    return ret;
 }
 
-int
-Lcm1602::expandWrite(char value)
+maa_result_t
+Lcm1602::expandWrite(uint8_t value)
 {
-    char buffer = value | LCD_BACKLIGHT;
+    uint8_t buffer = value | LCD_BACKLIGHT;
     return maa_i2c_write_byte(m_i2c, buffer);
 }
 
-int
-Lcm1602::pulseEnable(char value)
+maa_result_t
+Lcm1602::pulseEnable(uint8_t value)
 {
-    int ret = 0;
+    maa_result_t ret = MAA_SUCCESS;
     ret = expandWrite(value | LCD_EN);
     usleep(1);
     ret = expandWrite(value & ~LCD_EN);
index 69a128a..525bfc7 100644 (file)
@@ -7,7 +7,7 @@
  * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
  * Copyright (c) 2014 Intel Corporation.
  *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * Permission is hereby granted, free of uint8_tge, to any person obtaining a copy of
  * this software and associated documentation files (the "Software"), to deal in
  * the Software without restriction, including without limitation the rights to
  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
@@ -48,16 +48,16 @@ public:
     // change cursor to row,column.
     int cursor(int row, int column);
     //write a string at the position
-    int write(std::string msg);
-    int close();
+    maa_result_t write(std::string msg);
+    maa_result_t close();
 
 private:
-    int address;
-    int bus;
-    int send(char value, int mode);
-    int write4bits(char value);
-    int expandWrite(char value);
-    int pulseEnable(char value);
+    int m_address;
+    int m_bus;
+    maa_result_t send(uint8_t value, int mode);
+    maa_result_t write4bits(uint8_t value);
+    maa_result_t expandWrite(uint8_t value);
+    maa_result_t pulseEnable(uint8_t value);
     maa_i2c_context m_i2c;
 };