From 8cfb3d3dabfb7d77b89bbfba0650482b6e7ef201 Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Mon, 14 Jul 2014 13:59:19 +0100 Subject: [PATCH] my9221: add direction for setBarLevel Signed-off-by: Brendan Le Foll --- src/my9221/my9221.cxx | 18 +++++++++++++----- src/my9221/my9221.h | 3 ++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/my9221/my9221.cxx b/src/my9221/my9221.cxx index c543544a..63004c7b 100644 --- a/src/my9221/my9221.cxx +++ b/src/my9221/my9221.cxx @@ -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 diff --git a/src/my9221/my9221.h b/src/my9221/my9221.h index 9451bbe1..ad713a5b 100644 --- a/src/my9221/my9221.h +++ b/src/my9221/my9221.h @@ -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