my9221: add direction for setBarLevel
authorBrendan Le Foll <brendan.le.foll@intel.com>
Mon, 14 Jul 2014 12:59:19 +0000 (13:59 +0100)
committerBrendan Le Foll <brendan.le.foll@intel.com>
Mon, 14 Jul 2014 12:59:19 +0000 (13:59 +0100)
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
src/my9221/my9221.cxx
src/my9221/my9221.h

index c543544..63004c7 100644 (file)
@@ -73,17 +73,25 @@ MY9221::~MY9221() {
 }
 
 mraa_result_t
-MY9221::setBarLevel (uint8_t level) {
+MY9221::setBarLevel (uint8_t level, bool direction) {
     if (level > 10) {
         return MRAA_ERROR_INVALID_PARAMETER;
     }
 
     send16bitBlock (CMDMODE);
-    for(uint8_t block_idx = 0; block_idx < 12; block_idx++) {
-        uint32_t state = (block_idx < level) ? BIT_HIGH : BIT_LOW;
-        send16bitBlock (state);
+    if (direction) {
+        level += 3;
+        for(uint8_t block_idx = 12; block_idx > 0; block_idx--) {
+            uint32_t state = (block_idx < level) ? BIT_HIGH : BIT_LOW;
+            send16bitBlock (state);
+        }
+    } else {
+        for(uint8_t block_idx = 0; block_idx < 12; block_idx++) {
+            uint32_t state = (block_idx < level) ? BIT_HIGH : BIT_LOW;
+            send16bitBlock (state);
+        }
     }
-    lockData ();
+    return lockData ();
 }
 
 mraa_result_t
index 9451bbe..ad713a5 100644 (file)
@@ -63,8 +63,9 @@ class MY9221 {
          * Set the level bar
          *
          * @param level selected level for the bar (1 - 10)
+         * @param direction up or down, true is up and is the default
          */
-        mraa_result_t setBarLevel (uint8_t level);
+        mraa_result_t setBarLevel (uint8_t level, bool direction=true);
 
         /**
          * Return name of the component