Skip to content

Commit ac84fd5

Browse files
committed
remove powering-on and powering off
1 parent 1a50faa commit ac84fd5

4 files changed

Lines changed: 49 additions & 63 deletions

File tree

client/lib/devices/borneo/lyfi/view_models/lyfi_view_model.dart

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ class LyfiViewModel extends BaseBorneoDeviceViewModel {
4545

4646
bool get canLockOrUnlock => !isBusy && isOn;
4747
bool get canUnlock =>
48-
!isBusy &&
49-
isOnline &&
50-
isOn &&
51-
isLocked &&
52-
(_ledState == LedState.normal || _ledState == LedState.poweringOn || _ledState == LedState.temporary);
48+
!isBusy && isOnline && isOn && isLocked && (_ledState == LedState.normal || _ledState == LedState.temporary);
5349
bool get canTimedOn => !isBusy && (!isOn || _mode == LedRunningMode.scheduled);
5450

5551
IEditor? currentEditor;
@@ -192,10 +188,10 @@ class LyfiViewModel extends BaseBorneoDeviceViewModel {
192188
!isBusy &&
193189
_isOn &&
194190
(_mode == LedRunningMode.scheduled || _mode == LedRunningMode.sun) &&
195-
(ledState == LedState.temporary || ledState == LedState.normal || ledState == LedState.poweringOn);
191+
(ledState == LedState.temporary || ledState == LedState.normal);
196192

197193
void switchTemporaryState() {
198-
assert(_ledState == LedState.normal || _ledState == LedState.temporary || _ledState == LedState.poweringOn);
194+
assert(_ledState == LedState.normal || _ledState == LedState.temporary);
199195
super.enqueueUIJob(() => _switchTemporaryState());
200196
}
201197

@@ -205,7 +201,7 @@ class LyfiViewModel extends BaseBorneoDeviceViewModel {
205201
_deviceApi.switchState(super.boundDevice!.device, LedState.temporary);
206202
} else {
207203
// Restore running mode
208-
_deviceApi.switchState(super.boundDevice!.device, LedState.poweringOn);
204+
_deviceApi.switchState(super.boundDevice!.device, LedState.normal);
209205
}
210206
await refreshStatus();
211207
}

client/packages/borneo_kernel/lib/drivers/borneo/lyfi/lyfi_driver.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ enum LedState {
8585
normal,
8686
dimming,
8787
temporary,
88-
preview,
89-
poweringOn,
90-
poweringOff;
88+
preview;
9189

9290
bool get isLocked => !(this == preview || this == dimming);
9391
}

fw/lyfi/main/src/led.c

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ static inline void color_to_duties(const led_color_t color, led_duty_t* duties);
5757
static int led_set_channel_duty(uint8_t ch, led_duty_t duty);
5858
static int led_set_duties(const led_duty_t* duties);
5959
static int led_fade_to_color(const led_color_t color, uint32_t milssecs);
60-
static bool led_fade_inprogress();
60+
static bool led_is_fading();
6161
static int led_fade_stop();
62-
static int led_fade_powering_on();
62+
static int led_fade_to_normal();
6363
static void led_fade_drive();
6464

6565
static int led_mode_manual_entry();
@@ -198,7 +198,7 @@ int led_init()
198198
}
199199

200200
if (bo_power_is_on()) {
201-
BO_TRY(led_fade_powering_on());
201+
BO_TRY(led_fade_to_normal());
202202
}
203203

204204
xTaskCreate(&led_proc, "led_task", 2 * 1024, NULL, tskIDLE_PRIORITY + 2, NULL);
@@ -354,7 +354,7 @@ int led_fade_to_color(const led_color_t color, uint32_t duration_ms)
354354
return 0;
355355
}
356356

357-
int led_fade_powering_on()
357+
int led_fade_to_normal()
358358
{
359359
led_color_t end_color;
360360

@@ -396,7 +396,7 @@ int led_fade_stop()
396396

397397
void led_fade_drive()
398398
{
399-
if (!led_fade_inprogress()) {
399+
if (!led_is_fading()) {
400400
return;
401401
}
402402

@@ -418,7 +418,7 @@ void led_fade_drive()
418418
BO_MUST(led_update_color(color));
419419
}
420420

421-
inline static bool led_fade_inprogress() { return _led.fade_start_time_ms > 0LL; }
421+
inline static bool led_is_fading() { return _led.fade_start_time_ms > 0LL; }
422422

423423
int led_set_channel_brightness(uint8_t ch, led_brightness_t brightness)
424424
{
@@ -497,23 +497,26 @@ static void system_events_handler(void* handler_args, esp_event_base_t base, int
497497
switch (event_id) {
498498
case BO_EVENT_SHUTDOWN_FAULT:
499499
case BO_EVENT_FATAL_ERROR: {
500-
if (led_fade_inprogress()) {
500+
if (led_is_fading()) {
501501
BO_MUST(led_fade_stop());
502502
}
503-
BO_MUST(led_switch_state(LED_STATE_POWERING_OFF));
504503
led_blank();
504+
BO_MUST(led_switch_state(LED_STATE_NORMAL));
505505
} break;
506506

507507
case BO_EVENT_SHUTDOWN_SCHEDULED: {
508-
BO_MUST(led_switch_state(LED_STATE_POWERING_OFF));
508+
BO_MUST(led_switch_state(LED_STATE_NORMAL));
509509
} break;
510510

511511
case BO_EVENT_POWER_ON: {
512-
BO_MUST(led_switch_state(LED_STATE_POWERING_ON));
512+
BO_MUST(led_switch_state(LED_STATE_NORMAL));
513513
} break;
514514

515515
case BO_EVENT_GEO_LOCATION_CHANGED: {
516-
led_sun_update_scheduler();
516+
int rc = led_sun_update_scheduler();
517+
if (rc) {
518+
ESP_LOGE(TAG, "Failed to update solar scheduler");
519+
}
517520
} break;
518521

519522
default:
@@ -641,7 +644,7 @@ static int normal_state_entry()
641644

642645
static void normal_state_drive()
643646
{
644-
if (led_fade_inprogress()) {
647+
if (led_is_fading()) {
645648
led_fade_drive();
646649
return;
647650
}
@@ -743,7 +746,7 @@ int temporary_state_entry(uint8_t prev_state)
743746
return -EINVAL;
744747
}
745748

746-
if (prev_state != LED_STATE_NORMAL && prev_state != LED_STATE_POWERING_ON) {
749+
if (prev_state != LED_STATE_NORMAL) {
747750
return -EINVAL;
748751
}
749752

@@ -767,7 +770,7 @@ static int temporary_state_exit()
767770
}
768771

769772
_led.temporary_off_time = 0;
770-
BO_TRY(led_switch_state(LED_STATE_POWERING_ON));
773+
BO_TRY(led_switch_state(LED_STATE_NORMAL));
771774
return 0;
772775
}
773776

@@ -783,7 +786,7 @@ static void temporary_state_drive()
783786
BO_MUST(temporary_state_exit());
784787
}
785788
else {
786-
if (!led_fade_inprogress()) {
789+
if (!led_is_fading()) {
787790
led_update_color(_led.settings.manual_color);
788791
}
789792
else {
@@ -794,6 +797,11 @@ static void temporary_state_drive()
794797

795798
static void led_drive()
796799
{
800+
if (led_is_fading()) {
801+
led_fade_drive();
802+
return;
803+
}
804+
797805
switch (_led.state) {
798806

799807
case LED_STATE_NORMAL: {
@@ -811,24 +819,26 @@ static void led_drive()
811819
preview_state_drive();
812820
} break;
813821

814-
case LED_STATE_POWERING_OFF: {
815-
if (led_fade_inprogress()) {
816-
led_fade_drive();
817-
}
818-
else {
819-
led_blank();
820-
_led.state = LED_STATE_NORMAL;
821-
}
822-
} break;
822+
/*
823+
case LED_STATE_POWERING_OFF: {
824+
if (led_is_fading()) {
825+
led_fade_drive();
826+
}
827+
else {
828+
led_blank();
829+
_led.state = LED_STATE_NORMAL;
830+
}
831+
} break;
823832
824-
case LED_STATE_POWERING_ON: {
825-
if (led_fade_inprogress()) {
826-
led_fade_drive();
827-
}
828-
else {
829-
led_switch_state(LED_STATE_NORMAL);
830-
}
831-
} break;
833+
case LED_STATE_POWERING_ON: {
834+
if (led_is_fading()) {
835+
led_fade_drive();
836+
}
837+
else {
838+
led_switch_state(LED_STATE_NORMAL);
839+
}
840+
} break;
841+
*/
832842

833843
default:
834844
assert(false);
@@ -859,7 +869,7 @@ int led_switch_state(uint8_t state)
859869
return -EINVAL;
860870
}
861871

862-
if (led_fade_inprogress()) {
872+
if (led_is_fading()) {
863873
BO_TRY(led_fade_stop());
864874
}
865875

@@ -875,10 +885,6 @@ int led_switch_state(uint8_t state)
875885
preview_state_exit();
876886
} break;
877887

878-
case LED_STATE_POWERING_ON:
879-
case LED_STATE_POWERING_OFF: {
880-
} break;
881-
882888
default:
883889
return -1;
884890
}
@@ -894,8 +900,7 @@ int led_switch_state(uint8_t state)
894900
return -EINVAL;
895901
}
896902
// TODO Start the timer
897-
if (_led.state == LED_STATE_NORMAL || _led.state == LED_STATE_PREVIEW || _led.state == LED_STATE_POWERING_ON
898-
|| _led.state == LED_STATE_TEMPORARY) {
903+
if (_led.state == LED_STATE_NORMAL || _led.state == LED_STATE_PREVIEW || _led.state == LED_STATE_TEMPORARY) {
899904
_led.state = state;
900905
}
901906
else {
@@ -917,16 +922,6 @@ int led_switch_state(uint8_t state)
917922
BO_TRY(preview_state_entry());
918923
} break;
919924

920-
case LED_STATE_POWERING_ON: {
921-
_led.state = state;
922-
BO_TRY(led_fade_powering_on());
923-
} break;
924-
925-
case LED_STATE_POWERING_OFF: {
926-
_led.state = state;
927-
BO_TRY(led_fade_to_color(LED_COLOR_BLANK, FADE_OFF_PERIOD_MS));
928-
} break;
929-
930925
default:
931926
return -1;
932927
}

fw/lyfi/main/src/led.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ enum led_status_enum {
4141
LED_STATE_TEMPORARY = 2,
4242
LED_STATE_PREVIEW = 3,
4343

44-
LED_STATE_POWERING_ON = 4,
45-
LED_STATE_POWERING_OFF = 5,
46-
4744
LED_STATE_COUNT,
4845
};
4946

0 commit comments

Comments
 (0)