From 91ab8df4216985b8b899b426b58892bfb8df6344 Mon Sep 17 00:00:00 2001 From: Sjef Verhoeven PE5PVB Date: Tue, 13 Jun 2023 23:15:42 +0200 Subject: [PATCH] Work done on ASCII converter. (not ready yet!) List needs to be filled. --- TEF6686_ESP32.ino | 1 + src/TEF6686.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ src/TEF6686.h | 6 +++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/TEF6686_ESP32.ino b/TEF6686_ESP32.ino index fbb8719..51adfe5 100644 --- a/TEF6686_ESP32.ino +++ b/TEF6686_ESP32.ino @@ -8,6 +8,7 @@ #include "src/constants.h" #include "src/language.h" + #define GFXFF 1 #define FONT24 &Aura2CondensedPro_Regular24pt7b #define FONT14 &Aura2CondensedPro_Regular14pt8b diff --git a/src/TEF6686.cpp b/src/TEF6686.cpp index 65190e5..2398967 100644 --- a/src/TEF6686.cpp +++ b/src/TEF6686.cpp @@ -1,4 +1,7 @@ #include "TEF6686.h" +#include +#include + void TEF6686::init(byte TEF) { uint8_t bootstatus; @@ -296,6 +299,10 @@ bool TEF6686::readRDS(bool showrdserrors) if (ps_process == 2) { strcpy(rds.stationName, ps_buffer); + + RDScharConverter(ps_buffer, rds.PStext, sizeof(rds.PStext) / sizeof(wchar_t)); + rds.RDSPS = convertToUTF8(rds.PStext); + for (int i = 0; i < 9; i++) ps_buffer[i] = '\0'; ps_process = 0; rds.hasPS = true; @@ -583,3 +590,38 @@ void TEF6686::tone(uint16_t time, int16_t amplitude, uint16_t frequency) { delay (time); devTEF_Radio_Set_Wavegen(0, 0, 0); } + +String TEF6686::convertToUTF8(const wchar_t* input) { + String output; + while (*input) { + uint16_t unicode = *input; + if (unicode < 0x80) { + output += (char)unicode; + } else if (unicode < 0x800) { + output += (char)(0xC0 | (unicode >> 6)); + output += (char)(0x80 | (unicode & 0x3F)); + } else if (unicode < 0x10000) { + output += (char)(0xE0 | (unicode >> 12)); + output += (char)(0x80 | ((unicode >> 6) & 0x3F)); + output += (char)(0x80 | (unicode & 0x3F)); + } else { + output += (char)(0xF0 | (unicode >> 18)); + output += (char)(0x80 | ((unicode >> 12) & 0x3F)); + output += (char)(0x80 | ((unicode >> 6) & 0x3F)); + output += (char)(0x80 | (unicode & 0x3F)); + } + input++; + } + return output; +} + +void TEF6686::RDScharConverter(const char* input, wchar_t* output, size_t size) { + for (size_t i = 0; i < size - 1; i++) { + char currentChar = input[i]; + switch (currentChar) { + case 0x45: output[i] = L'ë'; break; // Test convert E to ë + default: output[i] = static_cast(currentChar); break; + } + } + output[size - 1] = L'\0'; +} \ No newline at end of file diff --git a/src/TEF6686.h b/src/TEF6686.h index f92c2ad..3af525a 100644 --- a/src/TEF6686.h +++ b/src/TEF6686.h @@ -88,6 +88,8 @@ typedef struct _rds_ { byte stationTypeCode; byte MS; char stationName[9]; + wchar_t PStext[9] = L""; + String RDSPS; char stationText[65]; char stationType[17]; char musicTitle[48]; @@ -172,6 +174,8 @@ class TEF6686 { bool mute; private: + void RDScharConverter(const char* input, wchar_t* output, size_t size); + String convertToUTF8(const wchar_t* input); uint16_t rdsTimeOut = 32768; uint8_t ps_process; uint8_t rt_process; @@ -184,4 +188,4 @@ class TEF6686 { byte rt_timer; byte offsetold; char stationTextBuffer[65]; -}; +}; \ No newline at end of file