Skip to content

Commit bc7daaa

Browse files
howard0suhexfet
authored andcommitted
Add Scanner support to 128x64x1 screen (#533)
* Optimize the scanner RAM usage * Add scanner page for devo10 * Enable scanner on devo10/devo12e/t8sg * Fix Windows emu build * Enable scanner for devo7e-256 * Optimize User experience * Simplify emulator implementation * Remove unused variable * Cleanup and dedup
1 parent be91761 commit bc7daaa

17 files changed

Lines changed: 239 additions & 119 deletions

File tree

src/pages/128x64x1/guiobj.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ struct reorder_obj {
120120
guiScrollable_t scrollable;
121121
};
122122

123+
struct scanner_obj {
124+
guiButton_t enable;
125+
guiButton_t scan_mode;
126+
guiButton_t attenuator;
127+
};
128+
123129
struct telemcfg_obj {
124130
guiLabel_t msg;
125131
guiLabel_t idx[7];
@@ -367,6 +373,9 @@ struct _gui_objs {
367373
struct modelload_obj modelload;
368374
struct modelpage_obj modelpage;
369375
struct reorder_obj reorder;
376+
#if HAS_SCANNER
377+
struct scanner_obj scanner;
378+
#endif
370379
struct telemcfg_obj telemcfg;
371380
struct telemtest_obj telemtest1;
372381
struct timer_obj timer;

src/pages/128x64x1/pagelist.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ PAGEDEF(PAGEID_CHANMON, PAGE_ChantestInit, PAGE_ChantestEvent, PAGE_Chant
7575
PAGEDEF(PAGEID_TELEMMON, PAGE_TelemtestInit, PAGE_TelemtestEvent, NULL, TX_MENU, _tr_noop("Telemetry monitor"))
7676
#endif
7777
PAGEDEF(PAGEID_RANGE, PAGE_RangeInit, NULL, PAGE_RangeExit, TX_MENU, _tr_noop("Range Test"))
78+
#if HAS_SCANNER
79+
PAGEDEF(PAGEID_SCANNER, PAGE_ScannerInit, PAGE_ScannerEvent, PAGE_ScannerExit, TX_MENU, _tr_noop("Scanner"))
80+
#endif
7881
//-------------------
7982

8083
// Pages menu

src/pages/128x64x1/pages.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ struct pagemem {
1414
struct timer_page timer_page;
1515
struct chantest_page chantest_page;
1616
struct range_page range_page;
17-
//struct scanner_page scanner_page;
17+
#if HAS_SCANNER
18+
struct scanner_page scanner_page;
19+
#endif
1820
#if HAS_MUSIC_CONFIG
1921
struct voiceconfig_page voiceconfig_page;
2022
#endif

src/pages/128x64x1/scanner_page.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
This project is free software: you can redistribute it and/or modify
3+
it under the terms of the GNU General Public License as published by
4+
the Free Software Foundation, either version 3 of the License, or
5+
(at your option) any later version.
6+
7+
Deviation is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with Deviation. If not, see <http://www.gnu.org/licenses/>.
14+
*/
15+
16+
#include "common.h"
17+
#include "protocol/interface.h"
18+
#include "pages.h"
19+
#include "config/model.h"
20+
21+
#if HAS_SCANNER
22+
#include "../common/_scanner_page.c"
23+
24+
static struct scanner_obj * const gui = &gui_objs.u.scanner;
25+
static const char *enablestr_cb(guiObject_t *obj, const void *data)
26+
{
27+
(void)obj;
28+
(void)data;
29+
return sp->enable ? _tr("On") : _tr("Off");
30+
}
31+
32+
static const char *modestr_cb(guiObject_t *obj, const void *data)
33+
{
34+
(void)obj;
35+
(void)data;
36+
return sp->scan_mode ? _tr("Average") : _tr("Peak");
37+
}
38+
39+
static const char *attstr_cb(guiObject_t *obj, const void *data)
40+
{
41+
(void)obj;
42+
(void)data;
43+
return sp->attenuator ? _tr("-20dB") : _tr("0dB");
44+
}
45+
46+
void _draw_page(u8 enable)
47+
{
48+
(void)enable;
49+
PAGE_ShowHeader(PAGE_GetName(PAGEID_SCANNER));
50+
GUI_CreateButtonPlateText(&gui->enable, 0, HEADER_HEIGHT, 40, LINE_HEIGHT, &BUTTON_FONT, enablestr_cb, press_enable_cb, NULL);
51+
GUI_CreateButtonPlateText(&gui->scan_mode, LCD_WIDTH/2 - 20, HEADER_HEIGHT, 40, LINE_HEIGHT, &BUTTON_FONT, modestr_cb, press_mode_cb, NULL);
52+
GUI_CreateButtonPlateText(&gui->attenuator, LCD_WIDTH - 40, HEADER_HEIGHT, 40, LINE_HEIGHT, &BUTTON_FONT, attstr_cb, press_attenuator_cb, NULL);
53+
}
54+
55+
void _draw_channels()
56+
{
57+
const unsigned offset = HEADER_HEIGHT + LINE_HEIGHT;
58+
// draw a line
59+
int col = (LCD_WIDTH - (MAX_RADIOCHANNEL - MIN_RADIOCHANNEL)) / 2 + sp->channel;
60+
int height = sp->channelnoise[sp->channel] * (LCD_HEIGHT - offset) / 0x1F;
61+
62+
LCD_DrawFastVLine(col, offset, LCD_HEIGHT - height, 0);
63+
LCD_DrawFastVLine(col, LCD_HEIGHT - height, LCD_HEIGHT, Display.xygraph.grid_color);
64+
}
65+
66+
#endif //HAS_SCANNER

src/pages/320x240x16/pages.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define _PAGES_H_
33

44
#include "../common/_pages.h"
5-
#include "scanner_page.h"
65
#include "icons.h"
76
#include "guiobj.h"
87

src/pages/320x240x16/scanner_page.c

Lines changed: 6 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -18,51 +18,10 @@
1818
#include "pages.h"
1919
#include "config/model.h"
2020

21+
2122
#if HAS_SCANNER
22-
static struct scanner_page * const sp = &pagemem.u.scanner_page;
23+
#include "../common/_scanner_page.c"
2324
static struct scanner_obj * const gui = &gui_objs.u.scanner;
24-
static u8 scanState = 0;
25-
26-
u16 scan_cb()
27-
{
28-
int delay;
29-
30-
if(scanState == 0) {
31-
if(sp->time_to_scan == 0) {
32-
CYRF_ConfigRFChannel(sp->channel + MIN_RADIOCHANNEL);
33-
if(sp->attenuator) {
34-
CYRF_WriteRegister(CYRF_06_RX_CFG, 0x0A);
35-
} else {
36-
CYRF_WriteRegister(CYRF_06_RX_CFG, 0x4A);
37-
}
38-
sp->time_to_scan = 1;
39-
}
40-
scanState = 1;
41-
delay = 300; //slow channel require 270usec for synthesizer to settle
42-
} else {
43-
if ( !(CYRF_ReadRegister(CYRF_05_RX_CTRL) & 0x80)) {
44-
CYRF_WriteRegister(CYRF_05_RX_CTRL, 0x80); //Prepare to receive
45-
Delay(10);
46-
CYRF_ReadRegister(CYRF_13_RSSI); //dummy read
47-
Delay(15);
48-
}
49-
int rssi = CYRF_ReadRegister(CYRF_13_RSSI) & 0x1F;
50-
if(sp->scan_mode) {
51-
sp->channelnoise[sp->channel] = (sp->channelnoise[sp->channel] + rssi) / 2;
52-
} else {
53-
if(rssi > sp->channelnoise[sp->channel])
54-
sp->channelnoise[sp->channel] = rssi;
55-
}
56-
scanState++;
57-
delay = 300;
58-
if(scanState == 5) {
59-
scanState = 0;
60-
delay = 50;
61-
}
62-
}
63-
return delay;
64-
}
65-
6625
static s32 show_bar_cb(void *data)
6726
{
6827
long ch = (long)data;
@@ -90,89 +49,27 @@ static const char *attstr_cb(guiObject_t *obj, const void *data)
9049
return sp->attenuator ? _tr("Att.: -20dB") : _tr("Att.: 0dB");
9150
}
9251

93-
static void press_enable_cb(guiObject_t *obj, const void *data)
94-
{
95-
(void)data;
96-
#ifndef ENABLE_MODULAR
97-
sp->enable ^= 1;
98-
if (sp->enable) {
99-
PROTOCOL_DeInit();
100-
DEVO_Cmds(0); //Switch to DEVO configuration
101-
PROTOCOL_SetBindState(0); //Disable binding message
102-
CLOCK_StopTimer();
103-
CYRF_SetTxRxMode(RX_EN); //Receive mode
104-
CLOCK_StartTimer(1250, scan_cb);
105-
} else {
106-
PROTOCOL_Init(0);
107-
}
108-
#endif
109-
GUI_Redraw(obj);
110-
}
111-
112-
static void press_mode_cb(guiObject_t *obj, const void *data)
113-
{
114-
(void)data;
115-
#ifndef ENABLE_MODULAR
116-
sp->scan_mode ^= 1;
117-
#endif
118-
GUI_Redraw(obj);
119-
}
120-
121-
static void press_attenuator_cb(guiObject_t *obj, const void *data)
122-
{
123-
(void)data;
124-
#ifndef ENABLE_MODULAR
125-
sp->attenuator ^= 1;
126-
#endif
127-
GUI_Redraw(obj);
128-
}
129-
130-
void PAGE_ScannerInit(int page)
52+
void _draw_page(u8 enable)
13153
{
13254
enum {
13355
SCANBARWIDTH = (LCD_WIDTH / (MAX_RADIOCHANNEL - MIN_RADIOCHANNEL + 1)),
13456
SCANBARXOFFSET = ((LCD_WIDTH - SCANBARWIDTH * (MAX_RADIOCHANNEL - MIN_RADIOCHANNEL + 1))/2),
13557
SCANBARHEIGHT = (LCD_HEIGHT - 78),
13658
};
13759
u8 i;
138-
(void)page;
139-
PAGE_SetModal(0);
60+
(void)enable;
14061
PAGE_ShowHeader(PAGE_GetName(PAGEID_SCANNER));
141-
sp->enable = 0;
14262
GUI_CreateButton(&gui->enable, LCD_WIDTH/2 - 152, 40, BUTTON_96, enablestr_cb, press_enable_cb, NULL);
143-
sp->scan_mode = 0;
14463
GUI_CreateButton(&gui->scan_mode, LCD_WIDTH/2 - 48, 40, BUTTON_96, modestr_cb, press_mode_cb, NULL);
145-
sp->attenuator = 0;
146-
GUI_CreateButton(&gui->attenuator, LCD_WIDTH/2 + 56, 40, BUTTON_96, attstr_cb, press_attenuator_cb, NULL);
147-
sp->channel = 0;
148-
sp->time_to_scan = 0;
64+
GUI_CreateButton(&gui->attenuator, LCD_WIDTH/2 + 56, 40, BUTTON_96, attstr_cb, press_attenuator_cb, NULL);
14965
for(i = 0; i < (MAX_RADIOCHANNEL - MIN_RADIOCHANNEL + 1); i++) {
15066
GUI_CreateBarGraph(&gui->bar[i], SCANBARXOFFSET + i * SCANBARWIDTH, 70, SCANBARWIDTH, SCANBARHEIGHT, 2, 31, BAR_VERTICAL, show_bar_cb, (void *)((long)i));
151-
sp->channelnoise[i] = 0;
15267
}
15368
}
15469

155-
void PAGE_ScannerEvent()
70+
void _draw_channels()
15671
{
157-
#ifndef ENABLE_MODULAR
158-
if(! sp->enable)
159-
return;
16072
GUI_Redraw(&gui->bar[sp->channel]);
161-
//printf("%02X : %d\n",sp->channel,sp->channelnoise[sp->channel]);
162-
sp->channel++;
163-
if(sp->channel == (MAX_RADIOCHANNEL - MIN_RADIOCHANNEL + 1))
164-
sp->channel = 0;
165-
sp->channelnoise[sp->channel] = 0;
166-
sp->time_to_scan = 0;
167-
#endif
168-
}
169-
170-
void PAGE_ScannerExit()
171-
{
172-
#ifndef ENABLE_MODULAR
173-
if(sp->enable)
174-
PROTOCOL_Init(0);
175-
#endif
17673
}
17774

17875
#endif //HAS_SCANNER

src/pages/480x272x16/scanner_page.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/pages/common/_pages.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "config/display.h"
2424
#include "rtc_config.h"
2525
#include "voiceconfig_page.h"
26+
#include "scanner_page.h"
2627

2728
#define PAGE_NAME_MAX 10
2829

0 commit comments

Comments
 (0)