Arduino Radio Library  0.9
A set of Arduino libraries to control diverse FM radio receiver chips in Arduino projects.
radio.h
Go to the documentation of this file.
1 
50 
51 
52 #ifndef __RADIO_h__
53 #define __RADIO_h__
54 
55 #include <arduino.h>
56 #include <Wire.h>
57 
58 // The DEBUG_xxx Macros enable Information to the Serial port.
59 // They can be enabled by setting the _debugEnabled variable to true disabled by using the debugEnable function.
60 // When the code has to be minimized they can be redefined without implementation like:
61 // #define DEBUG_STR(txt) {}
62 
64 #define DEBUG_STR(txt) if (_debugEnabled) { Serial.println(txt); }
65 
67 #define DEBUG_VAL(label, val) if (_debugEnabled) { Serial.print(label); Serial.print(':'); Serial.println(val); }
68 #define DEBUG_VALX(label, val) if (_debugEnabled) { Serial.print(label); Serial.print(':'); Serial.println(val, HEX); }
69 
71 #define DEBUG_FUNC0(fn) if (_debugEnabled) { Serial.print(fn); Serial.println("()"); }
72 
74 #define DEBUG_FUNC1(fn, p1) if (_debugEnabled) { Serial.print(fn); Serial.print('('); Serial.print(p1); Serial.println(')'); }
75 
77 #define DEBUG_FUNC1X(fn, p1) if (_debugEnabled) { Serial.print(fn); Serial.print("(0x"); Serial.print(p1, HEX); Serial.println(')'); }
78 
80 #define DEBUG_FUNC2(fn, p1, p2) if (_debugEnabled) { Serial.print(fn); Serial.print('('); Serial.print(p1); Serial.print(", "); Serial.print(p2); Serial.println(')'); }
81 
83 #define DEBUG_FUNC2X(fn, p1, p2) if (_debugEnabled) { Serial.print(fn); Serial.print("(0x"); Serial.print(p1, HEX); Serial.print(", 0x"); Serial.print(p2, HEX); Serial.println(')'); }
84 
85 
86 // ----- Callback function types -----
87 
89 extern "C" {
90  typedef void(*receiveRDSFunction)(uint16_t block1, uint16_t block2, uint16_t block3, uint16_t block4);
91 }
92 
93 
94 // ----- type definitions -----
95 
98 enum RADIO_BAND {
100 
105 
107 };
108 
109 
112 typedef uint16_t RADIO_FREQ;
113 
114 
116 typedef struct RADIO_INFO {
117  bool active;
118  uint8_t rssi;
119  bool rds;
120  bool tuned;
121  bool mono;
122  bool stereo;
123 };
124 
125 
127 typedef struct AUDIO_INFO {
128  uint8_t volume;
129  bool mute;
130  bool softmute;
131  bool bassBoost;
132 };
133 
134 // ----- common RADIO class definition -----
135 
137 class RADIO {
138 
139 public:
140  const uint8_t MAXVOLUME = 15;
141 
142  RADIO();
143 
144  virtual bool init();
145  virtual void term();
146 
147  // ----- Audio features -----
148 
149  virtual void setVolume(uint8_t newVolume);
150  virtual uint8_t getVolume();
151 
152  virtual void setMute(bool switchOn);
153  virtual bool getMute();
154 
155  virtual void setSoftMute(bool switchOn);
156  virtual bool getSoftMute();
157 
158  virtual void setBassBoost(bool switchOn);
159  virtual bool getBassBoost();
160 
161  // ----- Receiver features -----
162 
163  virtual RADIO_FREQ getMinFrequency();
164  virtual RADIO_FREQ getMaxFrequency();
165  virtual RADIO_FREQ getFrequencyStep();
166 
167  virtual void setBand(RADIO_BAND newBand);
168  virtual RADIO_BAND getBand();
169 
170  virtual void setFrequency(RADIO_FREQ newF);
171  virtual RADIO_FREQ getFrequency(void);
172 
173  virtual void setBandFrequency(RADIO_BAND newBand, RADIO_FREQ newFreq);
174 
175  virtual void seekUp(bool toNextSender = true);
176  virtual void seekDown(bool toNextSender = true);
177 
178  virtual void setMono(bool switchOn);
179  virtual bool getMono();
180 
181  // ----- combined status functions -----
182 
183  virtual void getRadioInfo(RADIO_INFO *info);
184 
185  virtual void getAudioInfo(AUDIO_INFO *info);
186 
187  // ----- Supporting RDS for FM bands -----
188 
189  virtual void checkRDS();
190  virtual void clearRDS();
191  virtual void attachReceiveRDS(receiveRDSFunction newFunction);
192 
193  // ----- Utilitys -----
194 
196  virtual void formatFrequency(char *s, uint8_t length);
197 
198  // ----- debug Helpers send information to Serial port
199 
200  virtual void debugEnable(bool enable = true);
201  virtual void debugRadioInfo();
202  virtual void debugAudioInfo();
203  virtual void debugStatus();
204 
205 protected:
207 
208  uint8_t _volume;
209  bool _bassBoost;
210  bool _mono;
211  bool _mute;
212  bool _softMute;
213 
216 
220 
222 
223  void _printHex4(uint16_t val);
224 
225 private:
226  void int16_to_s(char *s, uint16_t val);
227 
228 }; // class RADIO
229 
230 
231 #endif
232 
233 // End.
bool softmute
Definition: radio.h:130
void int16_to_s(char *s, uint16_t val)
Prints a register as 4 character hexadecimal code with leading zeros.
Definition: radio.cpp:284
bool active
receiving is active.
Definition: radio.h:117
virtual uint8_t getVolume()
Retrieve the current output volume in the range 0..15.
Definition: radio.cpp:59
RADIO_BAND
Definition: radio.h:98
virtual RADIO_BAND getBand()
Retrieve the current band setting.
Definition: radio.cpp:160
Maximal band enumeration value.
Definition: radio.h:106
virtual void attachReceiveRDS(receiveRDSFunction newFunction)
Register a RDS processor function.
Definition: radio.cpp:211
virtual void setBassBoost(bool switchOn)
Control the bass boost mode of the radio chip.
Definition: radio.cpp:69
RADIO()
create a new object from this class.
Definition: radio.cpp:35
virtual RADIO_FREQ getFrequencyStep()
Get resolution of the current selected band.
Definition: radio.cpp:164
RADIO_FREQ _freqHigh
Highest frequency of the current selected band.
Definition: radio.h:218
uint8_t volume
Definition: radio.h:128
FM band 87.5 – 108 MHz (USA, Europe) selected.
Definition: radio.h:101
bool mute
Definition: radio.h:129
virtual void debugEnable(bool enable=true)
Enable sending debug information to the Serial port.
Definition: radio.cpp:245
virtual bool init()
initialize library and the chip.
Definition: radio.cpp:41
virtual bool getMute()
Retrieve the current mute mode setting.
Definition: radio.cpp:104
virtual void debugRadioInfo()
Print out all radio information.
Definition: radio.cpp:251
bool tuned
A stable frequency is tuned.
Definition: radio.h:120
virtual RADIO_FREQ getFrequency(void)
Retrieve the current tuned frequency.
Definition: radio.cpp:161
virtual void term()
terminate all radio functions.
Definition: radio.cpp:48
virtual void setSoftMute(bool switchOn)
Control the softmute mode (mute on low signals) of the radio chip.
Definition: radio.cpp:112
virtual void debugStatus()
Send debug information about actual available chip functionality and other internal things...
Definition: radio.cpp:276
virtual void clearRDS()
Clear RDS data in the attached RDS Receiver by sending 0,0,0,0.
Definition: radio.cpp:203
virtual void seekDown(bool toNextSender=true)
Start a seek downwards from the current frequency.
Definition: radio.cpp:158
uint16_t RADIO_FREQ
Definition: radio.h:112
FM band 76 – 108 MHz (Japan, Worldwide) selected.
Definition: radio.h:102
virtual void debugAudioInfo()
Print out all audio information.
Definition: radio.cpp:264
bool _softMute
Last set softMute effect.
Definition: radio.h:212
virtual void setBandFrequency(RADIO_BAND newBand, RADIO_FREQ newFreq)
Set Band and Frequency in one call.
Definition: radio.cpp:151
uint8_t rssi
Radio Station Strength Information.
Definition: radio.h:118
bool _mono
Last set mono effect.
Definition: radio.h:210
virtual bool getMono()
Retrieve the current mono mode setting.
Definition: radio.cpp:90
virtual void setBand(RADIO_BAND newBand)
Set the current band.
Definition: radio.cpp:128
RADIO_FREQ _freqLow
Lowest frequency of the current selected band.
Definition: radio.h:217
const uint8_t MAXVOLUME
max volume level for all radio implementations.
Definition: radio.h:140
bool rds
RDS information is available.
Definition: radio.h:119
receiveRDSFunction _sendRDS
Registered RDS Function that is called on new available data.
Definition: radio.h:221
KW band selected.
Definition: radio.h:104
virtual void setVolume(uint8_t newVolume)
Control the volume output of the radio chip in the range 0..15.
Definition: radio.cpp:54
virtual void seekUp(bool toNextSender=true)
Start a seek upwards from the current frequency.
Definition: radio.cpp:157
bool _debugEnabled
Set by debugEnable() and controls debugging functionality.
Definition: radio.h:206
virtual void formatFrequency(char *s, uint8_t length)
Format the current frequency for display and printing.
Definition: radio.cpp:218
RADIO_BAND _band
Last set band.
Definition: radio.h:214
uint8_t _volume
Last set volume level.
Definition: radio.h:208
Library to control radio chips in general. This library acts as a base library for the chip specific ...
Definition: radio.h:137
AM band selected.
Definition: radio.h:103
virtual void setMute(bool switchOn)
Control the mute mode of the radio chip.
Definition: radio.cpp:98
bool mono
Mono mode is on.
Definition: radio.h:121
virtual void setMono(bool switchOn)
Control the mono mode of the radio chip.
Definition: radio.cpp:84
RADIO_FREQ _freq
Last set frequency.
Definition: radio.h:215
void(* receiveRDSFunction)(uint16_t block1, uint16_t block2, uint16_t block3, uint16_t block4)
callback function for passing RDS data.
Definition: radio.h:90
bool _bassBoost
Last set bass Boost effect.
Definition: radio.h:209
A structure that contains information about the radio features from the chip.
Definition: radio.h:116
virtual bool getBassBoost()
Retrieve the current bass boost mode setting.
Definition: radio.cpp:76
bool _mute
Last set mute effect.
Definition: radio.h:211
void _printHex4(uint16_t val)
Prints a register as 4 character hexadecimal code with leading zeros.
Definition: radio.cpp:301
virtual RADIO_FREQ getMinFrequency()
Get the minimum frequency of the current selected band.
Definition: radio.cpp:162
virtual RADIO_FREQ getMaxFrequency()
Get the maximum frequency of the current selected band.
Definition: radio.cpp:163
RADIO_FREQ _freqSteps
Resulution of the tuner.
Definition: radio.h:219
virtual void getAudioInfo(AUDIO_INFO *info)
Retrieve some information about the current audio function of the chip.
Definition: radio.cpp:184
bool bassBoost
Definition: radio.h:131
virtual void getRadioInfo(RADIO_INFO *info)
Retrieve some information about the current radio function of the chip.
Definition: radio.cpp:169
virtual void setFrequency(RADIO_FREQ newF)
Start using the new frequency for receiving.
Definition: radio.cpp:146
a structure that contains information about the audio features
Definition: radio.h:127
bool stereo
Stereo audio is available.
Definition: radio.h:122
virtual void checkRDS()
Check if RDS Data is available and good.
Definition: radio.cpp:198
virtual bool getSoftMute()
Retrieve the current soft mute mode setting.
Definition: radio.cpp:118
No band selected.
Definition: radio.h:99