-
Notifications
You must be signed in to change notification settings - Fork 2
/
fpv_scan.ino
109 lines (98 loc) · 2.46 KB
/
fpv_scan.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <LCD5110_Graph.h>
#include "radio.h"
#include "scanner.h"
#include "lcd.h"
#include "menu.h"
#include "list.h"
// Define pins
#define SPI_DATA_PIN 10
#define SPI_SLAVE_SELECT_PIN 11
#define SPI_CLOCK_PIN 12
#define RSSI_PIN A0
#define PIN_LCD_CLK 2
#define PIN_LCD_DIN 3
#define PIN_LCD_DC 4
#define PIN_LCD_RST 5
#define PIN_LCD_CE 6
#define PIN_UP 8
#define PIN_DOWN 13
#define PIN_SELECT 7
#define PIN_MENU 9
#define PIN_BATT A1
// Define modes
#define MODE_MENU 0
#define MODE_EDITOR 1
#define BUTTON_DELAY 200
int mode = MODE_MENU;
int old_mode = -1;
int menu_selection = 2;
extern uint8_t SmallFont[];
extern uint8_t TinyFont[];
Lcd lcd(PIN_LCD_CLK, PIN_LCD_DIN, PIN_LCD_DC, PIN_LCD_RST, PIN_LCD_CE);
Radio radio(SPI_DATA_PIN, SPI_SLAVE_SELECT_PIN, SPI_CLOCK_PIN, RSSI_PIN);
Scanner scanner(&radio, &lcd);
List ch_select(&radio, &lcd, false, "Channel Sel");
List fr_select(&radio, &lcd, true, "Frequency Sel");
Menu menu(&lcd, 3);
void setup() {
pinMode(SPI_SLAVE_SELECT_PIN, OUTPUT);
pinMode(SPI_DATA_PIN, OUTPUT);
pinMode(SPI_CLOCK_PIN, OUTPUT);
pinMode(PIN_UP, INPUT);
pinMode(PIN_DOWN, INPUT);
pinMode(PIN_SELECT, INPUT);
pinMode(PIN_MENU, INPUT);
lcd.InitLCD();
lcd.setFont(TinyFont);
Serial.begin(9600);
init_menu();
}
void init_menu() {
menu.add_item((Item*) &scanner);
menu.add_item((Item*) &ch_select);
menu.add_item((Item*) &fr_select);
}
void loop() {
if(old_mode != mode) {
switch(mode) {
case MODE_MENU:
menu.print();
break;
case MODE_EDITOR:
menu.get_selected()->start();
break;
}
old_mode = mode;
} else {
if(mode == MODE_EDITOR) {
menu.get_selected()->refresh();
} else {
int batt = analogRead(PIN_BATT);
double b = ((double)batt * 4.47 )/1023;
lcd.printBatt(60, 41, b);
lcd.update();
}
if(digitalRead(PIN_MENU) == HIGH) {
mode = MODE_MENU;
} else if(digitalRead(PIN_UP) == HIGH) {
if(mode == MODE_MENU) {
menu.selection_up();
} else {
menu.get_selected()->up();
}
} else if(digitalRead(PIN_DOWN) == HIGH) {
if(mode == MODE_MENU) {
menu.selection_down();
} else {
menu.get_selected()->down();
}
} else if(digitalRead(PIN_SELECT) == HIGH) {
if(mode == MODE_MENU) {
mode = MODE_EDITOR; // enter editor
} else {
menu.get_selected()->select();
}
}
}
delay(BUTTON_DELAY);
}