-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathspectrum.c
118 lines (89 loc) · 2.49 KB
/
spectrum.c
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
110
111
112
113
114
115
116
117
118
/*
* Spectrum scanner/analyzer
*/
#include <avr/io.h>
#include <stdio.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include "23nbfm.h"
#include <util/delay.h>
extern long int freq;
// internal function prototypes
void createGraphCharacters();
int getRSSI(long int f);
int avgRSSI();
// define S-meter chars
unsigned char spectrumChars[8][8] = {
{0B00000,0B00000,0B00000,0B00000,0B00000,0B00000,0B00000,0B11111},
{0B00000,0B00000,0B00000,0B00000,0B00000,0B00000,0B11111,0B11111},
{0B00000,0B00000,0B00000,0B00000,0B00000,0B11111,0B11111,0B11111},
{0B00000,0B00000,0B00000,0B00000,0B11111,0B11111,0B11111,0B11111},
{0B00000,0B00000,0B00000,0B11111,0B11111,0B11111,0B11111,0B11111},
{0B00000,0B00000,0B11111,0B11111,0B11111,0B11111,0B11111,0B11111},
{0B00000,0B11111,0B00000,0B11111,0B11111,0B11111,0B11111,0B11111},
{0B11111,0B11111,0B11111,0B11111,0B11111,0B11111,0B11111,0B11111}
};
/* Maps values (the index) to characters (the value) */
unsigned char graphCharacterMap[9] = { ' ', 0, 1, 2, 3, 4, 5, 6, 7 };
long int scanWidth = 800000;
int Spectrum() {
int x;
lcdClear();
createGraphCharacters();
// long int startFreq = freq - scanWidth/2;
// long int endFreq = freq + scanWidth/2;
// long int step = 25000; //(endFreq - startFreq)/16;
// mute the rx during spectrum display
sbi(PORTC, MUTE);
for (;;) {
for (x=0; x<16; x++) {
int rssi = getRSSI(freq+x);
// int rssi = avgRSSI(startFreq+x*step, startFreq+x*step+step);
if (getRotaryPush())
return VFO;
// map rssi 48 bars horizontal to 16 vertical
unsigned char y = rssi/3;
lcdCursor(x,0);
if (y>8)
lcdChar((char)graphCharacterMap[min(8,y-8)]);
else
lcdChar(' ');
lcdCursor(x,1);
lcdChar((char)graphCharacterMap[min(8,y)]);
}
}
}
int getRSSI(long int f)
{
int rssi=0;
setFrequency(f - IF);
if (getRotaryPush()) return TRUE;
rssi = max(rssi, readRSSI());
if (rssi < 0) rssi = 0;
return rssi;
}
int avgRSSI(long int start, long int end)
{
int rssi=0;
long int f;
for (f=start; f<end; f+=10) {
setFrequency(f - IF);
if (getRotaryPush()) return TRUE;
_delay_ms(10);
rssi = max(rssi, readRSSI());
}
if (rssi < 0) rssi = 0;
return rssi;
}
void createGraphCharacters()
{
int i, j;
// define custom chars for spectrum
lcdCmd(0x40);
for (i=0; i<8; i++) {
for (j=0; j<8; j++) {
lcdData(spectrumChars[i][j]);
}
}
}