2023-07-03 23:38:00 +00:00
|
|
|
#pragma once
|
|
|
|
#include "system.hpp"
|
|
|
|
#include "uv_k5_display.hpp"
|
2023-07-10 00:03:12 +00:00
|
|
|
#include "radio.hpp"
|
2023-07-03 23:38:00 +00:00
|
|
|
|
2023-08-01 15:54:30 +00:00
|
|
|
template <Radio::CBK4819 &RadioDriver>
|
2023-07-17 17:42:15 +00:00
|
|
|
class CSpectrum
|
2023-07-03 23:38:00 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto StepSize = 0xFFFF / TUV_K5Display::SizeX;
|
|
|
|
static constexpr auto StepSizeFreq = 10'000;
|
2023-07-10 00:03:12 +00:00
|
|
|
|
|
|
|
enum eState : unsigned char
|
|
|
|
{
|
|
|
|
Init,
|
|
|
|
Idle,
|
|
|
|
RxPending,
|
|
|
|
SendData,
|
|
|
|
RxDone,
|
|
|
|
Exit,
|
|
|
|
};
|
|
|
|
|
2023-07-03 23:38:00 +00:00
|
|
|
CSpectrum()
|
2023-08-01 15:54:30 +00:00
|
|
|
: DisplayBuff(gDisplayBuffer), FontSmallNr(gSmallDigs), Display(DisplayBuff), State(eState::Init), u8RxCnt(0){};
|
2023-07-03 23:38:00 +00:00
|
|
|
|
|
|
|
void Handle()
|
|
|
|
{
|
2023-07-08 10:23:49 +00:00
|
|
|
if (!(GPIOC->DATA & 0b1))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-07-03 23:38:00 +00:00
|
|
|
|
2023-07-12 00:10:45 +00:00
|
|
|
switch (State)
|
2023-07-03 23:38:00 +00:00
|
|
|
{
|
2023-07-12 00:10:45 +00:00
|
|
|
case eState::Init:
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2023-08-01 15:54:30 +00:00
|
|
|
DelayMs(600);
|
2023-07-12 00:10:45 +00:00
|
|
|
//memset(U8Buff, 0, sizeof(U8Buff));
|
2023-07-17 17:42:15 +00:00
|
|
|
RadioDriver.RecieveAsyncAirCopyMode(U8Buff, sizeof(U8Buff), Radio::CallbackRxDoneType(this, &CSpectrum::RxDoneHandler));
|
2023-07-12 00:10:45 +00:00
|
|
|
State = eState::RxPending;
|
|
|
|
// while(State == eState::RxPending)
|
|
|
|
// {
|
|
|
|
// RadioDriver.InterruptHandler();
|
2023-08-01 15:54:30 +00:00
|
|
|
// // if(PollKeyboard() != 0xFF)
|
2023-07-12 00:10:45 +00:00
|
|
|
// // {
|
|
|
|
// // break;
|
|
|
|
// // }
|
|
|
|
// }
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2023-07-03 23:38:00 +00:00
|
|
|
|
2023-07-12 00:10:45 +00:00
|
|
|
case eState::RxDone:
|
|
|
|
{
|
|
|
|
char kupa[20];
|
|
|
|
U8Buff[10] = 0;
|
|
|
|
DisplayBuff.ClearAll();
|
2023-08-01 15:54:30 +00:00
|
|
|
FormatString(kupa, "RX DONE %u", u8RxCnt);
|
|
|
|
PrintTextOnScreen(kupa, 0, 127, 0, 8, 0);
|
|
|
|
FormatString(kupa, "LEN: %i", RadioDriver.u16RxDataLen);
|
|
|
|
PrintTextOnScreen(kupa, 0, 127, 2, 8, 0);
|
|
|
|
FormatString(kupa, "S: %s", U8Buff);
|
|
|
|
PrintTextOnScreen(kupa, 0, 127, 4, 8, 0);
|
|
|
|
FlushFramebufferToScreen();
|
2023-07-12 00:10:45 +00:00
|
|
|
|
|
|
|
static unsigned int u32Cnt = 1;
|
|
|
|
if(!(u32Cnt++%8))
|
2023-07-10 00:03:12 +00:00
|
|
|
{
|
|
|
|
u8RxCnt++;
|
|
|
|
State = eState::Init;
|
|
|
|
}
|
2023-07-08 10:23:49 +00:00
|
|
|
|
2023-08-01 15:54:30 +00:00
|
|
|
// WriteSerialData((unsigned char *)"RX packet, hex: ", 17);
|
2023-07-12 00:10:45 +00:00
|
|
|
// for (unsigned int i = 0; i < sizeof(U8Buff); i++)
|
|
|
|
// {
|
2023-08-01 15:54:30 +00:00
|
|
|
// FormatString(kupa, "%02X", U8Buff[i]);
|
|
|
|
// WriteSerialData((unsigned char *)kupa, 1);
|
2023-07-12 00:10:45 +00:00
|
|
|
// }
|
2023-08-01 15:54:30 +00:00
|
|
|
// WriteSerialData((unsigned char *)"\n", 1);
|
2023-07-12 00:10:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eState::RxPending:
|
|
|
|
{
|
|
|
|
|
2023-08-01 15:54:30 +00:00
|
|
|
//AirCopyFskSetup();
|
2023-07-12 00:10:45 +00:00
|
|
|
char kupa[20];
|
|
|
|
DisplayBuff.ClearAll();
|
2023-08-01 15:54:30 +00:00
|
|
|
FormatString(kupa, "Rx: %u kHz", IntDivide(RadioDriver.GetFrequency(), 100));
|
|
|
|
PrintTextOnScreen(kupa, 0, 127, 0, 8, 0);
|
|
|
|
FormatString(kupa, "0x3F: 0x%04X", BK4819Read(0x3F));
|
|
|
|
PrintTextOnScreen(kupa, 0, 127, 2, 8, 0);
|
|
|
|
FormatString(kupa, "len: %i", BK4819Read(0x5D) >> 8);
|
|
|
|
PrintTextOnScreen(kupa, 0, 127, 4, 8, 0);
|
|
|
|
FlushFramebufferToScreen();
|
2023-07-12 00:10:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eState::SendData:
|
|
|
|
{
|
|
|
|
|
|
|
|
static char C8TxStr[20] __attribute__((aligned(4)));
|
|
|
|
char kupa[20];
|
|
|
|
static unsigned char u8TxCnt = 0;
|
|
|
|
static unsigned int u32Cnt = 1;
|
|
|
|
if(!(u32Cnt++%8))
|
2023-07-10 00:03:12 +00:00
|
|
|
{
|
2023-07-12 00:10:45 +00:00
|
|
|
u8TxCnt++;
|
2023-08-01 15:54:30 +00:00
|
|
|
FormatString((char *)C8TxStr, "packet %i", u8TxCnt);
|
2023-07-12 00:10:45 +00:00
|
|
|
RadioDriver.SendSyncAirCopyMode72((unsigned char *)C8TxStr);
|
2023-07-10 00:03:12 +00:00
|
|
|
}
|
2023-07-08 10:23:49 +00:00
|
|
|
|
2023-07-12 00:10:45 +00:00
|
|
|
DisplayBuff.ClearAll();
|
2023-08-01 15:54:30 +00:00
|
|
|
FormatString(kupa, "TX: %u kHz", IntDivide(RadioDriver.GetFrequency(), 100));
|
|
|
|
PrintTextOnScreen(kupa, 0, 127, 0, 8, 0);
|
|
|
|
FormatString(kupa, "Irq: 0x%04X", RadioDriver.GetIrqReg());
|
|
|
|
PrintTextOnScreen(kupa, 0, 127, 2, 8, 0);
|
|
|
|
FormatString(kupa, "S: %s", C8TxStr);
|
|
|
|
PrintTextOnScreen(kupa, 0, 127, 4, 8, 0);
|
|
|
|
FlushFramebufferToScreen();
|
2023-07-12 00:10:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
2023-07-10 00:03:12 +00:00
|
|
|
}
|
2023-07-03 23:38:00 +00:00
|
|
|
}
|
|
|
|
|
2023-07-17 17:42:15 +00:00
|
|
|
void RxDoneHandler(unsigned char u8DataLen, bool bCrcOk)
|
2023-07-03 23:38:00 +00:00
|
|
|
{
|
2023-07-10 00:03:12 +00:00
|
|
|
State = eState::RxDone;
|
2023-07-03 23:38:00 +00:00
|
|
|
}
|
|
|
|
|
2023-07-10 00:03:12 +00:00
|
|
|
private:
|
2023-07-03 23:38:00 +00:00
|
|
|
TUV_K5Display DisplayBuff;
|
|
|
|
const TUV_K5SmallNumbers FontSmallNr;
|
|
|
|
CDisplay<const TUV_K5Display> Display;
|
2023-07-10 00:03:12 +00:00
|
|
|
eState State;
|
2023-07-12 00:10:45 +00:00
|
|
|
unsigned char U8Buff[72];
|
2023-07-10 00:03:12 +00:00
|
|
|
unsigned char u8RxCnt;
|
2023-08-01 15:54:30 +00:00
|
|
|
};
|