Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "TEF6686.h"
- uint16_t frequency;
- byte volume;
- bool isRdsSync;
- char programTypePrevious[17] = " ";
- char programServicePrevious[9];
- char programServiceUnsafePrevious[9];
- char programIdPrevious[4];
- char radioTextPrevious[65];
- TEF6686 radio;
- RdsInfo rdsInfo;
- void setup() {
- delay(1000);
- Serial.begin(115200);
- while (!Serial);
- Serial.println(F("Begin"));
- radio.init();
- radio.powerOn();
- radio.setFrequency(8750);
- frequency = radio.getFrequency();
- //displayInfo();
- radioGui(1);
- }
- void loop() {
- readRds();
- radioGui(0);
- if (Serial.available()) {
- char ch = Serial.read();
- if (ch == 'm') {
- radio.setMute();
- //displayInfo();
- }
- else if (ch == 'n') {
- radio.setUnMute();
- //displayInfo();
- }
- else if (ch == 'p') {
- radio.powerOn();
- //displayInfo();
- }
- else if (ch == 'o') {
- radio.powerOff();
- //displayInfo();
- }
- if (ch == 'u') {
- frequency = radio.seekUp();
- //displayInfo();
- radioGui(true);
- }
- else if (ch == 'd') {
- frequency = radio.seekDown();
- //displayInfo();
- radioGui(true);
- }
- else if (ch == '+') {
- volume += 4;
- if (volume >= 24) volume = 24;
- radio.setVolume(volume);
- displayInfo();
- }
- else if (ch == '-') {
- volume -= 4;
- if (volume < -60) volume = -60;
- radio.setVolume(volume);
- displayInfo();
- }
- else if (ch == 'a') {
- frequency = radio.tuneUp();
- //displayInfo();
- radioGui(true);
- }
- else if (ch == 'b') {
- frequency = radio.tuneDown();
- //displayInfo();
- radioGui(true);
- }
- else if (ch == 'r') {
- radioGui(true);
- }
- }
- }
- void readRds() {
- isRdsSync = radio.readRDS();
- radio.getRDS(&rdsInfo);
- }
- void showPI() {
- if (isNewPi()){
- strcpy(programIdPrevious, rdsInfo.programId);
- }
- Serial.print(rdsInfo.programId);
- }
- bool isNewPi(){
- return (strlen(rdsInfo.programId) == 4) && !strcmp(rdsInfo.programId, programIdPrevious, 4);
- }
- //UNUSED
- void showPTY() {
- if (isNewPty()) {
- Serial.print(rdsInfo.programType);
- strcpy(programTypePrevious, rdsInfo.programType);
- Serial.println();
- }
- }
- //UNUSED
- bool isNewPty() {
- return (isRdsSync == 1) && !strcmp(rdsInfo.programType, programTypePrevious, 16);
- }
- void showPS() {
- if (isNewPs()) {
- strcpy(programServicePrevious, rdsInfo.programService);
- }
- Serial.print(rdsInfo.programService);
- }
- void showPsUnsafe(){
- if (isNewPsUnsafe()){
- strcpy(programServiceUnsafePrevious, rdsInfo.programServiceUnsafe);
- }
- Serial.print(rdsInfo.programServiceUnsafe);
- }
- bool isNewPs() {
- return (strlen(rdsInfo.programService) == 8) && !strcmp(rdsInfo.programService, programServicePrevious, 8);
- }
- bool isNewPsUnsafe() {
- return (strlen(rdsInfo.programServiceUnsafe) == 8) && !strcmp(rdsInfo.programServiceUnsafe, programServiceUnsafePrevious, 8);
- }
- //UNUSED
- void showRadioText() {
- if (isNewRt()){
- Serial.print(rdsInfo.radioText);
- strcpy(radioTextPrevious, rdsInfo.radioText);
- Serial.println();
- }
- }
- //UNUSED
- bool isNewRt() {
- return (isRdsSync == 1) && !strcmp(rdsInfo.radioText, radioTextPrevious, 65);
- }
- bool strcmp(char* str1, char* str2, int length) {
- for (int i = 0; i < length; i++) {
- if (str1[i] != str2[i]) {
- return false;
- }
- }
- return true;
- }
- void displayInfo() {
- delay(10);
- Serial.print(F("Frequency:"));
- Serial.print(frequency);
- Serial.print(F(" Volume:"));
- Serial.println(volume);
- Serial.print(F("Level:"));
- Serial.println(radio.getLevel() / 10);
- Serial.print(F("Stereo:"));
- Serial.println(radio.getStereoStatus());
- }
- void radioGui(bool force){
- if (force || isNewPi() || isNewPs() || isNewPsUnsafe()) {
- //clrscr
- Serial.write(27); // ESC command
- Serial.print("[2J"); // clear screen command
- Serial.write(27);
- Serial.print("[H"); // cursor to home command
- //first line
- Serial.print(F("FM "));
- Serial.print(frequency / 100);
- Serial.print(F("."));
- Serial.print(frequency % 100 / 10);
- Serial.print(F(" MHz "));
- Serial.print(frequency >= 10000 ? F("[ ") : F(" [ "));
- showPS();
- Serial.print(" ]");
- //second line
- Serial.println();
- Serial.print(F("PI: "));
- showPI();
- Serial.print(F(" ( "));
- showPsUnsafe();
- Serial.print(F(" ) "));
- Serial.println();
- Serial.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement