my9221: add direction for setBarLevel

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll 2014-07-14 13:59:19 +01:00
parent d2e2682f0e
commit 8cfb3d3dab
2 changed files with 15 additions and 6 deletions

View 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

View 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