Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/pages/128x64x1/guiobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ struct reorder_obj {
guiScrollable_t scrollable;
};

struct scanner_obj {
guiButton_t enable;
guiButton_t scan_mode;
guiButton_t attenuator;
};

struct telemcfg_obj {
guiLabel_t msg;
guiLabel_t idx[7];
Expand Down Expand Up @@ -367,6 +373,9 @@ struct _gui_objs {
struct modelload_obj modelload;
struct modelpage_obj modelpage;
struct reorder_obj reorder;
#if HAS_SCANNER
struct scanner_obj scanner;
#endif
struct telemcfg_obj telemcfg;
struct telemtest_obj telemtest1;
struct timer_obj timer;
Expand Down
3 changes: 3 additions & 0 deletions src/pages/128x64x1/pagelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ PAGEDEF(PAGEID_CHANMON, PAGE_ChantestInit, PAGE_ChantestEvent, PAGE_Chant
PAGEDEF(PAGEID_TELEMMON, PAGE_TelemtestInit, PAGE_TelemtestEvent, NULL, TX_MENU, _tr_noop("Telemetry monitor"))
#endif
PAGEDEF(PAGEID_RANGE, PAGE_RangeInit, NULL, PAGE_RangeExit, TX_MENU, _tr_noop("Range Test"))
#if HAS_SCANNER
PAGEDEF(PAGEID_SCANNER, PAGE_ScannerInit, PAGE_ScannerEvent, PAGE_ScannerExit, TX_MENU, _tr_noop("Scanner"))
#endif
//-------------------

// Pages menu
Expand Down
4 changes: 3 additions & 1 deletion src/pages/128x64x1/pages.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ struct pagemem {
struct timer_page timer_page;
struct chantest_page chantest_page;
struct range_page range_page;
//struct scanner_page scanner_page;
#if HAS_SCANNER
struct scanner_page scanner_page;
#endif
#if HAS_MUSIC_CONFIG
struct voiceconfig_page voiceconfig_page;
#endif
Expand Down
66 changes: 66 additions & 0 deletions src/pages/128x64x1/scanner_page.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
This project is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Deviation is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Deviation. If not, see <http://www.gnu.org/licenses/>.
*/

#include "common.h"
#include "protocol/interface.h"
#include "pages.h"
#include "config/model.h"

#if HAS_SCANNER
#include "../common/_scanner_page.c"

static struct scanner_obj * const gui = &gui_objs.u.scanner;
static const char *enablestr_cb(guiObject_t *obj, const void *data)
{
(void)obj;
(void)data;
return sp->enable ? _tr("On") : _tr("Off");
}

static const char *modestr_cb(guiObject_t *obj, const void *data)
{
(void)obj;
(void)data;
return sp->scan_mode ? _tr("Average") : _tr("Peak");
}

static const char *attstr_cb(guiObject_t *obj, const void *data)
{
(void)obj;
(void)data;
return sp->attenuator ? _tr("-20dB") : _tr("0dB");
}

void _draw_page(u8 enable)
{
(void)enable;
PAGE_ShowHeader(PAGE_GetName(PAGEID_SCANNER));
GUI_CreateButtonPlateText(&gui->enable, 0, HEADER_HEIGHT, 40, LINE_HEIGHT, &BUTTON_FONT, enablestr_cb, press_enable_cb, NULL);
GUI_CreateButtonPlateText(&gui->scan_mode, LCD_WIDTH/2 - 20, HEADER_HEIGHT, 40, LINE_HEIGHT, &BUTTON_FONT, modestr_cb, press_mode_cb, NULL);
GUI_CreateButtonPlateText(&gui->attenuator, LCD_WIDTH - 40, HEADER_HEIGHT, 40, LINE_HEIGHT, &BUTTON_FONT, attstr_cb, press_attenuator_cb, NULL);
}

void _draw_channels()
{
const unsigned offset = HEADER_HEIGHT + LINE_HEIGHT;
// draw a line
int col = (LCD_WIDTH - (MAX_RADIOCHANNEL - MIN_RADIOCHANNEL)) / 2 + sp->channel;
int height = sp->channelnoise[sp->channel] * (LCD_HEIGHT - offset) / 0x1F;

LCD_DrawFastVLine(col, offset, LCD_HEIGHT - height, 0);
LCD_DrawFastVLine(col, LCD_HEIGHT - height, LCD_HEIGHT, Display.xygraph.grid_color);
}

#endif //HAS_SCANNER
1 change: 0 additions & 1 deletion src/pages/320x240x16/pages.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define _PAGES_H_

#include "../common/_pages.h"
#include "scanner_page.h"
#include "icons.h"
#include "guiobj.h"

Expand Down
115 changes: 6 additions & 109 deletions src/pages/320x240x16/scanner_page.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,10 @@
#include "pages.h"
#include "config/model.h"


#if HAS_SCANNER
static struct scanner_page * const sp = &pagemem.u.scanner_page;
#include "../common/_scanner_page.c"
static struct scanner_obj * const gui = &gui_objs.u.scanner;
static u8 scanState = 0;

u16 scan_cb()
{
int delay;

if(scanState == 0) {
if(sp->time_to_scan == 0) {
CYRF_ConfigRFChannel(sp->channel + MIN_RADIOCHANNEL);
if(sp->attenuator) {
CYRF_WriteRegister(CYRF_06_RX_CFG, 0x0A);
} else {
CYRF_WriteRegister(CYRF_06_RX_CFG, 0x4A);
}
sp->time_to_scan = 1;
}
scanState = 1;
delay = 300; //slow channel require 270usec for synthesizer to settle
} else {
if ( !(CYRF_ReadRegister(CYRF_05_RX_CTRL) & 0x80)) {
CYRF_WriteRegister(CYRF_05_RX_CTRL, 0x80); //Prepare to receive
Delay(10);
CYRF_ReadRegister(CYRF_13_RSSI); //dummy read
Delay(15);
}
int rssi = CYRF_ReadRegister(CYRF_13_RSSI) & 0x1F;
if(sp->scan_mode) {
sp->channelnoise[sp->channel] = (sp->channelnoise[sp->channel] + rssi) / 2;
} else {
if(rssi > sp->channelnoise[sp->channel])
sp->channelnoise[sp->channel] = rssi;
}
scanState++;
delay = 300;
if(scanState == 5) {
scanState = 0;
delay = 50;
}
}
return delay;
}

static s32 show_bar_cb(void *data)
{
long ch = (long)data;
Expand Down Expand Up @@ -90,89 +49,27 @@ static const char *attstr_cb(guiObject_t *obj, const void *data)
return sp->attenuator ? _tr("Att.: -20dB") : _tr("Att.: 0dB");
}

static void press_enable_cb(guiObject_t *obj, const void *data)
{
(void)data;
#ifndef ENABLE_MODULAR
sp->enable ^= 1;
if (sp->enable) {
PROTOCOL_DeInit();
DEVO_Cmds(0); //Switch to DEVO configuration
PROTOCOL_SetBindState(0); //Disable binding message
CLOCK_StopTimer();
CYRF_SetTxRxMode(RX_EN); //Receive mode
CLOCK_StartTimer(1250, scan_cb);
} else {
PROTOCOL_Init(0);
}
#endif
GUI_Redraw(obj);
}

static void press_mode_cb(guiObject_t *obj, const void *data)
{
(void)data;
#ifndef ENABLE_MODULAR
sp->scan_mode ^= 1;
#endif
GUI_Redraw(obj);
}

static void press_attenuator_cb(guiObject_t *obj, const void *data)
{
(void)data;
#ifndef ENABLE_MODULAR
sp->attenuator ^= 1;
#endif
GUI_Redraw(obj);
}

void PAGE_ScannerInit(int page)
void _draw_page(u8 enable)
{
enum {
SCANBARWIDTH = (LCD_WIDTH / (MAX_RADIOCHANNEL - MIN_RADIOCHANNEL + 1)),
SCANBARXOFFSET = ((LCD_WIDTH - SCANBARWIDTH * (MAX_RADIOCHANNEL - MIN_RADIOCHANNEL + 1))/2),
SCANBARHEIGHT = (LCD_HEIGHT - 78),
};
u8 i;
(void)page;
PAGE_SetModal(0);
(void)enable;
PAGE_ShowHeader(PAGE_GetName(PAGEID_SCANNER));
sp->enable = 0;
GUI_CreateButton(&gui->enable, LCD_WIDTH/2 - 152, 40, BUTTON_96, enablestr_cb, press_enable_cb, NULL);
sp->scan_mode = 0;
GUI_CreateButton(&gui->scan_mode, LCD_WIDTH/2 - 48, 40, BUTTON_96, modestr_cb, press_mode_cb, NULL);
sp->attenuator = 0;
GUI_CreateButton(&gui->attenuator, LCD_WIDTH/2 + 56, 40, BUTTON_96, attstr_cb, press_attenuator_cb, NULL);
sp->channel = 0;
sp->time_to_scan = 0;
GUI_CreateButton(&gui->attenuator, LCD_WIDTH/2 + 56, 40, BUTTON_96, attstr_cb, press_attenuator_cb, NULL);
for(i = 0; i < (MAX_RADIOCHANNEL - MIN_RADIOCHANNEL + 1); i++) {
GUI_CreateBarGraph(&gui->bar[i], SCANBARXOFFSET + i * SCANBARWIDTH, 70, SCANBARWIDTH, SCANBARHEIGHT, 2, 31, BAR_VERTICAL, show_bar_cb, (void *)((long)i));
sp->channelnoise[i] = 0;
}
}

void PAGE_ScannerEvent()
void _draw_channels()
{
#ifndef ENABLE_MODULAR
if(! sp->enable)
return;
GUI_Redraw(&gui->bar[sp->channel]);
//printf("%02X : %d\n",sp->channel,sp->channelnoise[sp->channel]);
sp->channel++;
if(sp->channel == (MAX_RADIOCHANNEL - MIN_RADIOCHANNEL + 1))
sp->channel = 0;
sp->channelnoise[sp->channel] = 0;
sp->time_to_scan = 0;
#endif
}

void PAGE_ScannerExit()
{
#ifndef ENABLE_MODULAR
if(sp->enable)
PROTOCOL_Init(0);
#endif
}

#endif //HAS_SCANNER
1 change: 0 additions & 1 deletion src/pages/480x272x16/scanner_page.h

This file was deleted.

1 change: 1 addition & 0 deletions src/pages/common/_pages.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "config/display.h"
#include "rtc_config.h"
#include "voiceconfig_page.h"
#include "scanner_page.h"

#define PAGE_NAME_MAX 10

Expand Down
Loading