Spectrum refactor

This commit is contained in:
Krzysiek Egzmont 2023-11-22 23:43:39 +01:00
parent 9a3249a667
commit a0d052b68b
3 changed files with 44 additions and 63 deletions

View File

@ -17,6 +17,7 @@
#include "app/spectrum.h"
#include "driver/backlight.h"
#include "audio.h"
#include "ui/helper.h"
struct FrequencyBandInfo {
uint32_t lower;
@ -125,21 +126,13 @@ static void SetRegMenuValue(uint8_t st, bool add) {
// GUI functions
static void PutPixel(uint8_t x, uint8_t y, bool fill) {
if (fill) {
gFrameBuffer[y >> 3][x] |= 1 << (y & 7);
} else {
gFrameBuffer[y >> 3][x] &= ~(1 << (y & 7));
}
UI_DrawPixelBuffer(gFrameBuffer, x, y, fill);
}
static void PutPixelStatus(uint8_t x, uint8_t y, bool fill) {
if (fill) {
gStatusLine[x] |= 1 << y;
} else {
gStatusLine[x] &= ~(1 << y);
}
UI_DrawPixelBuffer(&gStatusLine, x, y, fill);
}
static void DrawHLine(int sy, int ey, int nx, bool fill) {
static void DrawVLine(int sy, int ey, int nx, bool fill) {
for (int i = sy; i <= ey; i++) {
if (i < 56 && nx < 128) {
PutPixel(nx, i, fill);
@ -606,7 +599,7 @@ static void DrawSpectrum() {
for (uint8_t x = 0; x < 128; ++x) {
uint16_t rssi = rssiHistory[x >> settings.stepsCount];
if (rssi != RSSI_MAX_VALUE) {
DrawHLine(Rssi2Y(rssi), DrawingEndY, x, true);
DrawVLine(Rssi2Y(rssi), DrawingEndY, x, true);
}
}
}
@ -620,36 +613,28 @@ static void DrawStatus() {
#endif
GUI_DisplaySmallest(String, 0, 1, true, true);
for (int i = 0; i < 4; i++) {
BOARD_ADC_GetBatteryInfo(&gBatteryVoltages[i], &gBatteryCurrent);
}
BOARD_ADC_GetBatteryInfo(&gBatteryVoltages[gBatteryCheckCounter++ % 4], &gBatteryCurrent);
uint16_t Voltage;
uint8_t v = 0;
Voltage = (gBatteryVoltages[0] + gBatteryVoltages[1] + gBatteryVoltages[2] +
uint16_t voltage = (gBatteryVoltages[0] + gBatteryVoltages[1] + gBatteryVoltages[2] +
gBatteryVoltages[3]) /
4;
4 * 760 / gBatteryCalibration[3];
for(uint8_t i = 5; i > 0; i--) {
if(Voltage > gBatteryCalibration[i - 1]) {
v = i;
break;
}
}
unsigned perc = BATTERY_VoltsToPercent(voltage);
gStatusLine[127] = 0b01111110;
for (int i = 126; i >= 116; i--) {
gStatusLine[i] = 0b01000010;
// sprintf(String, "%d %d", voltage, perc);
// GUI_DisplaySmallest(String, 48, 1, true, true);
gStatusLine[116] = 0b00011100;
gStatusLine[117] = 0b00111110;
for (int i = 118; i <= 126; i++) {
gStatusLine[i] = 0b00100010;
}
v <<= 1;
for (int i = 125; i >= 116; i--) {
if (126 - i <= v) {
gStatusLine[i + 2] = 0b01111110;
for (unsigned i = 127; i >= 118; i--) {
if (127 - i <= (perc+5)*9/100) {
gStatusLine[i] = 0b00111110;
}
}
gStatusLine[117] = 0b01111110;
gStatusLine[116] = 0b00011000;
}
static void DrawF(uint32_t f) {
@ -712,19 +697,13 @@ static void DrawTicks() {
// center
if (IsCenterMode()) {
gFrameBuffer[5][62] = 0x80;
gFrameBuffer[5][63] = 0x80;
memset(gFrameBuffer[5] + 62, 0x80, 5);
gFrameBuffer[5][64] = 0xff;
gFrameBuffer[5][65] = 0x80;
gFrameBuffer[5][66] = 0x80;
} else {
memset(gFrameBuffer[5] + 1, 0x80, 3);
memset(gFrameBuffer[5] + 124, 0x80, 3);
gFrameBuffer[5][0] = 0xff;
gFrameBuffer[5][1] = 0x80;
gFrameBuffer[5][2] = 0x80;
gFrameBuffer[5][3] = 0x80;
gFrameBuffer[5][124] = 0x80;
gFrameBuffer[5][125] = 0x80;
gFrameBuffer[5][126] = 0x80;
gFrameBuffer[5][127] = 0xff;
}
}

View File

@ -180,10 +180,12 @@ void UI_DisplayFrequency(const char *string, uint8_t X, uint8_t Y, bool center)
}
}
void UI_DrawPixel(uint8_t x, uint8_t y, bool black)
void UI_DrawPixelBuffer(uint8_t (*buffer)[128], uint8_t x, uint8_t y, bool black)
{
gFrameBuffer[y/8][x] &= ~(1 << (y%8));
gFrameBuffer[y/8][x] |= black << (y%8);
if(black)
buffer[y/8][x] |= 1 << (y%8);
else
buffer[y/8][x] &= ~(1 << (y%8));
}
static void sort(int16_t *a, int16_t *b)
@ -195,12 +197,12 @@ static void sort(int16_t *a, int16_t *b)
}
}
void UI_DrawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black)
void UI_DrawLineBuffer(uint8_t (*buffer)[128], int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black)
{
if(x2==x1) {
sort(&y1, &y2);
for(int16_t i = y1; i <= y2; i++) {
UI_DrawPixel(x1, i, black);
UI_DrawPixelBuffer(buffer, x1, i, black);
}
} else {
const int multipl = 1000;
@ -210,17 +212,17 @@ void UI_DrawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black)
sort(&x1, &x2);
for(int i = x1; i<= x2; i++)
{
UI_DrawPixel(i, i*a/multipl +b, black);
UI_DrawPixelBuffer(buffer, i, i*a/multipl +b, black);
}
}
}
void UI_DrawRectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black)
void UI_DrawRectangleBuffer(uint8_t (*buffer)[128], int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black)
{
UI_DrawLine(x1,y1, x1,y2, black);
UI_DrawLine(x1,y1, x2,y1, black);
UI_DrawLine(x2,y1, x2,y2, black);
UI_DrawLine(x1,y2, x2,y2, black);
UI_DrawLineBuffer(buffer, x1,y1, x1,y2, black);
UI_DrawLineBuffer(buffer, x1,y1, x2,y1, black);
UI_DrawLineBuffer(buffer, x2,y1, x2,y2, black);
UI_DrawLineBuffer(buffer, x1,y2, x2,y2, black);
}
void UI_DisplayPopup(const char *string)
@ -234,13 +236,13 @@ void UI_DisplayPopup(const char *string)
// }
// for(uint8_t x = 10; x < 118; x++) {
// UI_DrawPixel(x, 10, true);
// UI_DrawPixel(x, 46-9, true);
// UI_DrawPixelBuffer(x, 10, true);
// UI_DrawPixelBuffer(x, 46-9, true);
// }
// for(uint8_t y = 11; y < 37; y++) {
// UI_DrawPixel(10, y, true);
// UI_DrawPixel(117, y, true);
// UI_DrawPixelBuffer(10, y, true);
// UI_DrawPixelBuffer(117, y, true);
// }
// DrawRectangle(9,9, 118,38, true);
UI_PrintString(string, 9, 118, 2, 8);

View File

@ -33,7 +33,7 @@ void UI_DisplayFrequency(const char *string, uint8_t X, uint8_t Y, bool center);
void UI_DisplayPopup(const char *string);
void UI_DrawPixel(uint8_t x, uint8_t y, bool black);
void UI_DrawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black);
void UI_DrawRectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black);
void UI_DrawPixelBuffer(uint8_t (*buffer)[128], uint8_t x, uint8_t y, bool black);
void UI_DrawLineBuffer(uint8_t (*buffer)[128], int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black);
void UI_DrawRectangleBuffer(uint8_t (*buffer)[128], int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black);