1111
1212 */
1313
14- #include < Arduino.h>
15- #include < Wire.h>
14+ /* *************************************************************************************
15+ * INCLUDE
16+ **************************************************************************************/
17+
1618#include " Backlight.h"
1719
20+ /* *************************************************************************************
21+ * CTOR/DTOR
22+ **************************************************************************************/
23+
24+ Backlight::Backlight (rtos::Mutex & wire_mtx)
25+ : _wire_mtx{wire_mtx}
26+ {
27+
28+ }
29+
30+ /* *************************************************************************************
31+ * PUBLIC MEMBER FUNCTIONS
32+ **************************************************************************************/
33+
1834void Backlight::begin ()
1935{
2036 reset ();
@@ -27,62 +43,14 @@ void Backlight::end()
2743 powerDown ();
2844}
2945
30- void Backlight::setColor (RGBColors color )
46+ void Backlight::turnOn ( )
3147{
32- if (color == off) {
33- _blue = 0x00 ;
34- _green = 0x00 ;
35- _red = 0x00 ;
36- }
37-
38- if (color == green) {
39- _blue = 0x00 ;
40- _green = 0xFF ;
41- _red = 0x00 ;
42- }
43-
44- if (color == blue) {
45- _blue = 0xFF ;
46- _green = 0x00 ;
47- _red = 0x00 ;
48- }
49-
50- if (color == red) {
51- _blue = 0x00 ;
52- _green = 0x00 ;
53- _red = 0xFF ;
54- }
55-
56- if (color == cyan) {
57- _blue = 0x20 ;
58- _green = 0x20 ;
59- _red = 0x00 ;
60- }
61-
62- if (color == magenta) {
63- _blue = 0x20 ;
64- _green = 0x00 ;
65- _red = 0x20 ;
66- }
67-
68- if (color == yellow) {
69- _blue = 0x00 ;
70- _green = 0x20 ;
71- _red = 0x20 ;
72- }
73-
74- setColor (_blue, _green, _red);
75-
48+ setColor (0xFF , 0xFF , 0xFF );
7649}
7750
78- void Backlight::setColor ( uint8_t blue, uint8_t green, uint8_t red )
51+ void Backlight::turnOff ( )
7952{
80- // set rgb led current
81- writeByte (IS31FL3194_ADDRESS, IS31FL3194_OUT1, blue); // maximum current
82- writeByte (IS31FL3194_ADDRESS, IS31FL3194_OUT2, green);
83- writeByte (IS31FL3194_ADDRESS, IS31FL3194_OUT3, red);
84- writeByte (IS31FL3194_ADDRESS, IS31FL3194_COLOR_UPDATE, 0xC5 ); // write to color update register for changes to take effect
85-
53+ setColor (0 , 0 , 0 );
8654}
8755
8856// Read the Chip ID register, this is a good test of communication
@@ -92,6 +60,9 @@ uint8_t Backlight::getChipID()
9260 return c;
9361}
9462
63+ /* *************************************************************************************
64+ * PRIVATE MEMBER FUNCTIONS
65+ **************************************************************************************/
9566
9667void Backlight::reset ()
9768{
@@ -122,15 +93,19 @@ void Backlight::init()// configure rgb led function
12293 writeByte (IS31FL3194_ADDRESS, 0x32 , 0xFF ); // Max power on led R (OUT 3)
12394}
12495
125- void Backlight::ledBlink (RGBColors color, uint32_t duration )
96+ void Backlight::setColor ( uint8_t blue, uint8_t green, uint8_t red )
12697{
127- setColor (color);
128- delay (duration);
129- setColor (off);
98+ // set rgb led current
99+ writeByte (IS31FL3194_ADDRESS, IS31FL3194_OUT1, blue); // maximum current
100+ writeByte (IS31FL3194_ADDRESS, IS31FL3194_OUT2, green);
101+ writeByte (IS31FL3194_ADDRESS, IS31FL3194_OUT3, red);
102+ writeByte (IS31FL3194_ADDRESS, IS31FL3194_COLOR_UPDATE, 0xC5 ); // write to color update register for changes to take effect
130103}
131104
132105void Backlight::writeByte (uint8_t address, uint8_t subAddress, uint8_t data)
133106{
107+ mbed::ScopedLock<rtos::Mutex> lock (_wire_mtx);
108+
134109 Wire.beginTransmission (address);
135110 Wire.write (subAddress);
136111 Wire.write (data);
@@ -139,6 +114,8 @@ void Backlight::writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
139114
140115uint8_t Backlight::readByte (uint8_t address, uint8_t subAddress)
141116{
117+ mbed::ScopedLock<rtos::Mutex> lock (_wire_mtx);
118+
142119 char response = 0xFF ;
143120 Wire.beginTransmission (address);
144121 Wire.write (subAddress);
0 commit comments