Skip to content

Commit

Permalink
Merge pull request #348 from Master92/go_sleep
Browse files Browse the repository at this point in the history
Add shortcut for entering sleep mode from video
  • Loading branch information
ligenxxxx authored Nov 3, 2023
2 parents 39dd17e + dc84949 commit 60c7459
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 80 deletions.
18 changes: 18 additions & 0 deletions src/core/app_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ void app_switch_to_menu() {
system_script(REC_STOP_LIVE);
}

void app_exit_menu() {
switch (g_source_info.source) {
case SOURCE_HDZERO:
progress_bar.start = 1;
app_switch_to_hdzero(true);
break;
case SOURCE_HDMI_IN:
app_switch_to_hdmi_in();
break;
case SOURCE_AV_IN:
app_switch_to_analog(0);
break;
case SOURCE_EXPANSION:
app_switch_to_analog(1);
break;
}
}

void app_switch_to_analog(bool is_bay) {
Source_AV(is_bay);

Expand Down
3 changes: 3 additions & 0 deletions src/core/app_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ typedef enum {
APP_STATE_WIFI = 13,

APP_STATE_USER_INPUT_DISABLED = 20,

APP_STATE_SLEEP = 30,
} app_state_t;

extern app_state_t g_app_state;

void app_state_push(app_state_t state);

void app_switch_to_menu();
void app_exit_menu();
void app_switch_to_analog(bool is_bay);
void app_switch_to_hdmi_in();
void app_switch_to_hdzero(bool is_default);
3 changes: 2 additions & 1 deletion src/core/ht.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "bmi270/accel_gyro.h"
#include "core/settings.h"
#include "core/sleep_mode.h"
#include "driver/beep.h"
#include "driver/dm6302.h"
#include "driver/hardware.h"
Expand Down Expand Up @@ -146,7 +147,7 @@ static void detect_motion(bool is_moving) {
}

void ht_detect_motion() {
if (has_motion_data) {
if (!isSleeping && has_motion_data) {
detect_motion(is_moving);
has_motion_data = false;
}
Expand Down
39 changes: 20 additions & 19 deletions src/core/input_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "core/dvr.h"
#include "core/elrs.h"
#include "core/settings.h"
#include "core/sleep_mode.h"
#include "driver/dm6302.h"
#include "driver/hardware.h"
#include "driver/i2c.h"
Expand Down Expand Up @@ -170,21 +171,7 @@ static void btn_press(void) // long press left key
g_autoscan_exit = true;
if (g_app_state == APP_STATE_MAINMENU) // Main menu -> Video
{
switch (g_source_info.source) {
case SOURCE_HDZERO:
progress_bar.start = 1;
app_switch_to_hdzero(true);
break;
case SOURCE_HDMI_IN:
app_switch_to_hdmi_in();
break;
case SOURCE_AV_IN:
app_switch_to_analog(0);
break;
case SOURCE_EXPANSION:
app_switch_to_analog(1);
break;
}
app_exit_menu();
app_state_push(APP_STATE_VIDEO);
} else if ((g_app_state == APP_STATE_VIDEO) || (g_app_state == APP_STATE_IMS)) { // video -> Main menu
if (tune_timer && g_source_info.source == SOURCE_HDZERO)
Expand All @@ -194,9 +181,11 @@ static void btn_press(void) // long press left key
} else if (g_app_state == APP_STATE_OSD_ELEMENT_PREV) {
ui_osd_element_pos_cancel_and_hide();
app_switch_to_menu();
} else if (g_app_state == APP_STATE_PLAYBACK)
} else if (g_app_state == APP_STATE_PLAYBACK) {
pb_key(DIAL_KEY_PRESS);
else { // Sub-menu -> Main menu
} else if (g_app_state == APP_STATE_SLEEP) {
wake_up();
} else { // Sub-menu -> Main menu
submenu_exit();
app_state_push(APP_STATE_MAINMENU);
main_menu_show(true);
Expand Down Expand Up @@ -250,6 +239,8 @@ static void btn_click(void) // short press enter key
g_app_state == APP_STATE_SUBMENU_ITEM_FOCUSED ||
g_app_state == APP_STATE_WIFI) {
submenu_click();
} else if (g_app_state == APP_STATE_SLEEP) {
wake_up();
}
pthread_mutex_unlock(&lvgl_mutex);
}
Expand Down Expand Up @@ -279,9 +270,16 @@ void rbtn_click(right_button_t click_type) {
step_topfan();
pthread_mutex_unlock(&lvgl_mutex);
} else if (click_type == RIGHT_DOUBLE_CLICK) {
ht_set_center_position();
if (g_setting.ht.enable == true) {
ht_set_center_position();
} else {
go_sleep();
}
}
break;
case APP_STATE_SLEEP:
wake_up();
break;
}
}

Expand Down Expand Up @@ -315,6 +313,8 @@ static void roller_up(void) {
ims_key(DIAL_KEY_UP);
} else if (g_app_state == APP_STATE_OSD_ELEMENT_PREV) {
ui_osd_element_pos_handle_input(DIAL_KEY_UP);
} else if (g_app_state == APP_STATE_SLEEP) {
wake_up();
}
pthread_mutex_unlock(&lvgl_mutex);
}
Expand Down Expand Up @@ -348,8 +348,9 @@ static void roller_down(void) {
ims_key(DIAL_KEY_DOWN);
} else if (g_app_state == APP_STATE_OSD_ELEMENT_PREV) {
ui_osd_element_pos_handle_input(DIAL_KEY_DOWN);
} else if (g_app_state == APP_STATE_SLEEP) {
wake_up();
}

pthread_mutex_unlock(&lvgl_mutex);
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "core/osd.h"
#include "core/self_test.h"
#include "core/settings.h"
#include "core/sleep_mode.h"
#include "core/thread.h"
#include "driver/TP2825.h"
#include "driver/dm5680.h"
Expand Down Expand Up @@ -195,6 +196,7 @@ int main(int argc, char *argv[]) {
g_init_done = 1;
for (;;) {
pthread_mutex_lock(&lvgl_mutex);
sleep_reminder();
statubar_update();
osd_hdzero_update();
ims_update();
Expand Down
97 changes: 97 additions & 0 deletions src/core/sleep_mode.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#include "sleep_mode.h"

#include "core/app_state.h"
#include "core/common.hh"
#include "core/dvr.h"
#include "core/settings.h"

#include "driver/beep.h"
#include "driver/dm5680.h"
#include "driver/fans.h"
#include "driver/hardware.h"

#include "log/log.h"

#include "ui/page_fans.h"

static app_state_t previousState;
static int fans_auto_mode_save;
static fan_speed_t fan_speed_save;

static uint16_t beepCnt = 0;

bool isSleeping = false;

void go_sleep() {
LOGI("Entering sleep mode");
previousState = g_app_state;
app_state_push(APP_STATE_SLEEP);

// Stop DVR
dvr_cmd(DVR_STOP);
dvr_update_vi_conf(VR_1080P30);

// Turn off OLED
OLED_ON(0);

// Turn off HDZero Receiver
HDZero_Close();

// Turn off Analog Receiver -- Batch 2 goggles only
if (getHwRevision() >= HW_REV_2) {
DM5680_Power_AnalogModule(1);
}

// Minimum fan
fans_auto_mode_save = g_setting.fans.auto_mode;
fan_speed_save.top = fan_speed.top;
fan_speed_save.left = fan_speed.left;
fan_speed_save.right = fan_speed.right;
g_setting.fans.top_speed = MIN_FAN_TOP;
g_setting.fans.left_speed = MIN_FAN_SIDE;
g_setting.fans.right_speed = MIN_FAN_SIDE;
g_setting.fans.auto_mode = 0;
fans_top_setspeed(MIN_FAN_TOP);
fans_left_setspeed(MIN_FAN_SIDE);
fans_right_setspeed(MIN_FAN_SIDE);
isSleeping = true;
beepCnt = 0;
}

void wake_up() {
LOGI("Exiting sleep mode");
isSleeping = false;

OLED_ON(1); // Turn on OLED
Analog_Module_Power(1);

g_setting.fans.top_speed = fan_speed_save.top;
g_setting.fans.left_speed = fan_speed_save.left;
g_setting.fans.right_speed = fan_speed_save.right;
g_setting.fans.auto_mode = fans_auto_mode_save;
fans_top_setspeed(fan_speed_save.top);
fans_left_setspeed(fan_speed_save.left);
fans_right_setspeed(fan_speed_save.right);

app_state_push(previousState);
if (previousState == APP_STATE_SUBMENU) {
submenu_exit();
} else if (previousState == APP_STATE_VIDEO) {
app_switch_to_menu(); // Necessary to display the progress bar
app_state_push(previousState); // Because app_switch_to_menu() pushes main menu state
app_exit_menu();
}
}

void sleep_reminder()
{
if (isSleeping == false) {
return;
}

#define BEEP_INTERVAL 4000
if (++beepCnt == BEEP_INTERVAL) {
beep_dur(BEEP_VERY_SHORT);
beepCnt = 0;
}
}
9 changes: 9 additions & 0 deletions src/core/sleep_mode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <stdbool.h>

extern bool isSleeping;

void go_sleep();
void wake_up();
void sleep_reminder();
1 change: 1 addition & 0 deletions src/driver/beep.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#define BEEP_VERY_SHORT 1
#define BEEP_SHORT 50
#define BEEP_LONG 200

Expand Down
70 changes: 10 additions & 60 deletions src/ui/page_sleep.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#include "page_sleep.h"

#include "core/app_state.h"
#include "core/common.hh"
#include "core/settings.h"
#include "driver/dm5680.h"
#include "driver/fans.h"
#include "driver/hardware.h"
#include "page_fans.h"
#include "sleep_mode.h"
#include <log/log.h>
#include <minIni.h>
#include <stdio.h>

lv_obj_t *page_sleep_create(lv_obj_t *parent, panel_arr_t *arr) {
Expand All @@ -26,7 +21,10 @@ lv_obj_t *page_sleep_create(lv_obj_t *parent, panel_arr_t *arr) {

lv_obj_t *cont = lv_menu_cont_create(section);
lv_obj_t *desc_label = lv_label_create(cont);
lv_label_set_text(desc_label, "Click the Enter Button to go sleep.\nClick any button to exit sleep mode.");
lv_label_set_text(desc_label, "Click the Enter Button to go sleep.\n"
"Click any button to exit sleep mode.\n\n"
"Double-click the right button to go sleep from video mode.\n"
"(Only when Head Tracker is disabled!)");
lv_obj_set_style_text_font(desc_label, &lv_font_montserrat_26, 0);
lv_obj_set_style_text_color(desc_label, lv_color_make(255, 255, 255), 0);
lv_obj_set_style_pad_top(desc_label, 12, 0);
Expand All @@ -41,63 +39,15 @@ static fan_speed_t fan_speed_save;
static void page_sleep_enter() {
LOGI("page_sleep_enter");

// Turn off OLED
OLED_ON(0);

// Turn off HDZero Receiver
HDZero_Close();

// Turn off Analog Receiver -- Batch 2 goggles only
if (getHwRevision() >= HW_REV_2) {
DM5680_Power_AnalogModule(1);
}

// Minimum fan
fans_auto_mode_save = g_setting.fans.auto_mode;
fan_speed_save.top = fan_speed.top;
fan_speed_save.left = fan_speed.left;
fan_speed_save.right = fan_speed.right;
g_setting.fans.top_speed = MIN_FAN_TOP;
g_setting.fans.left_speed = MIN_FAN_SIDE;
g_setting.fans.right_speed = MIN_FAN_SIDE;
g_setting.fans.auto_mode = 0;
fans_top_setspeed(MIN_FAN_TOP);
fans_left_setspeed(MIN_FAN_SIDE);
fans_right_setspeed(MIN_FAN_SIDE);
}

static void page_sleep_exit() {
LOGI("page_sleep_exit");
OLED_ON(1); // Turn on OLED
Analog_Module_Power(1);

g_setting.fans.top_speed = fan_speed_save.top;
g_setting.fans.left_speed = fan_speed_save.left;
g_setting.fans.right_speed = fan_speed_save.right;
g_setting.fans.auto_mode = fans_auto_mode_save;
fans_top_setspeed(fan_speed_save.top);
fans_left_setspeed(fan_speed_save.left);
fans_right_setspeed(fan_speed_save.right);
}

static void page_sleep_click(uint8_t key, int sel) {
submenu_exit();
}

static void page_sleep_roller(uint8_t key) {
submenu_exit();
};

static void page_sleep_right_button(bool is_short) {
submenu_exit();
go_sleep();
}

page_pack_t pp_sleep = {
.create = page_sleep_create,
.enter = page_sleep_enter,
.exit = page_sleep_exit,
.on_roller = page_sleep_roller,
.on_click = page_sleep_click,
.on_right_button = page_sleep_right_button,
.exit = NULL,
.on_roller = NULL,
.on_click = NULL,
.on_right_button = NULL,
.name = "Go Sleep!",
};

0 comments on commit 60c7459

Please sign in to comment.