TeensyNanoExoCode
Loading...
Searching...
No Matches
StatusLed.h
Go to the documentation of this file.
1
19#ifndef StatusLed_h
20#define StatusLed_h
21
22#include "Arduino.h"
23#include "Board.h"
24#include "StatusDefs.h"
25
26#if defined(ARDUINO_TEENSY36) || defined(ARDUINO_TEENSY41)
27#include <map>
28
32namespace status_led_defs
33{
34 typedef std::map<uint16_t, uint16_t> IdxRemap;
37 const IdxRemap status_led_idx =
38 {
47
84
101 };
102}
103#endif
104// Define the on and off state of the LED. This is handy for if you are using a P Channel MOSFET where low is on.
105//#define STATUS_LED_ON_STATE 0
106//#define STATUS_LED_OFF_STATE 255
107
108// color assumes 255 is on. The code will use the on/off state above to compensate for the code.
109//#define STATUS_MESSAGE_LED_OFF 0 // set the message index
110//#define STATUS_COLOR_LED_OFF {0, 0, 0} // set the color in {R, G, B} format 0-255
111
112//#define STATUS_MESSAGE_TRIAL_OFF 1 // set the message index
113//#define STATUS_COLOR_TRIAL_OFF {0, 0, 255} // set the color in {R, G, B} format 0-255
114
115//#define STATUS_MESSAGE_TRIAL_ON 2 // set the message index
116//#define STATUS_COLOR_TRIAL_ON {0, 255, 0} // set the color in {R, G, B} format 0-255
117
118//#define STATUS_MESSAGE_ERROR 3 // set the message index
119//#define STATUS_COLOR_ERROR {255, 0, 0} // set the color in {R, G, B} format 0-255
120
121//#define NO_PWM true // true if using simple digital pins, false if using pwm pins
122
127{
131 namespace colors // just used namespace due to the complex structure.
132 {
133 const int off[] = {0, 0, 0};
134 const int trial_off[] = {0, 0, 255};
135 const int trial_on[] = {0, 255, 0};
136 const int test[] = {0, 255, 0};
137 const int torque_calibration[] = {255, 255, 0};
138 const int fsr_calibration[] = {255, 0, 255};
139 const int fsr_refinement[] = {255, 0, 255};
140 const int motor_start_up[] = {255, 68, 0};
141 const int error[] = {255, 0, 0};
142 const int warning[] = {255, 68, 0};
143
144 }
145
149 namespace patterns // just used namespace due to the complex structure.
150 {
151 const uint8_t solid = 0;
152 const uint8_t blink = 1;
153 const uint8_t pulse = 2;
154 const uint8_t rainbow = 3;
155
156
157 //Format is pattern number and period in ms
158 const int off[] = {solid, 0}; // Solid
159 const int trial_off[] = {solid,0}; // Solid
160 const int trial_on[] = {pulse, 500}; // Solid
161 const int test[] = {rainbow, 4000}; // pulse
162 const int torque_calibration[] = {solid, 0};
163 const int fsr_calibration[] = {solid, 0};
164 const int fsr_refinement[] = {pulse, 250};
165 const int motor_start_up[] = {pulse, 4000};
166 const int error[] = {blink, 250}; // blinking
167 const int warning[] = {blink, 250}; // blinking
168 }
169
175}
176
177// Arduino compiles everything in the src folder even if not included so it causes and error for the nano if this is not included.
178#if defined(ARDUINO_TEENSY36) || defined(ARDUINO_TEENSY41)
182class StatusLed
183{
184 public:
185 // Constructors one you can set the default LED State
186 StatusLed(int r_pin, int g_pin, int b_pin); // pins are the pins assocated with the different LED inputs
187 StatusLed(int r_pin, int g_pin, int b_pin, int brightness); // pins are the pins assocated with the different LED inputs, brightness is used to scale the colors that are sent: color * brightness/255
188
194 void update(uint16_t message); // Changes the LED State to the current state
195
201 void set_brightness(int brightness); // Used if you need to change the brightness after initialization, brightness is used to scale the colors that are sent: color * brightness/255
202
206 void toggle();
207 private:
208
216 void _set_color(int R, int G, int B); // changes the color R, G, and B are 0-255 values to set the corresponding colors.
217
221 void _solid();
222
226 void _pulse();
227
231 void _blink();
232
236 void _rainbow_sin();
237
241 void _rainbow_hsv();
242
243 int _r_pin;
244 int _g_pin;
245 int _b_pin;
246 int _brightness;
247 int _current_message;
248 uint16_t _msg_idx;
250 int _pattern_start_timestamp;
251 int _period_ms;
252 int _pattern_brightness_percent;
254 // make sure to keep in index order from messages, this is an array of the colors to use _messageColors[_currentMessage][color] where color is 0 for r, 1 for g, and 2 for b.
255 // This method of accessing array elements is bulky but works.
256 const int _message_colors[10][3] = {{status_led_defs::colors::off[0], status_led_defs::colors::off[1], status_led_defs::colors::off[2]},
266 };
268 // make sure to keep in index order from messages, this is an array of the colors to use _messageColors[_currentMessage][color] where color is 0 for r, 1 for g, and 2 for b.
269 // This method of accessing array elements is bulky but works.
270 const int _message_pattern[10][2] = {{status_led_defs::patterns::off[0], status_led_defs::patterns::off[1]},
280 };
283};
284#endif
285#endif
Stores the different status messages for the system.
const uint8_t status_led_on_state
Definition Board.h:130
const bool status_has_pwm
Definition Board.h:128
const uint8_t status_led_off_state
Definition Board.h:131
const uint16_t trial_on
Definition StatusDefs.h:31
const uint16_t error_to_be_used_6
Definition StatusDefs.h:72
const uint16_t warning_to_be_used_9
Definition StatusDefs.h:93
const uint16_t warning_to_be_used_2
Definition StatusDefs.h:86
const uint16_t fsr_calibration
Definition StatusDefs.h:34
const uint16_t error_to_be_used_7
Definition StatusDefs.h:73
const uint16_t off
Definition StatusDefs.h:29
const uint16_t error_left_toe
Definition StatusDefs.h:42
const uint16_t error_right_knee_motor
Definition StatusDefs.h:57
const uint16_t warning_to_be_used_10
Definition StatusDefs.h:94
const uint16_t torque_calibration
Definition StatusDefs.h:33
const uint16_t error_to_be_used_1
Definition StatusDefs.h:67
const uint16_t warning_to_be_used_14
Definition StatusDefs.h:98
const uint16_t error_left_ankle_motor
Definition StatusDefs.h:55
const uint16_t test
Definition StatusDefs.h:32
const uint16_t error_left_hip_torque_sensor
Definition StatusDefs.h:46
const uint16_t error_right_ankle_controller
Definition StatusDefs.h:65
const uint16_t error_to_be_used_13
Definition StatusDefs.h:79
const uint16_t error_left_ankle_controller
Definition StatusDefs.h:62
const uint16_t warning_to_be_used_6
Definition StatusDefs.h:90
const uint16_t error_left_ankle_torque_sensor
Definition StatusDefs.h:48
const uint16_t error_right_ankle_motor
Definition StatusDefs.h:58
const uint16_t error
Definition StatusDefs.h:39
const uint16_t warning_to_be_used_12
Definition StatusDefs.h:96
const uint16_t error_left_heel_fsr
Definition StatusDefs.h:41
const uint16_t error_left_knee_torque_sensor
Definition StatusDefs.h:47
const uint16_t error_right_ankle_torque_sensor
Definition StatusDefs.h:51
const uint16_t error_to_be_used_9
Definition StatusDefs.h:75
const uint16_t warning_to_be_used_1
Definition StatusDefs.h:85
const uint16_t motor_start_up
Definition StatusDefs.h:36
const uint16_t error_to_be_used_8
Definition StatusDefs.h:74
const uint16_t error_right_hip_torque_sensor
Definition StatusDefs.h:49
const uint16_t warning
Definition StatusDefs.h:82
const uint16_t warning_exo_run_time
Definition StatusDefs.h:83
const uint16_t error_to_be_used_3
Definition StatusDefs.h:69
const uint16_t fsr_refinement
Definition StatusDefs.h:35
const uint16_t error_to_be_used_11
Definition StatusDefs.h:77
const uint16_t error_to_be_used_12
Definition StatusDefs.h:78
const uint16_t error_right_toe_fsr
Definition StatusDefs.h:44
const uint16_t error_left_hip_controller
Definition StatusDefs.h:60
const uint16_t warning_to_be_used_11
Definition StatusDefs.h:95
const uint16_t warning_to_be_used_5
Definition StatusDefs.h:89
const uint16_t error_left_knee_controller
Definition StatusDefs.h:61
const uint16_t warning_to_be_used_7
Definition StatusDefs.h:91
const uint16_t error_to_be_used_2
Definition StatusDefs.h:68
const uint16_t error_left_knee_motor
Definition StatusDefs.h:54
const uint16_t error_to_be_used_4
Definition StatusDefs.h:70
const uint16_t error_right_heel_fsr
Definition StatusDefs.h:43
const uint16_t trial_off
Definition StatusDefs.h:30
const uint16_t error_left_hip_motor
Definition StatusDefs.h:53
const uint16_t error_to_be_used_5
Definition StatusDefs.h:71
const uint16_t warning_to_be_used_8
Definition StatusDefs.h:92
const uint16_t warning_to_be_used_13
Definition StatusDefs.h:97
const uint16_t error_to_be_used_10
Definition StatusDefs.h:76
const uint16_t error_right_knee_controller
Definition StatusDefs.h:64
const uint16_t error_right_knee_torque_sensor
Definition StatusDefs.h:50
const uint16_t error_right_hip_controller
Definition StatusDefs.h:63
const uint16_t error_right_hip_motor
Definition StatusDefs.h:56
const uint16_t warning_to_be_used_3
Definition StatusDefs.h:87
const uint16_t warning_to_be_used_4
Definition StatusDefs.h:88
const int torque_calibration[]
Definition StatusLed.h:137
const int fsr_refinement[]
Definition StatusLed.h:139
const int error[]
Definition StatusLed.h:141
const int test[]
Definition StatusLed.h:136
const int off[]
Definition StatusLed.h:133
const int warning[]
Definition StatusLed.h:142
const int trial_off[]
Definition StatusLed.h:134
const int fsr_calibration[]
Definition StatusLed.h:138
const int trial_on[]
Definition StatusLed.h:135
const int motor_start_up[]
Definition StatusLed.h:140
const uint8_t pulse
Definition StatusLed.h:153
const int trial_off[]
Definition StatusLed.h:159
const uint8_t rainbow
Definition StatusLed.h:154
const int fsr_refinement[]
Definition StatusLed.h:164
const int warning[]
Definition StatusLed.h:167
const int off[]
Definition StatusLed.h:158
const int test[]
Definition StatusLed.h:161
const int motor_start_up[]
Definition StatusLed.h:165
const int trial_on[]
Definition StatusLed.h:160
const int torque_calibration[]
Definition StatusLed.h:162
const int fsr_calibration[]
Definition StatusLed.h:163
const int error[]
Definition StatusLed.h:166
const uint8_t solid
Definition StatusLed.h:151
const uint8_t blink
Definition StatusLed.h:152
define how each message will be displayed.
Definition StatusLed.h:127
const bool has_pwm
Definition StatusLed.h:173
const uint8_t off_state
Definition StatusLed.h:171
const uint8_t on_state
Definition StatusLed.h:170
Definition Config.h:53