-
Notifications
You must be signed in to change notification settings - Fork 1
/
Smeter.cpp
57 lines (44 loc) · 1.14 KB
/
Smeter.cpp
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
//
// S Meter
//
#include "RadioControl.h"
//#define S_DEBUG
const int slevels[MAXSLEVELS] = {25, 100, 200, 375, 500, 575, 650, 775, 900, 950, 975, 1000};
//byte smeter = 0;
unsigned long smeter_raw = 0;
unsigned long smeter_sample_count = 0;
unsigned long smeter_time = 0;
//*****************************************
void CheckSmeter() {
int i;
int smeter_avg;
if (TxRxState == TX) {
return;
}
smeter_raw = smeter_raw + analogRead(SMETER_PIN);
smeter_sample_count++;
if ((millis() - SMETER_SAMPLE_TIMER) > smeter_time) {
/*
lcd.setCursor(12, 1);
lcd.print(" ");
lcd.setCursor(12, 1);
lcd.print(smeter_raw);
*/
smeter_avg = int(smeter_raw / smeter_sample_count);
#ifdef S_DEBUG
String msg = F("S raw:");
msg+=smeter_avg;
displayBanner(msg);
#endif
smeter = 0;
for (i = 0; i < MAXSLEVELS; i++) {
if (smeter_avg >= slevels[i]) {
smeter = byte(i);
}
}
displaySMeter(smeter);
smeter_raw = 0;
smeter_sample_count = 0;
smeter_time = millis();
}
}