-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathEmotiBitLedController.h
More file actions
148 lines (128 loc) · 4.62 KB
/
EmotiBitLedController.h
File metadata and controls
148 lines (128 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**************************************************************************/
/*!
@file EmotiBitLedController.h
This class handles LEDs on EmotiBit.
EmotiBit invests time and resources providing this open source code,
please support EmotiBit and open-source hardware by purchasing
products from EmotiBit!
Written by Nitin Nair for EmotiBit.
BSD license, all text here must be included in any redistribution
*/
/**************************************************************************/
#ifndef EMOTIBIT_LED_CONTROLLER
#define EMOTIBIT_LED_CONTROLLER
#include <Arduino.h>
#include "EmotiBitVersionController.h"
#include "EmotiBit_NCP5623.h"
#include "KTD2026.h"
class EmotiBitLedController
{
public:
/*!
* @brief enumerator for LEDs on EmotiBit
*/
enum Led
{
RED = 0,
BLUE,
YELLOW,
length
};
/*!
* @brief struct to hold current state of LEDs on EmotiBit
*/
struct LedStatus
{
bool state = false;
bool isChanged = false;
} _ledStatus[Led::length];
/*!
* @brief Map LedController to NCP led numbers.
The NCP led number are taken from the driver implementation.
*/
const uint8_t ledToNcpMap[Led::length] =
{
1, // Red
2, // Blue
3 // Yellow
};
struct SettingsNCP5623{
uint8_t driverCurrent = 1;
uint8_t pwmVal = 8;
} settingsNCP5623;
/*!
@brief Map EmotiBit LEDs to KTD2026 channels. Refer hardware schematic for mapping.
*/
const KTD2026::Channel ledToKtdMap[Led::length] =
{
KTD2026::Channel::CH1, // RED
KTD2026::Channel::CH2, // BLUE
KTD2026::Channel::CH3 // YELLOW
};
struct SettingsKTD2026{
// ToDo: consider if we want 3 iOut settings, 1 for each channel.
//Since each channel has a different LED color, different currents may be required to produce same luminosity.
uint8_t iOut = 0x10; // setting current to 2mA. value = 2mA/24mA * 192 steps = 16 steps = 0x10
}settingsKTD2026;
NCP5623 ncp5623; //<! instance of NCP5623
KTD2026* ktd2026b = new KTD2026(); //<! instance of KTD2026
public:
/*!
* @brief Setup the LedController
* @param emotibitI2c i2c instance on EmotiBit
* @param hwVersion EmotiBit Hardware Version
* @return true if setup successful, else false
*/
bool begin(TwoWire* emotibitI2c, EmotiBitVersionController::EmotiBitVersion hwVersion);
/*!
* @brief set the state of the LED
* @param led the led to set
* @param state State LED is set to
* @param updateNow Specify if the physical state should be updated immediately. Warning: EmotiBit LED driver should only be communicated with in the ISR if running stock EmotiBit FW.
* @return true if success, else false
*/
bool setState(Led led, bool state, bool updateNow = false);
/*!
* @brief Function to get the State of the LED
* @param led Get state of this led
* @return state of the LED can be true (ON) or false (OFF)
*/
bool getState(Led led);
/*!
* @brief Function to update the LEDs with the internal LED state. Call with caution as it may involve communicating with the driver.
EmotiBit stock FW only allows I2C communication ONLY DURING ISR. Communicating outside ISR may cause collision on the I2C line.
* @return true if successful, else false
*/
bool update();
/*!
@brief Set HW version in the LedController class
@param version EmotiBit HW version
@return True is set successfully, else false
*/
bool setHwVersion(EmotiBitVersionController::EmotiBitVersion version)
{
_hwVersion = version;
return true;
}
/*!
@brief Get the HW version set in the LedController class
@return HW version
*/
EmotiBitVersionController::EmotiBitVersion getHeWVersion()
{
return _hwVersion;
}
private:
/*!
* @brief Function to communicate with the NCP5623 driver
* @return true if successful, else false
*/
bool _updateNcp();
/*!
@brief Function to communicate with the KTD2026 driver
@return True if successful, else false
*/
bool _updateKtd2026();
EmotiBitVersionController::EmotiBitVersion _hwVersion;
};
#endif