Skip to content

Commit a0d052b

Browse files
committed
Spectrum refactor
1 parent 9a3249a commit a0d052b

File tree

3 files changed

+44
-63
lines changed

3 files changed

+44
-63
lines changed

app/spectrum.c

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "app/spectrum.h"
1818
#include "driver/backlight.h"
1919
#include "audio.h"
20+
#include "ui/helper.h"
2021

2122
struct FrequencyBandInfo {
2223
uint32_t lower;
@@ -125,21 +126,13 @@ static void SetRegMenuValue(uint8_t st, bool add) {
125126
// GUI functions
126127

127128
static void PutPixel(uint8_t x, uint8_t y, bool fill) {
128-
if (fill) {
129-
gFrameBuffer[y >> 3][x] |= 1 << (y & 7);
130-
} else {
131-
gFrameBuffer[y >> 3][x] &= ~(1 << (y & 7));
132-
}
129+
UI_DrawPixelBuffer(gFrameBuffer, x, y, fill);
133130
}
134131
static void PutPixelStatus(uint8_t x, uint8_t y, bool fill) {
135-
if (fill) {
136-
gStatusLine[x] |= 1 << y;
137-
} else {
138-
gStatusLine[x] &= ~(1 << y);
139-
}
132+
UI_DrawPixelBuffer(&gStatusLine, x, y, fill);
140133
}
141134

142-
static void DrawHLine(int sy, int ey, int nx, bool fill) {
135+
static void DrawVLine(int sy, int ey, int nx, bool fill) {
143136
for (int i = sy; i <= ey; i++) {
144137
if (i < 56 && nx < 128) {
145138
PutPixel(nx, i, fill);
@@ -606,7 +599,7 @@ static void DrawSpectrum() {
606599
for (uint8_t x = 0; x < 128; ++x) {
607600
uint16_t rssi = rssiHistory[x >> settings.stepsCount];
608601
if (rssi != RSSI_MAX_VALUE) {
609-
DrawHLine(Rssi2Y(rssi), DrawingEndY, x, true);
602+
DrawVLine(Rssi2Y(rssi), DrawingEndY, x, true);
610603
}
611604
}
612605
}
@@ -620,36 +613,28 @@ static void DrawStatus() {
620613
#endif
621614
GUI_DisplaySmallest(String, 0, 1, true, true);
622615

623-
for (int i = 0; i < 4; i++) {
624-
BOARD_ADC_GetBatteryInfo(&gBatteryVoltages[i], &gBatteryCurrent);
625-
}
626-
627-
uint16_t Voltage;
628-
uint8_t v = 0;
616+
BOARD_ADC_GetBatteryInfo(&gBatteryVoltages[gBatteryCheckCounter++ % 4], &gBatteryCurrent);
629617

630-
Voltage = (gBatteryVoltages[0] + gBatteryVoltages[1] + gBatteryVoltages[2] +
618+
uint16_t voltage = (gBatteryVoltages[0] + gBatteryVoltages[1] + gBatteryVoltages[2] +
631619
gBatteryVoltages[3]) /
632-
4;
620+
4 * 760 / gBatteryCalibration[3];
633621

634-
for(uint8_t i = 5; i > 0; i--) {
635-
if(Voltage > gBatteryCalibration[i - 1]) {
636-
v = i;
637-
break;
638-
}
639-
}
622+
unsigned perc = BATTERY_VoltsToPercent(voltage);
640623

641-
gStatusLine[127] = 0b01111110;
642-
for (int i = 126; i >= 116; i--) {
643-
gStatusLine[i] = 0b01000010;
624+
// sprintf(String, "%d %d", voltage, perc);
625+
// GUI_DisplaySmallest(String, 48, 1, true, true);
626+
627+
gStatusLine[116] = 0b00011100;
628+
gStatusLine[117] = 0b00111110;
629+
for (int i = 118; i <= 126; i++) {
630+
gStatusLine[i] = 0b00100010;
644631
}
645-
v <<= 1;
646-
for (int i = 125; i >= 116; i--) {
647-
if (126 - i <= v) {
648-
gStatusLine[i + 2] = 0b01111110;
632+
633+
for (unsigned i = 127; i >= 118; i--) {
634+
if (127 - i <= (perc+5)*9/100) {
635+
gStatusLine[i] = 0b00111110;
649636
}
650637
}
651-
gStatusLine[117] = 0b01111110;
652-
gStatusLine[116] = 0b00011000;
653638
}
654639

655640
static void DrawF(uint32_t f) {
@@ -712,19 +697,13 @@ static void DrawTicks() {
712697

713698
// center
714699
if (IsCenterMode()) {
715-
gFrameBuffer[5][62] = 0x80;
716-
gFrameBuffer[5][63] = 0x80;
700+
memset(gFrameBuffer[5] + 62, 0x80, 5);
717701
gFrameBuffer[5][64] = 0xff;
718-
gFrameBuffer[5][65] = 0x80;
719-
gFrameBuffer[5][66] = 0x80;
720702
} else {
703+
memset(gFrameBuffer[5] + 1, 0x80, 3);
704+
memset(gFrameBuffer[5] + 124, 0x80, 3);
705+
721706
gFrameBuffer[5][0] = 0xff;
722-
gFrameBuffer[5][1] = 0x80;
723-
gFrameBuffer[5][2] = 0x80;
724-
gFrameBuffer[5][3] = 0x80;
725-
gFrameBuffer[5][124] = 0x80;
726-
gFrameBuffer[5][125] = 0x80;
727-
gFrameBuffer[5][126] = 0x80;
728707
gFrameBuffer[5][127] = 0xff;
729708
}
730709
}

ui/helper.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,12 @@ void UI_DisplayFrequency(const char *string, uint8_t X, uint8_t Y, bool center)
180180
}
181181
}
182182

183-
void UI_DrawPixel(uint8_t x, uint8_t y, bool black)
183+
void UI_DrawPixelBuffer(uint8_t (*buffer)[128], uint8_t x, uint8_t y, bool black)
184184
{
185-
gFrameBuffer[y/8][x] &= ~(1 << (y%8));
186-
gFrameBuffer[y/8][x] |= black << (y%8);
185+
if(black)
186+
buffer[y/8][x] |= 1 << (y%8);
187+
else
188+
buffer[y/8][x] &= ~(1 << (y%8));
187189
}
188190

189191
static void sort(int16_t *a, int16_t *b)
@@ -195,12 +197,12 @@ static void sort(int16_t *a, int16_t *b)
195197
}
196198
}
197199

198-
void UI_DrawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black)
200+
void UI_DrawLineBuffer(uint8_t (*buffer)[128], int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black)
199201
{
200202
if(x2==x1) {
201203
sort(&y1, &y2);
202204
for(int16_t i = y1; i <= y2; i++) {
203-
UI_DrawPixel(x1, i, black);
205+
UI_DrawPixelBuffer(buffer, x1, i, black);
204206
}
205207
} else {
206208
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)
210212
sort(&x1, &x2);
211213
for(int i = x1; i<= x2; i++)
212214
{
213-
UI_DrawPixel(i, i*a/multipl +b, black);
215+
UI_DrawPixelBuffer(buffer, i, i*a/multipl +b, black);
214216
}
215217
}
216218
}
217219

218-
void UI_DrawRectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black)
220+
void UI_DrawRectangleBuffer(uint8_t (*buffer)[128], int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black)
219221
{
220-
UI_DrawLine(x1,y1, x1,y2, black);
221-
UI_DrawLine(x1,y1, x2,y1, black);
222-
UI_DrawLine(x2,y1, x2,y2, black);
223-
UI_DrawLine(x1,y2, x2,y2, black);
222+
UI_DrawLineBuffer(buffer, x1,y1, x1,y2, black);
223+
UI_DrawLineBuffer(buffer, x1,y1, x2,y1, black);
224+
UI_DrawLineBuffer(buffer, x2,y1, x2,y2, black);
225+
UI_DrawLineBuffer(buffer, x1,y2, x2,y2, black);
224226
}
225227

226228
void UI_DisplayPopup(const char *string)
@@ -234,13 +236,13 @@ void UI_DisplayPopup(const char *string)
234236
// }
235237

236238
// for(uint8_t x = 10; x < 118; x++) {
237-
// UI_DrawPixel(x, 10, true);
238-
// UI_DrawPixel(x, 46-9, true);
239+
// UI_DrawPixelBuffer(x, 10, true);
240+
// UI_DrawPixelBuffer(x, 46-9, true);
239241
// }
240242

241243
// for(uint8_t y = 11; y < 37; y++) {
242-
// UI_DrawPixel(10, y, true);
243-
// UI_DrawPixel(117, y, true);
244+
// UI_DrawPixelBuffer(10, y, true);
245+
// UI_DrawPixelBuffer(117, y, true);
244246
// }
245247
// DrawRectangle(9,9, 118,38, true);
246248
UI_PrintString(string, 9, 118, 2, 8);

ui/helper.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void UI_DisplayFrequency(const char *string, uint8_t X, uint8_t Y, bool center);
3333

3434
void UI_DisplayPopup(const char *string);
3535

36-
void UI_DrawPixel(uint8_t x, uint8_t y, bool black);
37-
void UI_DrawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black);
38-
void UI_DrawRectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black);
36+
void UI_DrawPixelBuffer(uint8_t (*buffer)[128], uint8_t x, uint8_t y, bool black);
37+
void UI_DrawLineBuffer(uint8_t (*buffer)[128], int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black);
38+
void UI_DrawRectangleBuffer(uint8_t (*buffer)[128], int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool black);
3939

0 commit comments

Comments
 (0)