Skip to content

Commit

Permalink
Fixed power save and added display contrast menu
Browse files Browse the repository at this point in the history
  • Loading branch information
OneOfEleven committed Oct 10, 2023
1 parent a552b04 commit 6660d00
Show file tree
Hide file tree
Showing 19 changed files with 213 additions and 126 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ENABLE_OVERLAY := 0
ENABLE_LTO := 1
ENABLE_UART := 1
ENABLE_UART_DEBUG := 1
ENABLE_AIRCOPY := 1
ENABLE_AIRCOPY := 0
ENABLE_FMRADIO := 1
ENABLE_NOAA := 1
ENABLE_VOICE := 0
Expand Down
6 changes: 3 additions & 3 deletions app/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void ACTION_Monitor(void)
if (g_current_function != FUNCTION_MONITOR)
{ // enable the monitor
RADIO_SelectVfos();
#ifdef ENABLE_NOAA
#ifdef g_power_save_expired
if (g_rx_vfo->channel_save >= NOAA_CHANNEL_FIRST && g_is_noaa_mode)
g_noaa_channel = g_rx_vfo->channel_save - NOAA_CHANNEL_FIRST;
#endif
Expand All @@ -95,7 +95,7 @@ void ACTION_Monitor(void)
g_scan_pause_mode = true;
}

#ifdef ENABLE_NOAA
#ifdef g_power_save_expired
if (g_eeprom.dual_watch == DUAL_WATCH_OFF && g_is_noaa_mode)
{
g_noaa_count_down_10ms = noaa_count_down_10ms;
Expand Down Expand Up @@ -180,7 +180,7 @@ void ACTION_Scan(bool bRestart)

RADIO_SelectVfos();

#ifdef ENABLE_NOAA
#ifdef g_power_save_expired
if (IS_NOT_NOAA_CHANNEL(g_rx_vfo->channel_save))
#endif
{
Expand Down
155 changes: 83 additions & 72 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ static void APP_HandleIncoming(void)
if (IS_NOAA_CHANNEL(g_rx_vfo->channel_save) && g_noaa_count_down_10ms > 0)
{
g_noaa_count_down_10ms = 0;
flag = true;
flag = true;
}
#endif

if (g_CTCSS_lost && g_current_code_type == CODE_TYPE_CONTINUOUS_TONE)
{
flag = true;
flag = true;
g_found_CTCSS = false;
}

Expand Down Expand Up @@ -322,7 +322,7 @@ static void APP_HandleReceive(void)
{
if (g_CxCSS_tail_found)
{
Mode = END_OF_RX_MODE_TTE;
Mode = END_OF_RX_MODE_TTE;
g_CxCSS_tail_found = false;
}
}
Expand All @@ -336,13 +336,13 @@ static void APP_HandleReceive(void)
else
if (!g_found_CTCSS)
{
g_found_CTCSS = true;
g_found_CTCSS = true;
g_found_CTCSS_count_down_10ms = 100; // 1 sec
}

if (g_CxCSS_tail_found)
{
Mode = END_OF_RX_MODE_TTE;
Mode = END_OF_RX_MODE_TTE;
g_CxCSS_tail_found = false;
}
break;
Expand All @@ -356,7 +356,7 @@ static void APP_HandleReceive(void)
else
if (!g_found_CDCSS)
{
g_found_CDCSS = true;
g_found_CDCSS = true;
g_found_CDCSS_count_down_10ms = 100; // 1 sec
}

Expand All @@ -375,15 +375,19 @@ static void APP_HandleReceive(void)
else
Mode = END_OF_RX_MODE_END;

if (!g_end_of_rx_detected_maybe &&
Mode == END_OF_RX_MODE_SKIP &&
g_next_time_slice_40ms &&
if (!g_end_of_rx_detected_maybe &&
Mode == END_OF_RX_MODE_SKIP &&
g_next_time_slice_40ms &&
g_eeprom.tail_note_elimination &&
(g_current_code_type == CODE_TYPE_DIGITAL || g_current_code_type == CODE_TYPE_REVERSE_DIGITAL) &&
BK4819_GetCTCType() == 1)
{
Mode = END_OF_RX_MODE_TTE;
}
else
{
g_next_time_slice_40ms = false;
}

Skip:
switch (Mode)
Expand Down Expand Up @@ -520,7 +524,6 @@ void APP_StartListening(function_type_t Function, const bool reset_am_fix)
g_rx_vfo->pRX->frequency = NoaaFrequencyTable[g_noaa_channel];
g_rx_vfo->pTX->frequency = NoaaFrequencyTable[g_noaa_channel];
g_eeprom.screen_channel[chan] = g_rx_vfo->channel_save;

g_noaa_count_down_10ms = 500; // 5 sec
g_schedule_noaa = false;
}
Expand Down Expand Up @@ -873,15 +876,15 @@ void APP_CheckRadioInterrupts(void)
#ifdef ENABLE_VOX
if (interrupt_status_bits & BK4819_REG_02_VOX_LOST)
{
g_vox_lost = true;
g_vox_lost = true;
g_vox_pause_count_down = 10;

if (g_eeprom.vox_switch)
{
if (g_current_function == FUNCTION_POWER_SAVE && !g_rx_idle_mode)
{
g_power_save_10ms = power_save2_10ms;
g_power_save_count_down_expired = 0;
g_power_save_10ms = power_save2_10ms;
g_power_save_expired = false;
}

if (g_eeprom.dual_watch != DUAL_WATCH_OFF && (g_schedule_dual_watch || g_dual_watch_count_down_10ms < dual_watch_count_after_vox_10ms))
Expand Down Expand Up @@ -1117,16 +1120,16 @@ void APP_Update(void)

#ifdef ENABLE_NOAA
#ifdef ENABLE_VOICE
if (g_eeprom.dual_watch == DUAL_WATCH_OFF && g_is_noaa_mode && g_schedule_noaa && g_voice_write_index == 0)
#else
if (g_eeprom.dual_watch == DUAL_WATCH_OFF && g_is_noaa_mode && g_schedule_noaa)
if (g_voice_write_index == 0)
#endif
{
NOAA_IncreaseChannel();
RADIO_SetupRegisters(false);

g_noaa_count_down_10ms = 7; // 70ms
g_schedule_noaa = false;
if (g_eeprom.dual_watch == DUAL_WATCH_OFF && g_is_noaa_mode && g_schedule_noaa)
{
NOAA_IncreaseChannel();
RADIO_SetupRegisters(false);
g_noaa_count_down_10ms = 7; // 70ms
g_schedule_noaa = false;
}
}
#endif

Expand Down Expand Up @@ -1187,7 +1190,7 @@ void APP_Update(void)
#ifdef ENABLE_NOAA
if (
#ifdef ENABLE_FMRADIO
g_fm_radio_mode ||
g_fm_radio_mode ||
#endif
g_ptt_is_pressed ||
g_key_held ||
Expand All @@ -1200,7 +1203,9 @@ void APP_Update(void)
g_battery_save_count_down_10ms = battery_save_count_10ms;
}
else
if ((IS_NOT_NOAA_CHANNEL(g_eeprom.screen_channel[0]) && IS_NOT_NOAA_CHANNEL(g_eeprom.screen_channel[1])) || !g_is_noaa_mode)
if ((IS_NOT_NOAA_CHANNEL(g_eeprom.screen_channel[0]) &&
IS_NOT_NOAA_CHANNEL(g_eeprom.screen_channel[1])) ||
!g_is_noaa_mode)
{
FUNCTION_Select(FUNCTION_POWER_SAVE);
}
Expand All @@ -1211,7 +1216,7 @@ void APP_Update(void)
#else
if (
#ifdef ENABLE_FMRADIO
g_fm_radio_mode ||
g_fm_radio_mode ||
#endif
g_ptt_is_pressed ||
g_key_held ||
Expand All @@ -1227,69 +1232,76 @@ void APP_Update(void)
{
FUNCTION_Select(FUNCTION_POWER_SAVE);
}

g_schedule_power_save = false;
#endif

g_schedule_power_save = false;
}

#ifdef ENABLE_VOICE
if (g_power_save_count_down_expired && g_current_function == FUNCTION_POWER_SAVE && g_voice_write_index == 0)
#else
if (g_power_save_count_down_expired && g_current_function == FUNCTION_POWER_SAVE)
#endif
{ // wake up, enable RX then go back to sleep
#ifdef ENABLE_VOICE
if (g_voice_write_index == 0)
#endif
{
if (g_power_save_expired && g_current_function == FUNCTION_POWER_SAVE)
{ // wake up, enable RX then go back to sleep
if (g_rx_idle_mode)
{
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_SendText("ps wake up\r\n");
#endif

if (g_rx_idle_mode)
{
BK4819_Conditional_RX_TurnOn_and_GPIO6_Enable();
BK4819_Conditional_RX_TurnOn_and_GPIO6_Enable();

#ifdef ENABLE_VOX
if (g_eeprom.vox_switch)
BK4819_EnableVox(g_eeprom.vox1_threshold, g_eeprom.vox0_threshold);
#endif
#ifdef ENABLE_VOX
if (g_eeprom.vox_switch)
BK4819_EnableVox(g_eeprom.vox1_threshold, g_eeprom.vox0_threshold);
#endif

if (g_eeprom.dual_watch != DUAL_WATCH_OFF &&
g_scan_state_dir == SCAN_OFF &&
g_css_scan_mode == CSS_SCAN_MODE_OFF)
{ // dual watch mode, toggle between the two VFO's
DUALWATCH_Alternate();
if (g_eeprom.dual_watch != DUAL_WATCH_OFF &&
g_scan_state_dir == SCAN_OFF &&
g_css_scan_mode == CSS_SCAN_MODE_OFF)
{ // dual watch mode, toggle between the two VFO's
DUALWATCH_Alternate();

g_update_rssi = false;
}
g_update_rssi = false;
}

FUNCTION_Init();
FUNCTION_Init();

g_power_save_10ms = power_save1_10ms; // come back here in a bit
g_rx_idle_mode = false; // RX is awake
}
else
if (g_eeprom.dual_watch == DUAL_WATCH_OFF || g_scan_state_dir != SCAN_OFF || g_css_scan_mode != CSS_SCAN_MODE_OFF || g_update_rssi)
{ // dual watch mode, go back to sleep
g_power_save_10ms = power_save1_10ms; // come back here in a bit
g_rx_idle_mode = false; // RX is awake
}
else
if (g_eeprom.dual_watch == DUAL_WATCH_OFF ||
g_scan_state_dir != SCAN_OFF ||
g_css_scan_mode != CSS_SCAN_MODE_OFF ||
g_update_rssi)
{ // dual watch mode, go back to sleep

updateRSSI(g_eeprom.rx_vfo);
updateRSSI(g_eeprom.rx_vfo);

// go back to sleep
// go back to sleep

g_power_save_10ms = g_eeprom.battery_save * 10;
g_rx_idle_mode = true;
g_power_save_10ms = g_eeprom.battery_save * 10;
g_rx_idle_mode = true;

BK4819_DisableVox();
BK4819_Sleep();
BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2, false);
BK4819_DisableVox();
BK4819_Sleep();
BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2, false);

// Authentic device checked removed
// Authentic device checked removed

}
else
{
// toggle between the two VFO's
DUALWATCH_Alternate();
}
else
{
// toggle between the two VFO's
DUALWATCH_Alternate();

g_update_rssi = true;
g_power_save_10ms = power_save1_10ms;
}
g_update_rssi = true;
g_power_save_10ms = power_save1_10ms;
}

g_power_save_count_down_expired = false;
g_power_save_expired = false;
}
}
}

Expand Down Expand Up @@ -2061,8 +2073,7 @@ void APP_TimeSlice500ms(void)

g_reduced_service = true;

//if (g_current_function != FUNCTION_POWER_SAVE)
FUNCTION_Select(FUNCTION_POWER_SAVE);
FUNCTION_Select(FUNCTION_POWER_SAVE);

ST7565_HardwareReset();

Expand Down
17 changes: 17 additions & 0 deletions app/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "driver/eeprom.h"
#include "driver/gpio.h"
#include "driver/keyboard.h"
#include "driver/st7565.h"
#include "frequencies.h"
#include "helper/battery.h"
#include "misc.h"
Expand Down Expand Up @@ -214,6 +215,13 @@ int MENU_GetLimits(uint8_t Cursor, int32_t *pMin, int32_t *pMax)
*pMax = ARRAY_SIZE(g_sub_menu_rx_tx) - 1;
break;

case MENU_CONTRAST:
// *pMin = 0;
// *pMax = 63;
*pMin = 26;
*pMax = 45;
break;

#ifdef ENABLE_AM_FIX_TEST1
case MENU_AM_FIX_TEST1:
*pMin = 0;
Expand Down Expand Up @@ -537,6 +545,11 @@ void MENU_AcceptSetting(void)
g_setting_backlight_on_tx_rx = g_sub_menu_selection;
break;

case MENU_CONTRAST:
g_setting_contrast = g_sub_menu_selection;
ST7565_SetContrast(g_setting_contrast);
break;

case MENU_TDR:
// g_eeprom.dual_watch = g_sub_menu_selection;
g_eeprom.dual_watch = (g_sub_menu_selection > 0) ? 1 + g_eeprom.tx_vfo : DUAL_WATCH_OFF;
Expand Down Expand Up @@ -1003,6 +1016,10 @@ void MENU_ShowCurrentSetting(void)
g_sub_menu_selection = g_setting_backlight_on_tx_rx;
break;

case MENU_CONTRAST:
g_sub_menu_selection = g_setting_contrast;
break;

case MENU_TDR:
// g_sub_menu_selection = g_eeprom.dual_watch;
g_sub_menu_selection = (g_eeprom.dual_watch == DUAL_WATCH_OFF) ? 0 : 1;
Expand Down
10 changes: 5 additions & 5 deletions app/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,11 @@ static void CMD_052F(const uint8_t *pBuffer)
{
const CMD_052F_t *pCmd = (const CMD_052F_t *)pBuffer;

g_eeprom.dual_watch = DUAL_WATCH_OFF;
g_eeprom.cross_vfo_rx_tx = CROSS_BAND_OFF;
g_eeprom.rx_vfo = 0;
g_eeprom.dtmf_side_tone = false;
g_eeprom.vfo_info[0].frequency_reverse = false;
g_eeprom.dual_watch = DUAL_WATCH_OFF;
g_eeprom.cross_vfo_rx_tx = CROSS_BAND_OFF;
g_eeprom.rx_vfo = 0;
g_eeprom.dtmf_side_tone = false;
g_eeprom.vfo_info[0].frequency_reverse = false;
g_eeprom.vfo_info[0].pRX = &g_eeprom.vfo_info[0].freq_config_rx;
g_eeprom.vfo_info[0].pTX = &g_eeprom.vfo_info[0].freq_config_tx;
g_eeprom.vfo_info[0].tx_offset_freq_dir = TX_OFFSET_FREQ_DIR_OFF;
Expand Down
1 change: 1 addition & 0 deletions board.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ void BOARD_EEPROM_Init(void)

// 0E78..0E7F
EEPROM_ReadBuffer(0x0E78, Data, 8);
g_setting_contrast = (Data[0] > 45) ? 31 : (Data[0] < 26) ? 31 : Data[0];
g_eeprom.channel_display_mode = (Data[1] < 4) ? Data[1] : MDF_FREQUENCY; // 4 instead of 3 - extra display mode
g_eeprom.cross_vfo_rx_tx = (Data[2] < 3) ? Data[2] : CROSS_BAND_OFF;
g_eeprom.battery_save = (Data[3] < 5) ? Data[3] : 4;
Expand Down
Loading

0 comments on commit 6660d00

Please sign in to comment.