----------------------------------------------------------------------------- Set the device's Color value -----------------------------------------------------------------------------
| 616 | // Set the device's Color value |
| 617 | //----------------------------------------------------------------------------- |
| 618 | bool Color::SetValue |
| 619 | ( |
| 620 | Value const& _value |
| 621 | ) |
| 622 | { |
| 623 | if (Value_Color == _value.GetID().GetIndex()) |
| 624 | { |
| 625 | ValueString const* value = static_cast<ValueString const*>(&_value); |
| 626 | string s = value->GetValue(); |
| 627 | /* make sure the first char is # */ |
| 628 | if (s.at(0) != '#') { |
| 629 | Log::Write( LogLevel_Warning, GetNodeId(), "Color::SetValue - String is Malformed. Missing #: %s", s.c_str()); |
| 630 | return false; |
| 631 | } |
| 632 | /* length minus the # has to be multiple of 2's */ |
| 633 | if ((s.length()-1) % 2 != 0 ) { |
| 634 | Log::Write( LogLevel_Warning, GetNodeId(), "Color::SetValue - Uneven Length string. Each Color should be 2 chars: %s", s.c_str()); |
| 635 | return false; |
| 636 | } |
| 637 | |
| 638 | /* the size of the string tells us how many colors are set */ |
| 639 | uint8_t nocols = (uint8_t)((s.length() -1) / 2) & 0xFF; |
| 640 | uint8_t colvals[8] = { 0, 0, 0, 0, 0, 0, 0, 0}; |
| 641 | bool colvalset[8] = { false, false, false, false, false, false, false, false }; |
| 642 | |
| 643 | |
| 644 | try { |
| 645 | /* we always will have at least RGB */ |
| 646 | colvals[COLORIDX_RED] = GetColor(s, 1); |
| 647 | colvals[COLORIDX_GREEN] = GetColor(s, 2); |
| 648 | colvals[COLORIDX_BLUE] = GetColor(s, 3); |
| 649 | |
| 650 | /* if nocols = 4 then allwhite is set */ |
| 651 | if (nocols == 4) { |
| 652 | /* use ww as the var for all white */ |
| 653 | colvals[COLORIDX_WARMWHITE] = GetColor(s, 4); |
| 654 | colvalset[COLORIDX_WARMWHITE] = true; |
| 655 | } |
| 656 | if (nocols >= 5) { |
| 657 | /* warm white and cold white are set */ |
| 658 | colvals[COLORIDX_WARMWHITE] = GetColor(s, 4); |
| 659 | colvals[COLORIDX_COLDWHITE] = GetColor(s, 5); |
| 660 | colvalset[COLORIDX_WARMWHITE] = true; |
| 661 | colvalset[COLORIDX_COLDWHITE] = true; |
| 662 | } |
| 663 | if (nocols >= 6) { |
| 664 | /* amber is also set */ |
| 665 | colvals[COLORIDX_AMBER] = GetColor(s, 6); |
| 666 | colvalset[COLORIDX_AMBER] = true; |
| 667 | } |
| 668 | if (nocols >= 7) { |
| 669 | /* cyan is also set */ |
| 670 | colvals[COLORIDX_CYAN] = GetColor(s, 7); |
| 671 | colvalset[COLORIDX_CYAN] = true; |
| 672 | } |
| 673 | if (nocols == 8) { |
| 674 | /* purple is also set */ |
| 675 | colvals[COLORIDX_PURPLE] = GetColor(s, 8); |
nothing calls this directly
no test coverage detected