Skip to content

Commit ae601e7

Browse files
mkuettner97cadivus
authored andcommitted
adjust led service
1 parent 799942d commit ae601e7

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

include/openearable_common.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ extern const struct device *const ls_1_8;
2424
extern const struct device *const ls_3_3;
2525
extern const struct device *const ls_sd;
2626

27+
typedef uint8_t RGBColor[3];
28+
2729
struct boot_state {
2830
bool timer_reset;
2931
uint64_t device_id;
@@ -43,15 +45,15 @@ enum charging_state {
4345
FAULT,
4446
};
4547

46-
enum led_state {
48+
enum led_mode {
4749
STATE_INDICATION,
4850
CUSTOM,
4951
};
5052

5153
struct earable_state {
5254
enum pairing_state pairing_state;
5355
enum charging_state charging_state;
54-
enum led_state led_state;
56+
enum led_mode led_mode;
5557
};
5658

5759
enum sensor_id {

src/bluetooth/gatt_services/led_service.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ static ssize_t write_led(struct bt_conn *conn,
2424
}
2525

2626
//earable_led.set_color((uint8_t*)buf);
27-
led_controller.setColor((uint8_t*)buf);
27+
//led_controller.setColor((uint8_t*)buf);
28+
29+
state_indicator.set_custom_color((uint8_t *) buf);
2830

2931
return len;
3032
}
@@ -47,7 +49,7 @@ static ssize_t write_state(struct bt_conn *conn,
4749
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
4850
}
4951

50-
state_indicator.set_led_state((led_state) *((uint8_t*)buf));
52+
state_indicator.set_indication_mode((led_mode) *((uint8_t*)buf));
5153

5254
return len;
5355
}

src/drivers/LED_Controller/KTD2026.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <math.h>
66
#include <Wire.h>
77

8-
typedef uint8_t RGBColor[3];
8+
#include "openearable_common.h"
99

1010
class KTD2026 {
1111
public:

src/utils/StateIndicator.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,13 @@ void StateIndicator::init(struct earable_state state) {
9090
set_state(state);
9191
}
9292

93-
void StateIndicator::set_led_state(enum led_state state) {
94-
_state.led_state = state;
93+
void StateIndicator::set_custom_color(RGBColor color) {
94+
memcpy(&this->color, color, sizeof(RGBColor));
95+
if (_state.led_mode == CUSTOM) led_controller.setColor(color);
96+
}
97+
98+
void StateIndicator::set_indication_mode(enum led_mode state) {
99+
_state.led_mode = state;
95100
set_state(_state);
96101
}
97102

@@ -109,7 +114,10 @@ void StateIndicator::set_state(struct earable_state state) {
109114
_state = state;
110115

111116
// do not update the state if set to custom color
112-
if (_state.led_state == CUSTOM) return;
117+
if (_state.led_mode == CUSTOM) {
118+
led_controller.setColor(color);
119+
return;
120+
}
113121

114122
RGBColor color = {0,0,0};
115123
switch (_state.charging_state) {

src/utils/StateIndicator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ class StateIndicator {
1111

1212
void set_charging_state(enum charging_state state);
1313
void set_pairing_state(enum pairing_state state);
14-
void set_led_state(enum led_state state);
14+
void set_indication_mode(enum led_mode state);
15+
void set_custom_color(RGBColor color);
1516

1617
private:
1718
earable_state _state;
19+
RGBColor color;
1820
};
1921

2022
extern StateIndicator state_indicator;

0 commit comments

Comments
 (0)