mirror of
https://github.com/phdlee/uvk5cec
synced 2024-11-23 17:19:50 +00:00
Add LiveSeek and Mhz Keypad function
This commit is contained in:
parent
eb16d92727
commit
29b97660e7
273
ceccommon.c
Normal file
273
ceccommon.c
Normal file
@ -0,0 +1,273 @@
|
|||||||
|
/* Copyright 2023 KD8CEC
|
||||||
|
* https://github.com/kd8cec
|
||||||
|
*
|
||||||
|
* 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 "ceccommon.h"
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t LOW_VALUE;
|
||||||
|
uint8_t HIGH_VALUE;
|
||||||
|
} TADC_RANGE;
|
||||||
|
|
||||||
|
uint8_t CW_TONE = 70; //*10 Hz, because BK4819 using 10Hz Step, as YAESU : PITCH, ICOM,KENWOOD : TONE
|
||||||
|
uint8_t CW_SPEED = 10; //WPM 5 ~ 50
|
||||||
|
uint8_t CW_KEYTYPE = 0;
|
||||||
|
uint8_t CEC_LiveSeekMode = 0; //0:NONE, 1:LIVE, 2:LIVE+1, 3:LIVE+2
|
||||||
|
TADC_RANGE CW_KEY_ADC[3];
|
||||||
|
|
||||||
|
//================================= For Reduce Use Memory ====================
|
||||||
|
//gMR_ChannelAttributes[207]; -> function
|
||||||
|
//resize to 7 byte and Move to ceccommon.c
|
||||||
|
uint16_t CEC_GetRssi()
|
||||||
|
{
|
||||||
|
int _wait_count = 0;
|
||||||
|
while (((BK4819_ReadRegister(0x63) & 0b11111111) >= 255 ) && _wait_count++ < 100)
|
||||||
|
SYSTICK_DelayUs(100);
|
||||||
|
|
||||||
|
return BK4819_GetRSSI();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisplayIntLog(char* displayMessage, int _logInt1, int _logInt2)
|
||||||
|
{
|
||||||
|
uint8_t tmpBuff[32];
|
||||||
|
|
||||||
|
memset(gStatusLine, 0, sizeof(gStatusLine));
|
||||||
|
memset(gFrameBuffer, 0, sizeof(gFrameBuffer));
|
||||||
|
|
||||||
|
sprintf(tmpBuff, "%s : %d", displayMessage, _logInt1);
|
||||||
|
UI_PrintString(tmpBuff, 2, 127, 0, 8);
|
||||||
|
|
||||||
|
sprintf(tmpBuff, "1: %u", _logInt1);
|
||||||
|
UI_PrintString(tmpBuff, 2, 127, 2, 8);
|
||||||
|
|
||||||
|
sprintf(tmpBuff, "2: %u", _logInt2);
|
||||||
|
UI_PrintString(tmpBuff, 2, 127, 4, 8);
|
||||||
|
|
||||||
|
ST7565_BlitFullScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------
|
||||||
|
//=================== Variables shared and used in various places , To Rduce memory usage
|
||||||
|
uint8_t CommBuff[COMBUFF_LENGTH]; //for Common Use for
|
||||||
|
uint8_t CommBuffUsingType = 0;
|
||||||
|
uint32_t CommBuffLastUseTime = 0; //10milisec using millis10() function
|
||||||
|
uint8_t CommValue1 = 0; //temp varaible
|
||||||
|
uint8_t CommValue2 = 0;
|
||||||
|
uint8_t CommValue3 = 0;
|
||||||
|
uint8_t strBuff[32]; //For sprintf
|
||||||
|
//-----------------------------------------------------------------------------------------
|
||||||
|
//=================== End of Common Variables =============================================
|
||||||
|
|
||||||
|
uint8_t lastSeekDirection = 0;
|
||||||
|
uint32_t rssiStartFreq = 0;
|
||||||
|
uint32_t addRssiCount = 0;
|
||||||
|
|
||||||
|
|
||||||
|
void UI_PrintStringSmallLeft(const char *pString, uint8_t Start, uint8_t End, uint8_t Line)
|
||||||
|
{
|
||||||
|
const size_t Length = strlen(pString);
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
const unsigned int char_width = ARRAY_SIZE(gFontSmall[0]);
|
||||||
|
const unsigned int char_spacing = char_width + 1;
|
||||||
|
|
||||||
|
uint8_t *pFb = gFrameBuffer[Line] + Start;
|
||||||
|
for (i = 0; i < Length; i++)
|
||||||
|
{
|
||||||
|
if (pString[i] > ' ')
|
||||||
|
{
|
||||||
|
const unsigned int index = (unsigned int)pString[i] - ' ' - 1;
|
||||||
|
if (index < ARRAY_SIZE(gFontSmall))
|
||||||
|
memmove(pFb + (i * char_spacing) + 1, &gFontSmall[index], char_width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
void DrawFrequencySmall(uint32_t _frequency, int _startX, int _Length, int _lineNumber)
|
||||||
|
{
|
||||||
|
sprintf(strBuff, "%3u.%03u", _frequency / 100000, (_frequency / 100) % 1000);
|
||||||
|
UI_PrintStringSmallLeft(strBuff, _startX, _startX + _Length, _lineNumber);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
void DrawFrequencySmall(uint32_t _frequency, int _startX, int _Length, int _lineNumber)
|
||||||
|
{
|
||||||
|
// 58096 48 3284 61428 eff4 firmware
|
||||||
|
// 58036 48 3284 61368 efb8 firmware
|
||||||
|
//sprintf(strBuff, "%1u.%03u", (_frequency / 100000) % 10, (_frequency / 100) % 1000);
|
||||||
|
sprintf(strBuff, "%3u.%03u", _frequency / 100000, (_frequency / 100) % 1000);
|
||||||
|
//UI_PrintStringSmallLeft(strBuff, _startX, _startX + _Length, _lineNumber);
|
||||||
|
memset(gFrameBuffer[_lineNumber], 0, 128);
|
||||||
|
UI_PrintStringSmallNormal(strBuff, _startX, 0, _lineNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawCommBuffToSpectrum(void)
|
||||||
|
{
|
||||||
|
//Low Value
|
||||||
|
int _lowValue = 999;
|
||||||
|
int drawYPosition = 53;
|
||||||
|
|
||||||
|
if (CEC_LiveSeekMode < LIVESEEK_RCV_SPECTRUM1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
if (addRssiCount < 3)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int i = 0; i < COMBUFF_LENGTH; i++)
|
||||||
|
{
|
||||||
|
if (CommBuff[i] > 0 && _lowValue > CommBuff[i])
|
||||||
|
_lowValue = CommBuff[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
//DrawFrequencyKhzSmall(gTxVfo->freq_config_RX.Frequency, lastSeekDirection == 12 ? 100 : 0, 55, 3);
|
||||||
|
|
||||||
|
//DrawFrequencyKhzSmall(gTxVfo->freq_config_RX.Frequency + (gTxVfo->StepFrequency * 64) * (lastSeekDirection == 12 ? -1 : 1),
|
||||||
|
// 57, 55, 3);
|
||||||
|
|
||||||
|
//DrawFrequencyKhzSmall(gTxVfo->freq_config_RX.Frequency + (gTxVfo->StepFrequency * 127) * (lastSeekDirection == 12 ? -1 : 1),
|
||||||
|
// lastSeekDirection == 12 ? 0 : 100, 55, 3);
|
||||||
|
memset(gFrameBuffer[6], 0, 128); //Clear Last Line
|
||||||
|
|
||||||
|
for (int i = 0; i < COMBUFF_LENGTH; i++)
|
||||||
|
{
|
||||||
|
int _drawXPosition = (lastSeekDirection == 10 ? 127 - i : i);
|
||||||
|
int _drawYValue = CommBuff[i] - _lowValue;
|
||||||
|
if (_drawYValue > 50)
|
||||||
|
_drawYValue = 50;
|
||||||
|
else if (_drawYValue < 0)
|
||||||
|
_drawYValue = 0;
|
||||||
|
UI_DrawLineBuffer(gFrameBuffer, _drawXPosition, drawYPosition, _drawXPosition, (drawYPosition - _drawYValue), true);
|
||||||
|
}
|
||||||
|
uint32_t _drawFreq = rssiStartFreq;
|
||||||
|
int _drawTextPosition = 0;
|
||||||
|
//int _drawTextPosition = lastSeekDirection == 12 ? 127 - addRssiCount: 0 + addRssiCount;
|
||||||
|
if (lastSeekDirection == 12)
|
||||||
|
{
|
||||||
|
_drawTextPosition = 127 - addRssiCount;
|
||||||
|
if (_drawTextPosition > 73)
|
||||||
|
_drawTextPosition = 73;
|
||||||
|
else if (_drawTextPosition < 0)
|
||||||
|
{
|
||||||
|
_drawTextPosition = 0;
|
||||||
|
_drawFreq = gTxVfo->freq_config_RX.Frequency - (gTxVfo->StepFrequency * 127);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_drawTextPosition = addRssiCount - 55;
|
||||||
|
|
||||||
|
if (_drawTextPosition < 0)
|
||||||
|
_drawTextPosition = 0;
|
||||||
|
else if (_drawTextPosition > 73)
|
||||||
|
{
|
||||||
|
_drawTextPosition = 73;
|
||||||
|
_drawFreq = gTxVfo->freq_config_RX.Frequency + (gTxVfo->StepFrequency * 127);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawFrequencySmall(_drawFreq, _drawTextPosition, 55, 3);
|
||||||
|
ST7565_BlitFullScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
//500msec interval execute function
|
||||||
|
void CEC_TimeSlice500ms(void)
|
||||||
|
{
|
||||||
|
if (CommBuffUsingType == COMBUFF_USE_SEEK_RSSI && (millis10() -CommBuffLastUseTime > 70))
|
||||||
|
{
|
||||||
|
//Clear
|
||||||
|
CommBuffUsingType = COMBUFF_USE_SEEK_NONE;
|
||||||
|
if (gScreenToDisplay == DISPLAY_MAIN)
|
||||||
|
{
|
||||||
|
gMonitor = false;
|
||||||
|
|
||||||
|
if (addRssiCount > 3)
|
||||||
|
{
|
||||||
|
if (CommValue1 != FUNCTION_MONITOR)
|
||||||
|
RADIO_SetupRegisters(true);
|
||||||
|
|
||||||
|
UI_DisplayMain();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Frequency Apply Receive Mode
|
||||||
|
//DEFAULT
|
||||||
|
//_applyOption 0 : No Delaytime
|
||||||
|
#define STOP_RSSI_LIMIT 50
|
||||||
|
#define STOP_RSSI_TIME 500
|
||||||
|
|
||||||
|
void CEC_ApplyChangeRXFreq(int _applyOption)
|
||||||
|
{
|
||||||
|
if (CEC_LiveSeekMode == LIVESEEK_NONE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
BK4819_SetFrequency(gTxVfo->freq_config_RX.Frequency);
|
||||||
|
BK4819_RX_TurnOn();
|
||||||
|
|
||||||
|
//BK4819_SetFrequency(frequency);
|
||||||
|
//APP_StartListeningLive(FUNCTION_MONITOR, false);
|
||||||
|
//if (gEeprom.SQUELCH_LEVEL == 0)
|
||||||
|
// AUDIO_AudioPathOn();
|
||||||
|
int32_t tmpRssi = CEC_GetRssi() / 3;
|
||||||
|
|
||||||
|
tmpRssi = (tmpRssi < 0 ? 0 : tmpRssi);
|
||||||
|
|
||||||
|
if (_applyOption >= 10 && _applyOption <= 12) //Save RSSI Result, 10 : Direction -1, 12 : Direction : 1
|
||||||
|
{
|
||||||
|
CommBuffUsingType = COMBUFF_USE_SEEK_RSSI;
|
||||||
|
if (lastSeekDirection != _applyOption || (millis10() -CommBuffLastUseTime > 70))
|
||||||
|
{
|
||||||
|
memset(CommBuff, 0, sizeof(CommBuff));
|
||||||
|
rssiStartFreq = gTxVfo->freq_config_RX.Frequency;
|
||||||
|
addRssiCount = 0;
|
||||||
|
CommValue1 = gCurrentFunction;
|
||||||
|
}
|
||||||
|
|
||||||
|
addRssiCount++;
|
||||||
|
lastSeekDirection = _applyOption;
|
||||||
|
|
||||||
|
int _insertIndex = COMBUFF_LENGTH -1;
|
||||||
|
if (addRssiCount < COMBUFF_LENGTH /2)
|
||||||
|
{
|
||||||
|
_insertIndex = COMBUFF_LENGTH /2 + addRssiCount;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//for (int i = 0; i < COMBUFF_LENGTH -1; i++)
|
||||||
|
// CommBuff[i] = CommBuff[i + 1];
|
||||||
|
memmove(&CommBuff[0], &CommBuff[1], sizeof(CommBuff) - 1);
|
||||||
|
}
|
||||||
|
CommBuff[_insertIndex] = tmpRssi > 255 ? 255 : tmpRssi;
|
||||||
|
CommBuffLastUseTime = millis10();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (gEeprom.SQUELCH_LEVEL == 0)
|
||||||
|
{
|
||||||
|
if (addRssiCount > 2)
|
||||||
|
APP_StartListening(FUNCTION_MONITOR);
|
||||||
|
//delay(200);
|
||||||
|
}
|
||||||
|
else if (tmpRssi > STOP_RSSI_LIMIT)
|
||||||
|
{
|
||||||
|
APP_StartListening(FUNCTION_MONITOR);
|
||||||
|
delay(STOP_RSSI_TIME);
|
||||||
|
RADIO_SetupRegisters(true);
|
||||||
|
}
|
||||||
|
}
|
89
ceccommon.h
Normal file
89
ceccommon.h
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/* Copyright 2023 KD8CEC
|
||||||
|
* https://github.com/kd8cec
|
||||||
|
*
|
||||||
|
* This is the source code used to minimize memory usage.
|
||||||
|
* Global variables among the source code written by KD8CEC will be shared and used.
|
||||||
|
* Most source code written by KD8CEC will INCLUDE this file.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CEC_COMMON_H
|
||||||
|
#define CEC_COMMON_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "driver\bk4819.h"
|
||||||
|
#include "driver\keyboard.h"
|
||||||
|
#include "audio.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "external/printf/printf.h"
|
||||||
|
//#include "gpsinfo.h"
|
||||||
|
#include "driver\eeprom.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "radio.h"
|
||||||
|
#include "driver\system.h"
|
||||||
|
#include "driver\st7565.h"
|
||||||
|
#include "settings.h"
|
||||||
|
#include "driver\systick.h"
|
||||||
|
#include "ui\helper.h"
|
||||||
|
#include "ui\ui.h"
|
||||||
|
#include "ui\main.h"
|
||||||
|
#include "font.h"
|
||||||
|
#include "functions.h"
|
||||||
|
#include "app\app.h"
|
||||||
|
|
||||||
|
#define _MAX_READ_CH_ATTRIBUTES 7
|
||||||
|
#define COMBUFF_USE_SEEK_RSSI 01
|
||||||
|
#define COMBUFF_USE_SEEK_NONE 99
|
||||||
|
#define COMBUFF_LENGTH 128
|
||||||
|
#define CEC_EEPROM_START1 0x1D50 //0x1D50 ~ 0x1DFF
|
||||||
|
#define CEC_EEPROM_START2 0x1D00 //0x1D00 ~ 0x1D4F
|
||||||
|
#define CEC_EEPROM_START3 0x1BD0 //0x1BD0 ~ 0x1BFF (48Byte)
|
||||||
|
#define CEC_EEPROM_START4 0x1F90 //0x1F90 ~ 0x1FFF (96Byte)
|
||||||
|
#define CEC_EEPROM_DATA1 0x0F5B //5 0x0F5A ~ 0x0F5F (6Byte, but 0x0F5A is buffer with Channel Name) + (index * 16) index Count = 20, 5byte * 20 = 100byte
|
||||||
|
#define CEC_EEPROM_DATA2 0x1E0A //7 0x1E0A ~ 0x1E0A (7byte) + (index * 16) index Count = 12, 7byte * 12 = 84byte
|
||||||
|
#define EEPROM_WELCOMESTRING1 0x0EB0 //16Byte
|
||||||
|
#define EEPROM_WELCOMESTRING2 0x0EC0 //16Byte
|
||||||
|
#define EEPROM_CONFIGSTART
|
||||||
|
#define CEC_EEPROM_CALLSIGN EEPROM_WELCOMESTRING1 //CALLSIGN SPACE GRID, ex)KD8CEC EM37, KD8CEC/TEST EM37
|
||||||
|
#define CEC_EEPROM USERNAME EEPROM_WELCOMESTRING1 //NAME STATUS using APRS
|
||||||
|
|
||||||
|
#define CW_LR_MODE + //ICOM STYLE, - : YAESU STYLE (uBITX : CWL, CWR)
|
||||||
|
//extern ChannelAttributes_t gMR_ChannelAttributes[_MAX_READ_CH_ATTRIBUTES];
|
||||||
|
extern uint8_t CommBuff[COMBUFF_LENGTH]; //for Common Use for
|
||||||
|
extern uint8_t CommBuffUsingType;
|
||||||
|
extern uint32_t CommBuffLastUseTime;
|
||||||
|
|
||||||
|
extern uint8_t CW_TONE; //Hz Default 700Hz
|
||||||
|
extern uint8_t CW_SPEED;
|
||||||
|
extern uint8_t CW_KEYTYPE;
|
||||||
|
extern uint8_t CEC_LiveSeekMode; //0:NONE, 1:LIVE, 2:LIVE+1, 3:LIVE+2
|
||||||
|
#define LIVESEEK_NONE 0 //NONE
|
||||||
|
#define LIVESEEK_RCV 1 //SPEAKER ONLY
|
||||||
|
#define LIVESEEK_RCV_SPECTRUM1 2 //SPECTRUM SMALL
|
||||||
|
#define LIVESEEK_RCV_SPECTRUM2 3 //SPECTRUM LARGE (Not Use, Reserve)
|
||||||
|
|
||||||
|
#define GET_FREQ_OFFSET(__rxmode__) ( CW_LR_MODE (__rxmode__ == MODULATION_CW ||__rxmode__ == MODULATION_CWN ? (CWTone) : 0))
|
||||||
|
#define delay(delayTime) SYSTEM_DelayMs(delayTime)
|
||||||
|
|
||||||
|
ChannelAttributes_t MR_ChannelAttributes(int _channelIndex);
|
||||||
|
void SetMR_ChannelAttributes(int channel, ChannelAttributes_t att);
|
||||||
|
void CEC_ApplyChangeRXFreq(int _applyOption);
|
||||||
|
void CEC_TimeSlice500ms(void);
|
||||||
|
void DrawCommBuffToSpectrum(void);
|
||||||
|
uint32_t millis10(); //scheduler.c
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user