-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfm_radio.cpp
More file actions
114 lines (67 loc) · 3.28 KB
/
Copy pathfm_radio.cpp
File metadata and controls
114 lines (67 loc) · 3.28 KB
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
// this is a base <data provider> class, this class will not access any
// of the other classes it doesnt have an event system like the others
// because this doesnt need any events
// i estimate this class to be taking 2% of the memeory but the libries
// we are importing wire and the SparkFunSi4703 library we are taking
// 5%
// i import the .cpp file because the .h dont import them and i get a
// linker error please dont remove it keep the libraries unedited as
// much as possible please
#include "Libraries/SparkFun/SparkFunSi4703.h"
#include "Libraries/SparkFun/SparkFunSi4703.cpp"
#include <Wire.h>
namespace FM_Radio{
// yes this class is simple you just have to make it work electrically
// everything else has been already coded for it to work
int reset_pin = 4;
Si4703_Breakout radio(reset_pin, A4, A5); // add the rest pin and the SAL and SOA pins
int current_volume = 0; // we start at 0 volume
int current_channel = 970; // this is the bbc channel i think
// warper functions
void set_channel(int frequency_mhz_10){
// this function needs to be changed once we figure out how
// the fm module actually works
// frequency_mhz_10 is basically ("frequency in mhz" * 10)
// clamp the channels
if (frequency_mhz_10 < 875) frequency_mhz_10 = 875;
if (frequency_mhz_10 > 1080) frequency_mhz_10 = 1080;
current_channel = frequency_mhz_10; // again we store it because the library doesnt support it
// for some reasons they made the function radio.getChannel
// private which is stuiped dont try to make it public they
// might have a reason for making it private
radio.setChannel(frequency_mhz_10);
}
void set_volume(int volume){
// this sets the volume
// we cap the volume
if (volume < 0) volume = 0;
if (volume > 15) volume = 15;
current_volume = volume; // store it in the current volume
radio.setVolume(volume);
}
void set_mono(bool state){
// this might be better for weak signals
// radio.setMono(state); // this fnuntion needs to be fixed the library is broken for thsi function
}
int get_current_channel(){
// return frequency in frequency_mhz_10 as what you set
//radio.getChannel(); //this function is private do not change it
return current_channel;
}
int get_current_volume(){
// we keep track of the volume our selfs the library
// doesnt provide the current volume since this chip
// doesnt support it "i think"
return current_volume;
}
void init(){
// this will setup the FM module thats about it
Wire.begin(); // init the wire if it is not intiated from other modules
radio.powerOn();
set_volume(current_volume); // set up the volume at 0 at the start
set_channel(current_channel); // set the current channel so we start with a channel
}
void loop(){
// this module doesnt need to be ran in a loop
}
}