diff --git a/Makefile b/Makefile index f8045dd..4679904 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ ENABLE_AM_FIX := 1 ENABLE_AM_FIX_SHOW_DATA := 1 ENABLE_SQUELCH1_LOWER := 0 ENABLE_AUDIO_BAR := 0 +ENABLE_COPY_CHAN_TO_VFO := 1 #ENABLE_SINGLE_VFO_CHAN := 1 #ENABLE_BAND_SCOPE := 1 @@ -226,6 +227,9 @@ endif ifeq ($(ENABLE_AUDIO_BAR),1) CFLAGS += -DENABLE_AUDIO_BAR endif +ifeq ($(ENABLE_COPY_CHAN_TO_VFO),1) + CFLAGS += -DENABLE_COPY_CHAN_TO_VFO +endif ifeq ($(ENABLE_SINGLE_VFO_CHAN),1) CFLAGS += -DENABLE_SINGLE_VFO_CHAN endif diff --git a/README.md b/README.md index 0c4e615..f183076 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ ENABLE_AM_FIX := 1 dynamically adjust the front end gains ENABLE_AM_FIX_SHOW_DATA := 1 show debug data for the AM fix ENABLE_SQUELCH1_LOWER := 0 adjusts squelch setting '1' to be more sensitive - I plan to let user adjust it in the menu ENABLE_AUDIO_BAR := 0 experimental, display an audo bar level when TX'ing +#ENABLE_COPY_CHAN_TO_VFO := 1 not yet implemented - copy the channel into the VFO #ENABLE_SINGLE_VFO_CHAN := 1 not yet implemented - single VFO on display when possible #ENABLE_BAND_SCOPE := 1 not yet implemented - spectrum/pan-adapter ``` diff --git a/am_fix.c b/am_fix.c index 3fb7e65..38c1a0c 100644 --- a/am_fix.c +++ b/am_fix.c @@ -53,8 +53,8 @@ const uint8_t orig_pga = 6; // -3dB uint8_t mixer; // 0 ~ 3 uint8_t pga; // 0 ~ 7 #endif - } t_am_fix_gain_table; - //} __attribute__((packed)) t_am_fix_gain_table; + } t_gain_table; + //} __attribute__((packed)) t_gain_table; // REG_10 AGC gain table // @@ -109,7 +109,7 @@ const uint8_t orig_pga = 6; // -3dB // lookup table is hugely easier than writing code to do the same // - static const t_am_fix_gain_table am_fix_gain_table[] = + static const t_gain_table gain_table[] = { {.lna_short = 3, .lna = 2, .mixer = 3, .pga = 6}, // 0 0dB -14dB 0dB -3dB .. -17dB original @@ -126,74 +126,8 @@ const uint8_t orig_pga = 6; // -3dB const unsigned int original_index = 1; -#elif 0 - - // in this table the 'lna-short' register I leave unchanged - - {3, 0, 0, 0}, // 1 .. 0dB -24dB -8dB -33dB .. -65dB - {3, 0, 1, 0}, // 2 .. 0dB -24dB -6dB -33dB .. -63dB - {3, 0, 2, 0}, // 3 .. 0dB -24dB -3dB -33dB .. -60dB - {3, 0, 0, 1}, // 4 .. 0dB -24dB -8dB -27dB .. -59dB - {3, 1, 1, 0}, // 5 .. 0dB -19dB -6dB -33dB .. -58dB - {3, 0, 1, 1}, // 6 .. 0dB -24dB -6dB -27dB .. -57dB - {3, 1, 2, 0}, // 7 .. 0dB -19dB -3dB -33dB .. -55dB - {3, 1, 0, 1}, // 8 .. 0dB -19dB -8dB -27dB .. -54dB - {3, 0, 0, 2}, // 9 .. 0dB -24dB -8dB -21dB .. -53dB - {3, 1, 1, 1}, // 10 .. 0dB -19dB -6dB -27dB .. -52dB - {3, 0, 1, 2}, // 11 .. 0dB -24dB -6dB -21dB .. -51dB - {3, 2, 2, 0}, // 12 .. 0dB -14dB -3dB -33dB .. -50dB - {3, 2, 0, 1}, // 13 .. 0dB -14dB -8dB -27dB .. -49dB - {3, 0, 2, 2}, // 14 .. 0dB -24dB -3dB -21dB .. -48dB - {3, 2, 3, 0}, // 15 .. 0dB -14dB 0dB -33dB .. -47dB - {3, 1, 3, 1}, // 16 .. 0dB -19dB 0dB -27dB .. -46dB - {3, 0, 3, 2}, // 17 .. 0dB -24dB 0dB -21dB .. -45dB - {3, 3, 0, 1}, // 18 .. 0dB -9dB -8dB -27dB .. -44dB - {3, 1, 2, 2}, // 19 .. 0dB -19dB -3dB -21dB .. -43dB - {3, 0, 2, 3}, // 20 .. 0dB -24dB -3dB -15dB .. -42dB - {3, 0, 0, 4}, // 21 .. 0dB -24dB -8dB -9dB .. -41dB - {3, 1, 1, 3}, // 22 .. 0dB -19dB -6dB -15dB .. -40dB - {3, 0, 1, 4}, // 23 .. 0dB -24dB -6dB -9dB .. -39dB - {3, 0, 0, 5}, // 24 .. 0dB -24dB -8dB -6dB .. -38dB - {3, 1, 2, 3}, // 25 .. 0dB -19dB -3dB -15dB .. -37dB - {3, 0, 2, 4}, // 26 .. 0dB -24dB -3dB -9dB .. -36dB - {3, 4, 0, 2}, // 27 .. 0dB -6dB -8dB -21dB .. -35dB - {3, 1, 1, 4}, // 28 .. 0dB -19dB -6dB -9dB .. -34dB - {3, 1, 0, 5}, // 29 .. 0dB -19dB -8dB -6dB .. -33dB - {3, 3, 0, 3}, // 30 .. 0dB -9dB -8dB -15dB .. -32dB - {3, 5, 1, 2}, // 31 .. 0dB -4dB -6dB -21dB .. -31dB - {3, 1, 0, 6}, // 32 .. 0dB -19dB -8dB -3dB .. -30dB - {3, 2, 3, 3}, // 33 .. 0dB -14dB 0dB -15dB .. -29dB - {3, 1, 1, 6}, // 34 .. 0dB -19dB -6dB -3dB .. -28dB - {3, 4, 1, 3}, // 35 .. 0dB -6dB -6dB -15dB .. -27dB - {3, 2, 2, 4}, // 36 .. 0dB -14dB -3dB -9dB .. -26dB - {3, 1, 2, 6}, // 37 .. 0dB -19dB -3dB -3dB .. -25dB - {3, 3, 1, 4}, // 38 .. 0dB -9dB -6dB -9dB .. -24dB - {3, 2, 1, 6}, // 39 .. 0dB -14dB -6dB -3dB .. -23dB - {3, 5, 2, 3}, // 40 .. 0dB -4dB -3dB -15dB .. -22dB - {3, 4, 1, 4}, // 41 .. 0dB -6dB -6dB -9dB .. -21dB - {3, 4, 0, 5}, // 42 .. 0dB -6dB -8dB -6dB .. -20dB - {3, 5, 1, 4}, // 43 .. 0dB -4dB -6dB -9dB .. -19dB - {3, 3, 3, 4}, // 44 .. 0dB -9dB 0dB -9dB .. -18dB - {3, 2, 3, 6}, // 45 .. 0dB -14dB 0dB -3dB .. -17dB original - {3, 5, 1, 5}, // 46 .. 0dB -4dB -6dB -6dB .. -16dB - {3, 3, 1, 7}, // 47 .. 0dB -9dB -6dB 0dB .. -15dB - {3, 2, 3, 7}, // 48 .. 0dB -14dB 0dB 0dB .. -14dB - {3, 5, 1, 6}, // 49 .. 0dB -4dB -6dB -3dB .. -13dB - {3, 4, 2, 6}, // 50 .. 0dB -6dB -3dB -3dB .. -12dB - {3, 5, 2, 6}, // 51 .. 0dB -4dB -3dB -3dB .. -10dB - {3, 4, 3, 6}, // 52 .. 0dB -6dB 0dB -3dB .. -9dB - {3, 5, 2, 7}, // 53 .. 0dB -4dB -3dB 0dB .. -7dB - {3, 4, 3, 7}, // 54 .. 0dB -6dB 0dB 0dB .. -6dB - {3, 5, 3, 7} // 55 .. 0dB -4dB 0dB 0dB .. -4dB - }; - - const unsigned int original_index = 45; - #else - // in this table I include adjusting the 'lna-short' register ~ - // more gain adjustment range from doing so - {0, 0, 0, 0}, // 1 .. -33dB -24dB -8dB -33dB .. -98dB {0, 0, 1, 0}, // 2 .. -33dB -24dB -6dB -33dB .. -96dB {1, 0, 0, 0}, // 3 .. -30dB -24dB -8dB -33dB .. -95dB @@ -296,18 +230,21 @@ const uint8_t orig_pga = 6; // -3dB #endif + // the total gain for each table index + int8_t gain_dB[ARRAY_SIZE(gain_table)] = {0}; + unsigned int counter = 0; int16_t orig_dB_gain = -17; #ifdef ENABLE_AM_FIX_TEST1 - unsigned int am_fix_gain_table_index[2] = {1 + gSetting_AM_fix_test1, 1 + gSetting_AM_fix_test1}; + unsigned int gain_table_index[2] = {1 + gSetting_AM_fix_test1, 1 + gSetting_AM_fix_test1}; #else - unsigned int am_fix_gain_table_index[2] = {original_index, original_index}; + unsigned int gain_table_index[2] = {original_index, original_index}; #endif // used to simply detect we've changed our table index/register settings - unsigned int am_fix_gain_table_index_prev[2] = {0, 0}; + unsigned int gain_table_index_prev[2] = {0, 0}; // holds the previous RSSI level int16_t prev_rssi[2] = {0, 0}; @@ -319,7 +256,7 @@ const uint8_t orig_pga = 6; // -3dB int16_t rssi_db_gain_diff[2] = {0, 0}; // used to limit the max front end gain - unsigned int max_index = ARRAY_SIZE(am_fix_gain_table) - 1; + unsigned int max_index = ARRAY_SIZE(gain_table) - 1; #ifndef ENABLE_AM_FIX_TEST1 // -89dBm, any higher and the AM demodulator starts to saturate/clip/distort @@ -330,35 +267,36 @@ const uint8_t orig_pga = 6; // -3dB { // called at boot-up unsigned int i; + for (i = 0; i < 2; i++) { #ifdef ENABLE_AM_FIX_TEST1 - am_fix_gain_table_index[i] = 1 + gSetting_AM_fix_test1; + gain_table_index[i] = 1 + gSetting_AM_fix_test1; #else - am_fix_gain_table_index[i] = original_index; // re-start with original QS setting + gain_table_index[i] = original_index; // re-start with original QS setting #endif } + // pre-compute the total gain DB for each table index + for (i = 0; i < ARRAY_SIZE(gain_table); i++) + { + const t_gain_table gains = gain_table[i]; + gain_dB[i] = lna_short_dB[gains.lna_short] + lna_dB[gains.lna] + mixer_dB[gains.mixer] + pga_dB[gains.pga]; + } + orig_dB_gain = lna_short_dB[orig_lna_short] + lna_dB[orig_lna] + mixer_dB[orig_mixer] + pga_dB[orig_pga]; #if 0 - { // set the maximum gain we want to use + { // set a maximum gain to use // const int16_t max_gain_dB = orig_dB_gain; const int16_t max_gain_dB = -10; - max_index = ARRAY_SIZE(am_fix_gain_table); + max_index = ARRAY_SIZE(gain_table); while (--max_index > 1) - { - const uint8_t lna_short = am_fix_gain_table[max_index].lna_short; - const uint8_t lna = am_fix_gain_table[max_index].lna; - const uint8_t mixer = am_fix_gain_table[max_index].mixer; - const uint8_t pga = am_fix_gain_table[max_index].pga; - const int16_t gain_dB = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga]; - if (gain_dB <= max_gain_dB) + if (gain_dB[max_index] <= max_gain_dB) break; - } } #else - max_index = ARRAY_SIZE(am_fix_gain_table) - 1; + max_index = ARRAY_SIZE(gain_table) - 1; #endif } @@ -374,12 +312,12 @@ const uint8_t orig_pga = 6; // -3dB rssi_db_gain_diff[vfo] = 0; #ifdef ENABLE_AM_FIX_TEST1 -// am_fix_gain_table_index[vfo] = 1 + gSetting_AM_fix_test1; +// gain_table_index[vfo] = 1 + gSetting_AM_fix_test1; #else -// am_fix_gain_table_index[vfo] = original_index; // re-start with original QS setting +// gain_table_index[vfo] = original_index; // re-start with original QS setting #endif - am_fix_gain_table_index_prev[vfo] = 0; + gain_table_index_prev[vfo] = 0; } // adjust the RX RF gain to try and prevent the AM demodulator from @@ -415,8 +353,13 @@ const uint8_t orig_pga = 6; // -3dB } if (counter > 0) + { if (++counter >= 20) // limit display update rate to 200ms - counter = 0; + { + counter = 0; + gUpdateDisplay = true; + } + } { // sample the current RSSI level // average it with the previous rssi (a bit of noise/spike immunity) @@ -444,9 +387,9 @@ const uint8_t orig_pga = 6; // -3dB { int i = 1 + (int)gSetting_AM_fix_test1; - i = (i < 1) ? 1 : (i > ((int)ARRAY_SIZE(am_fix_gain_table) - 1) ? ARRAY_SIZE(am_fix_gain_table) - 1 : i; + i = (i < 1) ? 1 : (i > ((int)ARRAY_SIZE(gain_table) - 1) ? ARRAY_SIZE(gain_table) - 1 : i; - if (am_fix_gain_table_index[vfo] == i) + if (gain_table_index[vfo] == i) return; // no change } @@ -462,38 +405,18 @@ const uint8_t orig_pga = 6; // -3dB if (diff_dB > 0) { // decrease gain - unsigned int index = am_fix_gain_table_index[vfo]; // current position we're at + unsigned int index = gain_table_index[vfo]; // current position we're at if (diff_dB >= 10) { // jump immediately to a new gain setting // this greatly speeds up initial gain reduction (but reduces noise/spike immunity) - - uint8_t lna_short = am_fix_gain_table[index].lna_short; - uint8_t lna = am_fix_gain_table[index].lna; - uint8_t mixer = am_fix_gain_table[index].mixer; - uint8_t pga = am_fix_gain_table[index].pga; - -// const int16_t desired_gain_dB = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga] - diff_dB; - const int16_t desired_gain_dB = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga] - diff_dB + 8; // get no closer than 8dB (bit of noise/spike immunity) - + const int16_t desired_gain_dB = (int16_t)gain_dB[index] - diff_dB + 8; // get no closer than 8dB (bit of noise/spike immunity) // scan the table to see what index to jump straight too while (index > 1) - { - index--; - - lna_short = am_fix_gain_table[index].lna_short; - lna = am_fix_gain_table[index].lna; - mixer = am_fix_gain_table[index].mixer; - pga = am_fix_gain_table[index].pga; - - { - const int16_t gain_dB = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga]; - if (gain_dB <= desired_gain_dB) - break; - } - } - - //index = (am_fix_gain_table_index[vfo] + index) / 2; // easy does it + if (gain_dB[--index] <= desired_gain_dB) + break; + + //index = (gain_table_index[vfo] + index) / 2; // easy does it } else { // incrementally reduce the gain .. taking it slow improves noise/spike immunity @@ -507,10 +430,10 @@ const uint8_t orig_pga = 6; // -3dB index = (index < 1) ? 1 : (index > max_index) ? max_index : index; - if (am_fix_gain_table_index[vfo] != index) + if (gain_table_index[vfo] != index) { - am_fix_gain_table_index[vfo] = index; - am_gain_hold_counter[vfo] = 30; // 300ms hold + gain_table_index[vfo] = index; + am_gain_hold_counter[vfo] = 30; // 300ms hold } } @@ -519,34 +442,30 @@ const uint8_t orig_pga = 6; // -3dB if (am_gain_hold_counter[vfo] == 0) { // hold has been released, we're free to increase gain - const unsigned int index = am_fix_gain_table_index[vfo] + 1; - am_fix_gain_table_index[vfo] = (index > max_index) ? max_index : index; // limit the gain + const unsigned int index = gain_table_index[vfo] + 1; + gain_table_index[vfo] = (index > max_index) ? max_index : index; // limit the gain } - if (am_fix_gain_table_index[vfo] == am_fix_gain_table_index_prev[vfo]) + if (gain_table_index[vfo] == gain_table_index_prev[vfo]) return; // no gain changes have been made #endif { // apply the new settings to the front end registers - const unsigned int index = am_fix_gain_table_index[vfo]; + const unsigned int index = gain_table_index[vfo]; - const uint8_t lna_short = am_fix_gain_table[index].lna_short; - const uint8_t lna = am_fix_gain_table[index].lna; - const uint8_t mixer = am_fix_gain_table[index].mixer; - const uint8_t pga = am_fix_gain_table[index].pga; - const int16_t gain_dB = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga]; + const t_gain_table gains = gain_table[index]; - BK4819_WriteRegister(BK4819_REG_13, (lna_short << 8) | (lna << 5) | (mixer << 3) | (pga << 0)); + BK4819_WriteRegister(BK4819_REG_13, ((uint16_t)gains.lna_short << 8) | ((uint16_t)gains.lna << 5) | ((uint16_t)gains.mixer << 3) | ((uint16_t)gains.pga << 0)); // offset the RSSI reading to the rest of the firmware to cancel out the gain adjustments we make // gain difference from original QS setting - rssi_db_gain_diff[vfo] = gain_dB - orig_dB_gain; + rssi_db_gain_diff[vfo] = (int16_t)gain_dB[index] - orig_dB_gain; // remember the new table index - am_fix_gain_table_index_prev[vfo] = index; + gain_table_index_prev[vfo] = index; { // save the corrected RSSI level const int16_t new_rssi = rssi - (rssi_db_gain_diff[vfo] * 2); @@ -576,14 +495,11 @@ const uint8_t orig_pga = 6; // -3dB void AM_fix_print_data(const int vfo, char *s) { // fetch current register settings - const unsigned int index = am_fix_gain_table_index[vfo]; - const uint8_t lna_short = am_fix_gain_table[index].lna_short; - const uint8_t lna = am_fix_gain_table[index].lna; - const uint8_t mixer = am_fix_gain_table[index].mixer; - const uint8_t pga = am_fix_gain_table[index].pga; - const int16_t gain_dB = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga]; if (s != NULL) - sprintf(s, "idx %2d %4ddB %3u", index, gain_dB, prev_rssi[vfo]); + { + const unsigned int index = gain_table_index[vfo]; + sprintf(s, "idx %2d %4ddB %3u", index, gain_dB[index], prev_rssi[vfo]); + } counter = 1; } diff --git a/app/app.c b/app/app.c index 36dd9a5..bdb90bf 100644 --- a/app/app.c +++ b/app/app.c @@ -1294,7 +1294,8 @@ void APP_CheckKeys(void) Key == KEY_SIDE1 || Key == KEY_UP || Key == KEY_DOWN || - Key == KEY_EXIT + Key == KEY_EXIT || + Key == KEY_MENU #ifdef ENABLE_MAIN_KEY_HOLD || Key <= KEY_9 // keys 0-9 can be held down to bypass pressing the F-Key #endif @@ -2048,33 +2049,20 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) } } - if (gScanState != SCAN_OFF && - Key != KEY_PTT && + if (Key != KEY_PTT && Key != KEY_UP && Key != KEY_DOWN && Key != KEY_EXIT && Key != KEY_SIDE1 && Key != KEY_SIDE2 && Key != KEY_STAR) - { // scanning - if (bKeyPressed && !bKeyHeld) - AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL); - return; - } - - if (gCssScanMode != CSS_SCAN_MODE_OFF && - Key != KEY_PTT && - Key != KEY_UP && - Key != KEY_DOWN && - Key != KEY_EXIT && - Key != KEY_SIDE1 && - Key != KEY_SIDE2 && - Key != KEY_STAR && - Key != KEY_MENU) - { // code scanning - if (bKeyPressed && !bKeyHeld) - AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL); - return; + { + if (gScanState != SCAN_OFF || gCssScanMode != CSS_SCAN_MODE_OFF) + { // frequency or CTCSS/DCS scanning + if (bKeyPressed && !bKeyHeld) + AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL); + return; + } } if (gPttWasPressed && Key == KEY_PTT) @@ -2099,7 +2087,7 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) } } - if (gWasFKeyPressed && Key > KEY_9 && Key != KEY_F && Key != KEY_STAR) + if (gWasFKeyPressed && Key > KEY_9 && Key != KEY_F && Key != KEY_STAR && Key != KEY_MENU) { gWasFKeyPressed = false; gUpdateStatus = true; diff --git a/app/main.c b/app/main.c index c191757..bd4a400 100644 --- a/app/main.c +++ b/app/main.c @@ -51,45 +51,14 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) #ifdef ENABLE_FMRADIO ACTION_FM(); #else - - - // TODO: do something useful with the key - - - #ifdef ENABLE_COPY_CHAN_VFO - { // copy channel to VFO - int channel = -1; - int vfo = -1; - if (IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE)) - { // VFO mode - if (IS_MR_CHANNEL(gRxVfo->CHANNEL_SAVE)) - { // other vfo is in channel mode - channel = gRxVfo->CHANNEL_SAVE; - vfo = gTxVfo->CHANNEL_SAVE; - } - } - else - if (IS_FREQ_CHANNEL((gRxVfo->CHANNEL_SAVE + 1) & 1)) - { // VFO mode - if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)) - { // other vfo is in channel mode - channel = gTxVfo->CHANNEL_SAVE; - vfo = gRxVfo->CHANNEL_SAVE; - } - } - - if (channel >= 0 && vfo >= 0) - { // copy the channel into the VFO - - gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - -// gRequestSaveVFO = true; -// gVfoConfigureMode = VFO_CONFIGURE_RELOAD; -// gRequestDisplayScreen = DISPLAY_MAIN; - } - } - #endif + + + + + // TODO: do something useful with the key + + @@ -124,7 +93,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) if (beep) gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - + break; case KEY_2: @@ -148,7 +117,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) if (beep) gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - + break; case KEY_3: @@ -188,7 +157,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) if (beep) gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; - + break; case KEY_4: @@ -201,7 +170,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) if (beep) gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - + break; case KEY_5: @@ -282,8 +251,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) if (bKeyPressed) { if (gScreenToDisplay == DISPLAY_MAIN) - { // we're going to go straight to the 0-9 key function - // without the need of the F-key + { if (gInputBoxIndex > 0) { // delete any inputted chars gInputBoxIndex = 0; @@ -300,7 +268,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) return; } - + #ifdef ENABLE_MAIN_KEY_HOLD if (bKeyPressed) { // key is pressed @@ -310,16 +278,17 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) #else if (!bKeyPressed) return; - + gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; #endif - + if (!gWasFKeyPressed) { // F-key wasn't pressed - uint8_t Vfo = gEeprom.TX_CHANNEL; + const uint8_t Vfo = gEeprom.TX_CHANNEL; gKeyInputCountdown = key_input_timeout_500ms; + INPUTBOX_Append(Key); gRequestDisplayScreen = DISPLAY_MAIN; @@ -490,7 +459,7 @@ static void MAIN_Key_EXIT(bool bKeyPressed, bool bKeyHeld) #ifdef ENABLE_FMRADIO ACTION_FM(); #endif - + return; } @@ -508,9 +477,78 @@ static void MAIN_Key_EXIT(bool bKeyPressed, bool bKeyHeld) } } -static void MAIN_Key_MENU(bool bKeyPressed, bool bKeyHeld) +static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) { - if (!bKeyHeld && bKeyPressed) + if (bKeyHeld) + { // key held down (long press) + + if (bKeyPressed) + { + if (gScreenToDisplay == DISPLAY_MAIN) + { + if (gInputBoxIndex > 0) + { // delete any inputted chars + gInputBoxIndex = 0; + gRequestDisplayScreen = DISPLAY_MAIN; + } + + gWasFKeyPressed = false; + gUpdateStatus = true; + + + + // TODO: long press M-key + + + + #ifdef ENABLE_COPY_CHAN_TO_VFO + { // copy channel to VFO + int channel = -1; + int vfo = -1; + //int selected = -1; + + if (IS_FREQ_CHANNEL(gRxVfo->CHANNEL_SAVE)) + { // VFO mode + if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)) + { // other VFO is in channel mode + channel = gTxVfo->CHANNEL_SAVE; + vfo = gRxVfo->CHANNEL_SAVE; + } + } + else + if (IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE)) + { // VFO mode + if (IS_MR_CHANNEL(gRxVfo->CHANNEL_SAVE)) + { // other VFO is in channel mode + channel = gRxVfo->CHANNEL_SAVE; + vfo = gTxVfo->CHANNEL_SAVE; + } + } + + if (channel >= 0 && vfo >= 0) + { // copy the channel into the VFO + + gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; + + + + //gEeprom.RX_CHANNEL = () & 1; // swap to the VFO + + +// gRequestSaveVFO = true; +// gVfoConfigureMode = VFO_CONFIGURE_RELOAD; +// gRequestDisplayScreen = DISPLAY_MAIN; + } + } + #endif + + } + } + + return; + } + + if (!bKeyPressed) { bool bFlag; diff --git a/firmware.bin b/firmware.bin index 76dc641..d8f8ebd 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index eeda92c..79e7def 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/functions.c b/functions.c index 4bf29fa..4aef501 100644 --- a/functions.c +++ b/functions.c @@ -151,6 +151,8 @@ void FUNCTION_Select(FUNCTION_Type_t Function) // if DTMF is enabled when TX'ing, it changes the TX audio filtering !! .. 1of11 BK4819_DisableDTMF(); + gDTMF_ReceivedSaved[0] = 0; + #if defined(ENABLE_FMRADIO) if (gFmRadioMode) BK1080_Init(0, false); diff --git a/ui/main.c b/ui/main.c index c88a0e5..1882ea3 100644 --- a/ui/main.c +++ b/ui/main.c @@ -36,33 +36,57 @@ #include "ui/ui.h" #ifdef ENABLE_AUDIO_BAR + + unsigned int sqrt16(unsigned int value) + { // return square root of 'value' + unsigned int shift = 15; + unsigned int bit = 1u << shift; + unsigned int sqrti = 0; + do { + const unsigned int temp = ((sqrti << 1) | bit) << shift--; + if (value >= temp) + { + value -= temp; + sqrti |= bit; + } + } while (bit >>= 1); + return sqrti; + } + void UI_DisplayAudioBar(void) { if (gSetting_mic_bar) { const unsigned int line = 3; const unsigned int lcd_width = sizeof(gFrameBuffer[line]) - 2; - + #if 1 // TX audio level - + if (gCurrentFunction != FUNCTION_TRANSMIT) return; - - // TODO: logify this to make the bar visible with the mostly small value - - - const uint16_t voice_amp = BK4819_GetVoiceAmplitudeOut(); // 15:0 - const unsigned int max = 32767; - const unsigned int level = (((uint32_t)voice_amp * lcd_width) + (max / 2)) / max; // with rounding + + const unsigned int voice_amp = BK4819_GetVoiceAmplitudeOut(); // 15:0 + +// const unsigned int max = 65535; +// const unsigned int level = ((voice_amp * lcd_width) + (max / 2)) / max; // with rounding +// const unsigned int len = (level <= lcd_width) ? level : lcd_width; + + // make non-linear to make more sensitive at low values + const unsigned int level = voice_amp * 8; + const unsigned int sqrt_level = sqrt16((level < 65535) ? level : 65535); + const unsigned int len = (sqrt_level <= lcd_width) ? sqrt_level : lcd_width; + #else // TX/RX AF input level (dB) - const uint8_t af_tx_rx = BK4819_GetAfTxRx(); // 6:0 - const unsigned int max = 63; - const unsigned int level = (((uint16_t)af_tx_rx * lcd_width) + (max / 2)) / max; // with rounding + + const uint8_t af_tx_rx = BK4819_GetAfTxRx(); // 6:0 + const unsigned int max = 63; + const unsigned int level = (((uint16_t)af_tx_rx * lcd_width) + (max / 2)) / max; // with rounding + const unsigned int len = (level <= lcd_width) ? level : lcd_width; + #endif - - const unsigned int len = (level <= lcd_width) ? level : lcd_width; + uint8_t *pLine = gFrameBuffer[line]; memset(pLine, 0, lcd_width); #if 0 @@ -72,7 +96,8 @@ for (unsigned int i = 0; i < len; i += 2) pLine[i] = 0x3e; #endif - + + if (gCurrentFunction == FUNCTION_TRANSMIT) ST7565_BlitFullScreen(); } @@ -343,7 +368,7 @@ void UI_DisplayMain(void) #else UI_PrintStringSmall(String, 32 + 4, 0, Line); #endif - + // show the channel frequency below the channel number/name sprintf(String, "%03u.%05u", frequency / 100000, frequency % 100000); UI_PrintStringSmall(String, 32 + 4, 0, Line + 1); @@ -503,7 +528,7 @@ void UI_DisplayMain(void) case FUNCTION_BAND_SCOPE: case FUNCTION_POWER_SAVE: break; - + case FUNCTION_FOREGROUND: break; @@ -520,9 +545,10 @@ void UI_DisplayMain(void) { #ifdef ENABLE_AUDIO_BAR UI_DisplayAudioBar(); - - if (!gSetting_mic_bar) + +// if (!gSetting_mic_bar) #endif + if (gCurrentFunction != FUNCTION_TRANSMIT) { if (gSetting_live_DTMF_decoder && gDTMF_ReceivedSaved[0] >= 32) { // show live DTMF decode