API Page
Library Functions
- begin()
- task()
- setCallback()
- tune()
- tuneservice()
- set_service()
- servicevalid()
- vol()
- servicedata()
- time()
- status()
- freq_khz()
- Ensemble[]
- ServiceData[]
Dab.begin()
Dab.begin(band)
Description
Initiate the Dab library. This should normally be called only once.
Parameters
band: the frequency band fm or dab. A value of 0 selects DAB, a value of 1 selects FM (optional); if not specified the band is DAB.
Returns
None
Example
#define BAND_DAB 0#define BAND_FM 1void setup() { //DAB Setup Dab.setCallback(ServiceData); Dab.begin(BAND_FM);}
Dab.task()
Description
Periodic call to Dab library. This should normally be called from within the application loop().
Parameters
None
Returns
None
Example
void loop() { // put your main code here, to run repeatedly: Dab.task();}
Dab.setCallback(callbackfunction)
Description
Specifies the application function to be called when Radio Information is updated. This should normally be called only once
The callback function is called when Service Data such as Radio Text has been updated.
Parameters
callabckfunction: the callback function. Must be in the format void function(void);
Returns
None
Example
//Callback function when Radio Information is updated.void ServiceData(void){ Serial.print(Dab.ServiceData); Serial.print(F("\n"));}void setup() { //DAB Setup Dab.setCallback(ServiceData); Dab.begin();}
Dab.tune(freq_index)
Dab.tune(freq_kHz)
Description
Tunes the receiver to a specified DAB Frequency index (ensemble) or FM frequency.
Parameters
freq_index: the frequency index.
freq_kHz: the FM frequency in 10kHz, e.g. 87500 = 87.5MHz
Returns
None
Example
uint16_t freqkhz = 87500;Dab.tune(freqkhz);Exampleuint8_t freqindex = 0;Dab.tune(freqindex);if(Dab.servicevalid() == true){ Serial.print(Dab.Ensemble); Dab.set_service(0);}Dab.tuneservice(freq, serviceID, CompID)
Description
Tunes the receiver to a specified DAB service when all the parameters for a service are known.
Parameters
freq: the frequency index
serviceID: the ID of the service
CompID: the ID of the service Component
Returns
None
Example
// Function to tune to stored presets
void tunepreset(uint8_t preset){uint8_t freqindex; uint32_t serviceID; uint32_t compID;
freqindex = presetstore[preset].freqindex; serviceID = presetstore[preset].serviceID; compID = presetstore[preset].compID;
Dab.tuneservice(freqindex, serviceID, compID);}
Dab.set_service(index)
Description
Tunes the receiver to a specified DAB service using the service index of the currently tuned ensemble.
Note that services are not always in the same order after a tune to an ensemble.
Parameters
index: the service index
Returns
None
Example
uint8_t freqindex;;for (freq_index = 0; freq_index < DAB_FREQS; freq_index++){ Dab.tune(freqindex); if(Dab.servicevalid() == true) { Serial.print(Dab.Ensemble); //Tune to first service of this ensemble Dab.set_service(0); break; }}
Dab.servicevalid()
Description
Checks if an ensemble contains services.
Parameters
None
Returns
bool: true the service (ensemble) contains services.
Example
uint8_t freqindex;;for (freq_index = 0; freq_index < DAB_FREQS; freq_index++){ Dab.tune(freqindex); //Check is ensemble contains valid services if(Dab.servicevalid() == true) { Serial.print(Dab.Ensemble); Dab.set_service(0); break; }}
Dab.vol(index)
Description
Sets the audio volume
Parameters
index: volume level 0 (muted) to 63 (max). default 63.
Returns
None
Example
void setvolume(uint8_t level){ Dab.vol(level);}////To Do... under construction.