11
11
12
12
*/
13
13
14
- #include < Arduino.h>
15
- #include < Wire.h>
14
+ /* *************************************************************************************
15
+ * INCLUDE
16
+ **************************************************************************************/
17
+
16
18
#include " Backlight.h"
17
19
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
+
18
34
void Backlight::begin ()
19
35
{
20
36
reset ();
@@ -27,62 +43,14 @@ void Backlight::end()
27
43
powerDown ();
28
44
}
29
45
30
- void Backlight::setColor (RGBColors color )
46
+ void Backlight::turnOn ( )
31
47
{
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 );
76
49
}
77
50
78
- void Backlight::setColor ( uint8_t blue, uint8_t green, uint8_t red )
51
+ void Backlight::turnOff ( )
79
52
{
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 );
86
54
}
87
55
88
56
// Read the Chip ID register, this is a good test of communication
@@ -92,6 +60,9 @@ uint8_t Backlight::getChipID()
92
60
return c;
93
61
}
94
62
63
+ /* *************************************************************************************
64
+ * PRIVATE MEMBER FUNCTIONS
65
+ **************************************************************************************/
95
66
96
67
void Backlight::reset ()
97
68
{
@@ -122,15 +93,19 @@ void Backlight::init()// configure rgb led function
122
93
writeByte (IS31FL3194_ADDRESS, 0x32 , 0xFF ); // Max power on led R (OUT 3)
123
94
}
124
95
125
- void Backlight::ledBlink (RGBColors color, uint32_t duration )
96
+ void Backlight::setColor ( uint8_t blue, uint8_t green, uint8_t red )
126
97
{
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
130
103
}
131
104
132
105
void Backlight::writeByte (uint8_t address, uint8_t subAddress, uint8_t data)
133
106
{
107
+ mbed::ScopedLock<rtos::Mutex> lock (_wire_mtx);
108
+
134
109
Wire.beginTransmission (address);
135
110
Wire.write (subAddress);
136
111
Wire.write (data);
@@ -139,6 +114,8 @@ void Backlight::writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
139
114
140
115
uint8_t Backlight::readByte (uint8_t address, uint8_t subAddress)
141
116
{
117
+ mbed::ScopedLock<rtos::Mutex> lock (_wire_mtx);
118
+
142
119
char response = 0xFF ;
143
120
Wire.beginTransmission (address);
144
121
Wire.write (subAddress);
0 commit comments