2023-09-09 07:03:56 +00:00
|
|
|
/* Copyright 2023 Dual Tachyon
|
|
|
|
* https://github.com/DualTachyon
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "misc.h"
|
2023-10-05 08:17:38 +00:00
|
|
|
#include "settings.h"
|
2023-09-09 07:03:56 +00:00
|
|
|
|
2023-09-17 09:13:55 +00:00
|
|
|
const uint8_t fm_resume_countdown_500ms = 2500 / 500; // 2.5 seconds
|
|
|
|
const uint8_t fm_radio_countdown_500ms = 2000 / 500; // 2 seconds
|
|
|
|
const uint16_t fm_play_countdown_scan_10ms = 100 / 10; // 100ms
|
|
|
|
const uint16_t fm_play_countdown_noscan_10ms = 1200 / 10; // 1.2 seconds
|
2023-09-25 12:27:52 +00:00
|
|
|
const uint16_t fm_restore_countdown_10ms = 5000 / 10; // 5 seconds
|
2023-09-18 07:30:24 +00:00
|
|
|
|
2023-10-02 21:04:41 +00:00
|
|
|
const uint8_t menu_timeout_500ms = 20000 / 500; // 20 seconds
|
|
|
|
const uint16_t menu_timeout_long_500ms = 120000 / 500; // 2 minutes
|
2023-09-18 07:30:24 +00:00
|
|
|
|
2023-09-29 19:48:23 +00:00
|
|
|
const uint8_t DTMF_RX_live_timeout_500ms = 6000 / 500; // 6 seconds live decoder on screen
|
|
|
|
const uint8_t DTMF_RX_timeout_500ms = 10000 / 500; // 10 seconds till we wipe the DTMF receiver
|
2023-09-30 10:22:19 +00:00
|
|
|
const uint8_t DTMF_decode_ring_countdown_500ms = 15000 / 500; // 15 seconds .. time we sound the ringing for
|
2023-09-17 09:13:55 +00:00
|
|
|
const uint8_t DTMF_txstop_countdown_500ms = 3000 / 500; // 6 seconds
|
|
|
|
|
|
|
|
const uint8_t key_input_timeout_500ms = 8000 / 500; // 8 seconds
|
2023-09-18 07:30:24 +00:00
|
|
|
|
2023-09-17 09:13:55 +00:00
|
|
|
const uint16_t key_repeat_delay_10ms = 400 / 10; // 400ms
|
|
|
|
const uint16_t key_repeat_10ms = 80 / 10; // 80ms .. MUST be less than 'key_repeat_delay'
|
|
|
|
const uint16_t key_debounce_10ms = 20 / 10; // 20ms
|
2023-09-18 07:30:24 +00:00
|
|
|
|
2023-09-17 09:13:55 +00:00
|
|
|
const uint8_t scan_delay_10ms = 210 / 10; // 210ms
|
2023-09-18 07:30:24 +00:00
|
|
|
|
2023-09-17 09:13:55 +00:00
|
|
|
const uint16_t dual_watch_count_after_tx_10ms = 3600 / 10; // 3.6 sec after TX ends
|
|
|
|
const uint16_t dual_watch_count_after_rx_10ms = 1000 / 10; // 1 sec after RX ends ?
|
|
|
|
const uint16_t dual_watch_count_after_1_10ms = 5000 / 10; // 5 sec
|
|
|
|
const uint16_t dual_watch_count_after_2_10ms = 3600 / 10; // 3.6 sec
|
|
|
|
const uint16_t dual_watch_count_noaa_10ms = 70 / 10; // 70ms
|
2023-10-04 10:57:34 +00:00
|
|
|
#ifdef ENABLE_VOX
|
|
|
|
const uint16_t dual_watch_count_after_vox_10ms = 200 / 10; // 200ms
|
|
|
|
#endif
|
2023-09-18 07:30:24 +00:00
|
|
|
const uint16_t dual_watch_count_toggle_10ms = 100 / 10; // 100ms between VFO toggles
|
|
|
|
|
2023-09-26 12:59:01 +00:00
|
|
|
const uint16_t scan_pause_delay_in_1_10ms = 5000 / 10; // 5 seconds
|
|
|
|
const uint16_t scan_pause_delay_in_2_10ms = 500 / 10; // 500ms
|
|
|
|
const uint16_t scan_pause_delay_in_3_10ms = 200 / 10; // 200ms
|
|
|
|
const uint16_t scan_pause_delay_in_4_10ms = 300 / 10; // 300ms
|
2023-10-02 08:31:35 +00:00
|
|
|
const uint16_t scan_pause_delay_in_5_10ms = 1000 / 10; // 1 sec
|
|
|
|
const uint16_t scan_pause_delay_in_6_10ms = 100 / 10; // 100ms
|
|
|
|
const uint16_t scan_pause_delay_in_7_10ms = 3600 / 10; // 3.6 seconds
|
2023-09-26 12:59:01 +00:00
|
|
|
|
2023-09-17 09:13:55 +00:00
|
|
|
const uint16_t battery_save_count_10ms = 10000 / 10; // 10 seconds
|
2023-09-18 07:30:24 +00:00
|
|
|
|
2023-09-21 22:06:47 +00:00
|
|
|
const uint16_t power_save1_10ms = 100 / 10; // 100ms
|
|
|
|
const uint16_t power_save2_10ms = 200 / 10; // 200ms
|
|
|
|
|
2023-10-04 10:57:34 +00:00
|
|
|
#ifdef ENABLE_VOX
|
|
|
|
const uint16_t vox_stop_count_down_10ms = 1000 / 10; // 1 second
|
|
|
|
#endif
|
2023-09-26 15:48:16 +00:00
|
|
|
|
2023-09-25 12:27:52 +00:00
|
|
|
const uint16_t NOAA_countdown_10ms = 5000 / 10; // 5 seconds
|
|
|
|
const uint16_t NOAA_countdown_2_10ms = 500 / 10; // 500ms
|
|
|
|
const uint16_t NOAA_countdown_3_10ms = 200 / 10; // 200ms
|
|
|
|
|
2023-10-01 21:14:45 +00:00
|
|
|
//const uint16_t gMax_bat_v = 840; // 8.4V
|
|
|
|
//const uint16_t gMin_bat_v = 660; // 6.6V
|
2023-09-17 09:13:55 +00:00
|
|
|
|
|
|
|
const uint32_t gDefaultAesKey[4] = {0x4AA5CC60, 0x0312CC5F, 0xFFD2DABB, 0x6BBA7F92};
|
2023-09-18 07:30:24 +00:00
|
|
|
|
2023-09-17 09:13:55 +00:00
|
|
|
const uint8_t gMicGain_dB2[5] = {3, 8, 16, 24, 31};
|
2023-09-13 16:34:56 +00:00
|
|
|
|
2023-09-09 07:03:56 +00:00
|
|
|
bool gSetting_350TX;
|
|
|
|
bool gSetting_KILLED;
|
|
|
|
bool gSetting_200TX;
|
|
|
|
bool gSetting_500TX;
|
|
|
|
bool gSetting_350EN;
|
2023-09-19 08:16:57 +00:00
|
|
|
bool gSetting_TX_EN;
|
2023-09-09 07:03:56 +00:00
|
|
|
uint8_t gSetting_F_LOCK;
|
|
|
|
bool gSetting_ScrambleEnable;
|
|
|
|
|
2023-10-04 15:37:11 +00:00
|
|
|
uint8_t gSetting_backlight_on_tx_rx;
|
2023-10-03 12:18:49 +00:00
|
|
|
|
2023-09-21 22:25:46 +00:00
|
|
|
#ifdef ENABLE_AM_FIX
|
2023-09-21 22:06:47 +00:00
|
|
|
bool gSetting_AM_fix;
|
|
|
|
#endif
|
2023-09-23 16:23:21 +00:00
|
|
|
#ifdef ENABLE_AM_FIX_TEST1
|
|
|
|
uint8_t gSetting_AM_fix_test1 = 0;
|
|
|
|
#endif
|
2023-09-21 06:31:29 +00:00
|
|
|
#ifdef ENABLE_AUDIO_BAR
|
|
|
|
bool gSetting_mic_bar;
|
|
|
|
#endif
|
2023-09-19 09:23:50 +00:00
|
|
|
bool gSetting_live_DTMF_decoder;
|
2023-09-19 19:04:02 +00:00
|
|
|
uint8_t gSetting_battery_text;
|
2023-09-19 09:23:50 +00:00
|
|
|
|
2023-09-26 12:59:01 +00:00
|
|
|
bool gMonitor = false; // true opens the squelch
|
|
|
|
|
2023-09-09 07:03:56 +00:00
|
|
|
uint32_t gCustomAesKey[4];
|
|
|
|
bool bHasCustomAesKey;
|
|
|
|
uint32_t gChallenge[4];
|
|
|
|
uint8_t gTryCount;
|
|
|
|
|
|
|
|
uint8_t gEEPROM_1EC0_0[8];
|
|
|
|
uint8_t gEEPROM_1EC0_1[8];
|
|
|
|
uint8_t gEEPROM_1EC0_2[8];
|
|
|
|
uint8_t gEEPROM_1EC0_3[8];
|
|
|
|
|
2023-09-29 14:22:41 +00:00
|
|
|
uint16_t gEEPROM_RSSI_CALIB[2][4];
|
2023-09-16 16:16:36 +00:00
|
|
|
|
2023-09-09 07:03:56 +00:00
|
|
|
uint16_t gEEPROM_1F8A;
|
|
|
|
uint16_t gEEPROM_1F8C;
|
|
|
|
|
2023-09-20 07:29:11 +00:00
|
|
|
uint8_t gMR_ChannelAttributes[FREQ_CHANNEL_LAST + 1];
|
2023-09-09 07:03:56 +00:00
|
|
|
|
2023-09-18 07:30:24 +00:00
|
|
|
volatile uint16_t gBatterySaveCountdown_10ms = battery_save_count_10ms;
|
2023-09-21 22:06:47 +00:00
|
|
|
|
|
|
|
volatile bool gPowerSaveCountdownExpired;
|
2023-09-18 20:18:00 +00:00
|
|
|
volatile bool gSchedulePowerSave;
|
|
|
|
|
|
|
|
volatile bool gScheduleDualWatch = true;
|
2023-09-18 07:30:24 +00:00
|
|
|
|
|
|
|
volatile uint16_t gDualWatchCountdown_10ms;
|
|
|
|
volatile bool gDualWatchCountdownExpired = true;
|
|
|
|
bool gDualWatchActive = false;
|
|
|
|
|
2023-10-02 21:04:41 +00:00
|
|
|
volatile uint8_t gSerialConfigCountDown_500ms;
|
|
|
|
|
2023-09-28 16:39:45 +00:00
|
|
|
volatile bool gNextTimeslice_500ms;
|
|
|
|
|
|
|
|
volatile uint16_t gTxTimerCountdown_500ms;
|
|
|
|
volatile bool gTxTimeoutReached;
|
|
|
|
|
2023-09-18 07:30:24 +00:00
|
|
|
volatile uint16_t gTailNoteEliminationCountdown_10ms;
|
2023-09-28 16:39:45 +00:00
|
|
|
|
2023-09-14 08:56:30 +00:00
|
|
|
#ifdef ENABLE_NOAA
|
2023-09-18 07:30:24 +00:00
|
|
|
volatile uint16_t gNOAA_Countdown_10ms;
|
2023-09-09 07:03:56 +00:00
|
|
|
#endif
|
2023-09-13 17:45:52 +00:00
|
|
|
|
2023-09-09 07:03:56 +00:00
|
|
|
bool gEnableSpeaker;
|
2023-09-15 14:36:43 +00:00
|
|
|
uint8_t gKeyInputCountdown = 0;
|
2023-09-09 07:03:56 +00:00
|
|
|
uint8_t gKeyLockCountdown;
|
|
|
|
uint8_t gRTTECountdown;
|
|
|
|
bool bIsInLockScreen;
|
|
|
|
uint8_t gUpdateStatus;
|
|
|
|
uint8_t gFoundCTCSS;
|
|
|
|
uint8_t gFoundCDCSS;
|
|
|
|
bool gEndOfRxDetectedMaybe;
|
2023-09-17 14:36:23 +00:00
|
|
|
|
2023-09-23 02:28:21 +00:00
|
|
|
int16_t gVFO_RSSI[2];
|
|
|
|
uint8_t gVFO_RSSI_bar_level[2];
|
2023-09-17 14:36:23 +00:00
|
|
|
|
2023-09-09 07:03:56 +00:00
|
|
|
uint8_t gReducedService;
|
|
|
|
uint8_t gBatteryVoltageIndex;
|
|
|
|
CssScanMode_t gCssScanMode;
|
|
|
|
bool gUpdateRSSI;
|
2023-10-01 18:17:51 +00:00
|
|
|
#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750)
|
2023-09-09 08:01:52 +00:00
|
|
|
AlarmState_t gAlarmState;
|
|
|
|
#endif
|
2023-10-02 21:04:41 +00:00
|
|
|
uint16_t gMenuCountdown;
|
2023-09-09 07:03:56 +00:00
|
|
|
bool gPttWasReleased;
|
|
|
|
bool gPttWasPressed;
|
|
|
|
uint8_t gKeypadLocked;
|
|
|
|
bool gFlagReconfigureVfos;
|
|
|
|
uint8_t gVfoConfigureMode;
|
|
|
|
bool gFlagResetVfos;
|
|
|
|
bool gRequestSaveVFO;
|
|
|
|
uint8_t gRequestSaveChannel;
|
|
|
|
bool gRequestSaveSettings;
|
2023-09-14 08:56:30 +00:00
|
|
|
#ifdef ENABLE_FMRADIO
|
|
|
|
bool gRequestSaveFM;
|
|
|
|
#endif
|
2023-09-09 07:03:56 +00:00
|
|
|
bool gFlagPrepareTX;
|
2023-10-01 23:38:59 +00:00
|
|
|
|
2023-09-09 07:03:56 +00:00
|
|
|
bool gFlagAcceptSetting;
|
|
|
|
bool gFlagRefreshSetting;
|
2023-10-01 23:38:59 +00:00
|
|
|
|
2023-09-09 07:03:56 +00:00
|
|
|
bool gFlagSaveVfo;
|
|
|
|
bool gFlagSaveSettings;
|
|
|
|
bool gFlagSaveChannel;
|
2023-09-14 08:56:30 +00:00
|
|
|
#ifdef ENABLE_FMRADIO
|
|
|
|
bool gFlagSaveFM;
|
|
|
|
#endif
|
2023-09-09 07:03:56 +00:00
|
|
|
bool g_CDCSS_Lost;
|
|
|
|
uint8_t gCDCSSCodeType;
|
|
|
|
bool g_CTCSS_Lost;
|
|
|
|
bool g_CxCSS_TAIL_Found;
|
2023-10-04 10:57:34 +00:00
|
|
|
#ifdef ENABLE_VOX
|
|
|
|
bool g_VOX_Lost;
|
|
|
|
bool gVOX_NoiseDetected;
|
|
|
|
uint16_t gVoxResumeCountdown;
|
|
|
|
uint16_t gVoxPauseCountdown;
|
|
|
|
#endif
|
2023-09-09 07:03:56 +00:00
|
|
|
bool g_SquelchLost;
|
|
|
|
uint8_t gFlashLightState;
|
|
|
|
volatile uint16_t gFlashLightBlinkCounter;
|
|
|
|
bool gFlagEndTransmission;
|
|
|
|
uint16_t gLowBatteryCountdown;
|
|
|
|
uint8_t gNextMrChannel;
|
|
|
|
ReceptionMode_t gRxReceptionMode;
|
2023-10-02 08:31:35 +00:00
|
|
|
|
|
|
|
uint8_t gRestoreMrChannel;
|
|
|
|
enum scan_next_chan_t gCurrentScanList;
|
|
|
|
uint32_t gRestoreFrequency;
|
|
|
|
|
2023-10-01 18:56:04 +00:00
|
|
|
bool gRxVfoIsActive;
|
2023-09-14 08:56:30 +00:00
|
|
|
#ifdef ENABLE_ALARM
|
2023-09-09 08:01:52 +00:00
|
|
|
uint8_t gAlarmToneCounter;
|
|
|
|
uint16_t gAlarmRunningCounter;
|
|
|
|
#endif
|
2023-09-09 07:03:56 +00:00
|
|
|
bool gKeyBeingHeld;
|
|
|
|
bool gPttIsPressed;
|
|
|
|
uint8_t gPttDebounceCounter;
|
|
|
|
uint8_t gMenuListCount;
|
|
|
|
uint8_t gBackupCROSS_BAND_RX_TX;
|
2023-09-18 10:29:28 +00:00
|
|
|
uint8_t gScanDelay_10ms;
|
2023-09-14 08:56:30 +00:00
|
|
|
#ifdef ENABLE_AIRCOPY
|
2023-09-09 07:03:56 +00:00
|
|
|
uint8_t gAircopySendCountdown;
|
|
|
|
#endif
|
|
|
|
uint8_t gFSKWriteIndex;
|
|
|
|
|
2023-09-14 08:56:30 +00:00
|
|
|
#ifdef ENABLE_NOAA
|
2023-09-09 07:03:56 +00:00
|
|
|
bool gIsNoaaMode;
|
|
|
|
uint8_t gNoaaChannel;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool gUpdateDisplay;
|
2023-10-01 16:19:38 +00:00
|
|
|
|
2023-10-01 23:38:59 +00:00
|
|
|
bool gF_LOCK = false;
|
|
|
|
|
2023-09-09 07:03:56 +00:00
|
|
|
uint8_t gShowChPrefix;
|
2023-09-13 17:45:52 +00:00
|
|
|
|
|
|
|
volatile bool gNextTimeslice;
|
2023-09-18 07:30:24 +00:00
|
|
|
volatile uint8_t gFoundCDCSSCountdown_10ms;
|
|
|
|
volatile uint8_t gFoundCTCSSCountdown_10ms;
|
2023-10-04 10:57:34 +00:00
|
|
|
#ifdef ENABLE_VOX
|
|
|
|
volatile uint16_t gVoxStopCountdown_10ms;
|
|
|
|
#endif
|
2023-09-09 07:03:56 +00:00
|
|
|
volatile bool gNextTimeslice40ms;
|
2023-09-14 08:56:30 +00:00
|
|
|
#ifdef ENABLE_NOAA
|
2023-09-18 07:30:24 +00:00
|
|
|
volatile uint16_t gNOAACountdown_10ms = 0;
|
|
|
|
volatile bool gScheduleNOAA = true;
|
2023-09-09 07:03:56 +00:00
|
|
|
#endif
|
2023-09-18 07:30:24 +00:00
|
|
|
volatile bool gFlagTailNoteEliminationComplete;
|
2023-09-14 08:56:30 +00:00
|
|
|
#ifdef ENABLE_FMRADIO
|
2023-09-18 07:30:24 +00:00
|
|
|
volatile bool gScheduleFM;
|
|
|
|
#endif
|
|
|
|
|
2023-09-18 10:54:42 +00:00
|
|
|
volatile uint8_t boot_counter_10ms;
|
2023-09-09 07:03:56 +00:00
|
|
|
|
2023-09-24 08:00:34 +00:00
|
|
|
int16_t gCurrentRSSI[2] = {0, 0}; // now one per VFO
|
2023-09-09 07:03:56 +00:00
|
|
|
|
|
|
|
uint8_t gIsLocked = 0xFF;
|
|
|
|
|
2023-10-05 08:17:38 +00:00
|
|
|
unsigned int get_rx_VFO(void)
|
|
|
|
{
|
|
|
|
unsigned int rx_vfo = gEeprom.TX_VFO;
|
|
|
|
if (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_CHAN_B)
|
|
|
|
rx_vfo = 0;
|
|
|
|
else
|
|
|
|
if (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_CHAN_A)
|
|
|
|
rx_vfo = 1;
|
|
|
|
else
|
|
|
|
if (gEeprom.DUAL_WATCH == DUAL_WATCH_CHAN_B)
|
|
|
|
rx_vfo = 1;
|
|
|
|
else
|
|
|
|
if (gEeprom.DUAL_WATCH == DUAL_WATCH_CHAN_A)
|
|
|
|
rx_vfo = 0;
|
|
|
|
return rx_vfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int get_tx_VFO(void)
|
|
|
|
{
|
|
|
|
unsigned int tx_vfo = gEeprom.TX_VFO;
|
|
|
|
if (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_CHAN_B)
|
|
|
|
tx_vfo = 1;
|
|
|
|
else
|
|
|
|
if (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_CHAN_A)
|
|
|
|
tx_vfo = 0;
|
|
|
|
else
|
|
|
|
if (gEeprom.DUAL_WATCH == DUAL_WATCH_CHAN_B)
|
|
|
|
tx_vfo = 1;
|
|
|
|
else
|
|
|
|
if (gEeprom.DUAL_WATCH == DUAL_WATCH_CHAN_A)
|
|
|
|
tx_vfo = 0;
|
|
|
|
return tx_vfo;
|
|
|
|
}
|
2023-09-09 07:03:56 +00:00
|
|
|
|
|
|
|
void NUMBER_Get(char *pDigits, uint32_t *pInteger)
|
|
|
|
{
|
2023-09-10 04:49:39 +00:00
|
|
|
unsigned int i;
|
|
|
|
uint32_t Multiplier = 10000000;
|
|
|
|
uint32_t Value = 0;
|
2023-09-09 07:03:56 +00:00
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
if (pDigits[i] > 9)
|
|
|
|
break;
|
|
|
|
Value += pDigits[i] * Multiplier;
|
|
|
|
Multiplier /= 10U;
|
|
|
|
}
|
|
|
|
*pInteger = Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NUMBER_ToDigits(uint32_t Value, char *pDigits)
|
|
|
|
{
|
2023-09-10 04:49:39 +00:00
|
|
|
unsigned int i;
|
2023-09-09 07:03:56 +00:00
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
const uint32_t Result = Value / 10U;
|
|
|
|
pDigits[7 - i] = Value - (Result * 10U);
|
|
|
|
Value = Result;
|
|
|
|
}
|
2023-09-10 04:49:39 +00:00
|
|
|
pDigits[8] = 0;
|
2023-09-09 07:03:56 +00:00
|
|
|
}
|
|
|
|
|
2023-09-15 20:58:59 +00:00
|
|
|
int32_t NUMBER_AddWithWraparound(int32_t Base, int32_t Add, int32_t LowerLimit, int32_t UpperLimit)
|
2023-09-09 07:03:56 +00:00
|
|
|
{
|
|
|
|
Base += Add;
|
2023-09-15 20:58:59 +00:00
|
|
|
|
|
|
|
if (Base == 0x7fffffff || Base < LowerLimit)
|
2023-09-09 07:03:56 +00:00
|
|
|
return UpperLimit;
|
2023-09-15 20:58:59 +00:00
|
|
|
|
2023-09-09 07:03:56 +00:00
|
|
|
if (Base > UpperLimit)
|
|
|
|
return LowerLimit;
|
2023-09-15 20:58:59 +00:00
|
|
|
|
2023-09-09 07:03:56 +00:00
|
|
|
return Base;
|
|
|
|
}
|