Radio DAB+ Si4684 + ESP32 + ILI9341

Récepteur basé sur la puce Si4684 et ESP32, avec écran tactile pour le choix des stations. Il affiche également les images transmises par les stations ainsi que petits textes (par exemple titre des chansons).

1 -

Deux modes d'affichages sont disponibles : un mode "catalogue des stations cliquable", et un mode "expert" avec des boutons. Dans ce dernier, les stations sont regroupées par multiplex. Quatre multiplex de 13 stations, soit 52 stations sont instantanément disponibles.

2 Le récepteur totalement fonctionnel

Fonctionnel certes, mais encore sur sa platine de prototypage !

3 Le schéma de la carte Si4684 + ESP32_radio

La puce principale, qui est un récepteur DAB+ intégré recevant directement les signaux 170 à 240MHz et qui recrache l'audio et des petites images est au format QFN48 c'est à dire qu'elle mesure 5mm de coté et comporte 4x12=48 contacts aveugles (situés dessous et ne débordant pas sur les côtés) et doit être soudée sur une petite carte, et sans courts-jus! avec une mini plaque chauffante régulée en température et de la soudure en pâte (même pas le volume d'un quart de grain de riz !). Vous êtes encore là ? Très bien, et dites vous que même moi j'ai réussi à le faire alors...

4 Le schéma de la carte ESP32_affi + afficheur ILI9341

Soit deux ESP32 au total, reliés par une simple liaison série UART (TX-RX croisés).

5 Code source en C++ : main_RADIO.cpp

CODE SOURCE en C++
  1. /*
  2. Radio Si4684 - ESP RADIO
  3.  
  4. Cette version utilise la mémoire LittleFS; Voir:
  5. -le dossier 'data' contenant les fichiers nécessaires
  6. -le fichier 'platformio.ini' qui doit contenir la ligne 'board_build.partitions = app_3M.csv.csv'
  7. -le fichier 'app_3M.csv' (def des partitions) qui doit se trouver à côté du fichier platformio.ini
  8.  
  9. Note :
  10. -un dossier 'data' doit se trouver dans le dossier qui contient le fichier 'platformio.ini'
  11. -les fichiers contenus dans 'data' sont à charger dans la mémoire flash de l'ESP
  12. avec l'outil 'Upload FIlsystem Image' de platformio (cliquer sur l'icone "Alien" à gauche)
  13.  
  14.  
  15. */
  16.  
  17. #include <Arduino.h>
  18.  
  19. String version = "2026-12-01";
  20.  
  21.  
  22. #include "FS.h"
  23. #include <LittleFS.h>
  24. #include <base64.h>
  25.  
  26. //#include "SD.h"
  27.  
  28. #include <Wire.h>
  29. #include "SPI.h"
  30. #include "si4684_628.cpp"
  31.  
  32. #define SPI_READ_FREQUENCY 16000000
  33.  
  34. //attention: ces valeurs ne sont pas celles par défaut pour SDA et SCL
  35. //const int GPIO_SDA = 21;
  36. //const int GPIO_SCL = 22;
  37.  
  38. //int8_t num_multiplex = -1; // déplacé dans si4684.h
  39. //int8_t num_station = -1; // déplacé dans si4684.h
  40.  
  41.  
  42.  
  43.  
  44. unsigned long previousMillis = 0;
  45.  
  46.  
  47. DAB radio;
  48.  
  49.  
  50.  
  51. void tune_station(uint8_t n_mult, uint8_t n_sta)
  52. {
  53. Serial.println("tune_station()");
  54. Serial.print("n_mult= "); Serial.println(n_mult);
  55. Serial.print("n_sta= "); Serial.println(n_sta);
  56.  
  57. // uint8_t dabfreq;
  58. //dabfreq = 22; // 211648 MHz, "10B" voir le tableau dans le fichier 'si4684.h'
  59.  
  60. radio.setFreq(n_mult);
  61. delay(500);
  62. //radio.EnsembleInfo();
  63. radio.setService(n_sta); // Start audio for service[_index] in the current ensemble.
  64. }
  65.  
  66.  
  67.  
  68. void setup()
  69. {
  70. Serial.begin(115200);
  71. delay(100);
  72.  
  73. Serial2.begin(921600, SERIAL_8N1, 16, 17); // RX, TX // UART pour liaison filaire entre les deux ESP
  74.  
  75. Serial.println("---------------------------------------------");
  76.  
  77. Serial.println("** Radio DAB+ Si4884 version Silicium628 **");
  78. Serial.println("* ESP32_radio *");
  79.  
  80. delay(1000);
  81.  
  82. Serial.println("---------------------------------------------");
  83.  
  84.  
  85. // Initialisation de LittleFS
  86. if(!LittleFS.begin(true))
  87. {
  88. Serial.println("LittleFS Mount Failed");
  89. return;
  90. }
  91. Serial.println("LittleFS Mount OK");
  92.  
  93. Serial.println("Formatage de LittleFS en cours...");
  94. LittleFS.format();
  95. Serial.println("Formatage OK !");
  96. Serial.println("---------------------------------------------");
  97. // Appel de la fonction : "/" pour la racine, et "3" pour le niveau de profondeur des dossiers
  98. listDir(LittleFS, "/", 3);
  99. Serial.println("---------------------------------------------");
  100.  
  101. const int GPIO_RST = 26;
  102.  
  103. pinMode(GPIO_RST, OUTPUT); // pin pilotant RSTB
  104.  
  105. // RESET
  106. digitalWrite(GPIO_RST, LOW); // bloque le si4684
  107. // Lorsque RSTB est maintenue à la masse (état BAS), le composant est en mode de réinitialisation complète
  108. // et sa consommation est quasi nulle (environ 0,5 µA), bloquant toute activité d'horloge.
  109. delayMicroseconds(100);
  110. digitalWrite(GPIO_RST, HIGH); // debloque le si4684
  111. delayMicroseconds(500);
  112.  
  113. bool result;
  114. uint16_t compte =0;
  115.  
  116. // Bus SPI pins :
  117. // VSPIMOSI=23, MISO=19, CLK=18, SS=15
  118.  
  119. Serial.println("----------------------------");
  120. Serial.println("boot Si4684");
  121.  
  122. compte ++;
  123. result = radio.begin(27); // SSpin
  124. if (result == false)
  125. {
  126. Serial.print(compte);
  127. Serial.println(" - boot HS...");
  128. while(1);
  129. }
  130. else
  131. {
  132. Serial.println("boot ok");
  133. Serial.println(String(radio.getChipID()) + " v" + String(radio.getFirmwareVersion()));
  134. }
  135.  
  136. Serial.println("----------------------------");
  137. delay (1000);
  138.  
  139. // uint8_t dabfreq;
  140. // dabfreq = 22; // 211648 MHz, "10C" voir le tableau dans le fichier 'si4684.h'
  141. // radio.setFreq(dabfreq);
  142. // radio.EnsembleInfo();
  143. // radio.setService(7); // Start audio for service[_index] in the current ensemble.
  144.  
  145. tune_station(22, 1); // (n_multiplex, n_station)
  146.  
  147.  
  148. /*
  149.   auto services = dab_getServiceList();
  150.   for(auto &s: services)
  151.   {
  152.   // Serial2.printf("{\"list\":1,\"id\":%u,\"name\":\"%s\"}\n", s.id, s.label);
  153.   Serial.printf("{\"list\":1,\"id\":%u,\"name\":\"%s\"}\n", s.id, s.label); // vers USB
  154.   }
  155. */
  156.  
  157. }
  158.  
  159.  
  160. // `tuning` is true so we don't fight an in-progress retune.
  161. // voir aussi void 'DAB::EnsembleInfo()' (en fait appelé depuis 'Update()')
  162.  
  163.  
  164.  
  165.  
  166.  
  167. int32_t extract_valeur(String ligne, String label)
  168. {
  169. String s2;
  170. uint32_t valeur = 0;
  171. int p1, p2;
  172.  
  173. p1 = ligne.indexOf('['); p2 = ligne.indexOf(']');
  174. s2 = ligne.substring(p1+1, p2);
  175.  
  176. if (s2 == label)
  177. {
  178. p1 = ligne.indexOf('<'); p2 = ligne.indexOf('>');
  179. s2 = ligne.substring(p1+1, p2);
  180. valeur = s2.toInt();
  181. return valeur;
  182. }
  183. return -1;
  184. }
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191. void envoi_CurrentServiceID_vers_ESP_affi()
  192. {
  193. String s1, s2, s3;
  194. s2 = convert_Dec_To_Hex( LST_services[num_station].ServiceID );
  195.  
  196. s1 += "[serviceID]<";
  197. s1 += s2;
  198. s1 +=">";
  199. Serial2.println(s1); // vers ESP_AFFI
  200. }
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209. void reception() //RECEPTION de l'ESP_AFFI -voir la fonction 'void send__num_station_to_ESP_radio()' in 'main_AFFI.cpp'
  210. {
  211. if(Serial2.available())
  212. {
  213. int32_t n1, n2;
  214. String s1;
  215.  
  216. s1 = Serial2.readStringUntil('\n');
  217.  
  218. Serial.println("-----------------------");
  219. Serial.print("BB s1="); Serial.println(s1);// vers le PC en USB
  220. // -----------------------------------------
  221. n1 = extract_valeur(s1, "multiplex");
  222. if(n1 != -1)
  223. {
  224. num_multiplex = n1;
  225. Serial.print("num_multiplex"); Serial.println(num_multiplex);
  226. }
  227.  
  228. n1 = extract_valeur(s1, "station"); // réception de la station désirée, depuis l'ESP_AFFI
  229. if(n1 != -1)
  230. {
  231. num_station = n1;
  232. Serial.print("num_station"); Serial.println(num_station);
  233. tune_station(num_multiplex, num_station);
  234. }
  235. // -----------------------------------------
  236.  
  237. n1 = extract_valeur(s1, "btLST");
  238. if(n1 == 1)
  239. {
  240. Serial.println("**** recu appui btLST *****");
  241. tune_station(num_multiplex, num_station);
  242. delay(500); // Laisse le temps au Si4684 de verrouiller le signal (Valid)
  243. radio.getServiceList();
  244. radio.getServiceList();
  245.  
  246. Serial.println("envoi <ACQ>");
  247. Serial2.print("<ACQ>"); // vers ESP_AFFI
  248. }
  249.  
  250.  
  251. n1 = extract_valeur(s1, "bt_affi_LST");
  252. if(n1 == 1)
  253. {
  254. Serial.println("**** recu appui bt_affi_LST *****");
  255.  
  256. envoi_LST_services_to_AFFI();
  257. }
  258. delay(300);
  259. }
  260. }
  261.  
  262.  
  263. void envoi_CurrentLabel_vers_ESP_affi()
  264. {
  265. if (send_SLC_en_cours == true) return;
  266.  
  267. String s1, s2;
  268. s2 = LST_services[num_station].Label;
  269.  
  270. //Serial.print("s2= "); Serial.println(s2);
  271.  
  272. s1 += "[label]<";
  273. s1 += s2;
  274. s1 +=">";
  275. Serial2.println(s1); // vers ESP_AFFI
  276. }
  277.  
  278.  
  279. uint8_t compteur2 = 0;
  280.  
  281. void toutes_les_2s()
  282. {
  283. if (send_SLC_en_cours == true) return;
  284.  
  285. compteur2++;
  286. if (compteur2 >=2)
  287. {
  288. compteur2 =0;
  289. envoi_CurrentLabel_vers_ESP_affi();
  290.  
  291. }
  292. else
  293. {
  294. envoi_CurrentServiceID_vers_ESP_affi();
  295. }
  296.  
  297. radio.envoi_rssi_vers_ESP_affi();
  298. }
  299.  
  300.  
  301.  
  302. uint8_t compteur1;
  303.  
  304. void toutes_les_500ms()
  305. {
  306. compteur1++;
  307. if (compteur1 >= 4)
  308. {
  309. compteur1 =0;
  310. toutes_les_2s();
  311. }
  312.  
  313. reception();
  314. }
  315.  
  316.  
  317. void loop()
  318. {
  319. unsigned long currentMillis = millis();
  320.  
  321. radio.ProcessDAB();
  322. //Communication();
  323.  
  324. if (currentMillis - previousMillis >= 500)
  325. {
  326. previousMillis = currentMillis;
  327. toutes_les_500ms();
  328. }
  329.  
  330. }
  331.  

6 si4684_628.cpp

CODE SOURCE en C++
  1. // SI4684 DAB chip driver.
  2.  
  3. /*
  4.  Ce programme est distribué sous la licence publique générale GNU (GNU GPL)
  5.  
  6.  CE fichier si4684_628.cpp et une adaptation (profondement modifié) du fichier si4684_628.cpp publié par Sjef Verhoeven (PE5PVB)
  7.  voir son dépôt ici : https://github.com/PE5PVB
  8.  
  9.  Je remercie vivement PE5PVB pour son travail, fondé sur une profonde étude du datasheet AN649 de la puce si4684
  10.  Ce document AN649 fait 450 pages en anglais, et j'avoue que j'ai utilisé l'IA pour arriver à parfaitement le maitriser.
  11.  
  12.  Le PDF AN629 est disponible ici:
  13.  - https://www.skyworksinc.com/-/media/Skyworks/SL/documents/public/application-notes/an649.pdf
  14.  - https://www.mikrocontroller.net/attachment/257262/AN649_-_Programming_Guide_0.8.pdf
  15.  
  16. */
  17.  
  18. /* --------------------------------
  19.   version : 2026-12-01
  20. ----------------------------------*/
  21.  
  22. #include "si4684_628.h"
  23.  
  24. #include "base64.h"
  25. #include "mbedtls/base64.h"
  26.  
  27. #include <vector>
  28.  
  29. unsigned char SPIbuffer[2048]; // 4096 // shared SPI tx/rx buffer (commands and replies)
  30. bool once = false;
  31.  
  32. unsigned long DataUpdate = 0; // millis() of last EnsembleInfo/ServiceInfo refresh (500 ms throttle)
  33. unsigned long SlideShowRecoverTimer = 0;
  34. bool EnsembleInfoSet;
  35. uint8_t slaveSelectPin;
  36.  
  37. int16_t SignalLevel;
  38. bool send_SLC_en_cours =false;
  39.  
  40. static void SPIwrite(unsigned char* data, uint32_t length);
  41. static void SPIread(uint16_t length);
  42. static void cts(void);
  43. static void Set_Property(uint16_t property, uint16_t value);
  44. static String convertToUTF8(const wchar_t* input);
  45. static String extractUTF8Substring(const String& utf8String, size_t start, size_t length);
  46. static void charConverter(const char* input, wchar_t* output, size_t size);
  47. static int compareCompID(const void* a, const void* b);
  48.  
  49.  
  50.  
  51.  
  52. //This function converts a Decimal number to a Hexadecimal number
  53. String convert_Dec_To_Hex(uint32_t n)
  54. {
  55. String hexNum;
  56. long reste;
  57.  
  58. while (n > 0)
  59. {
  60. reste = n % 16;
  61. n = n / 16;
  62. if (reste < 10) { hexNum = String(reste) + hexNum; }
  63. else
  64. {
  65. switch (reste)
  66. {
  67. case 10: hexNum = "A" + hexNum; break;
  68. case 11: hexNum = "B" + hexNum; break;
  69. case 12: hexNum = "C" + hexNum; break;
  70. case 13: hexNum = "D" + hexNum; break;
  71. case 14: hexNum = "E" + hexNum; break;
  72. case 15: hexNum = "F" + hexNum; break;
  73. }
  74. }
  75. }
  76. return hexNum;
  77. }
  78.  
  79.  
  80. // Fonction récursive pour lister les fichiers et dossiers
  81. void listDir(fs::FS &fs, const char * dirname, uint8_t levels)
  82. {
  83. Serial.printf("Listing directory: %s\n", dirname);
  84.  
  85. File root = fs.open(dirname);
  86. if(!root){
  87. Serial.println("Failed to open directory");
  88. return;
  89. }
  90. if(!root.isDirectory())
  91. {
  92. Serial.println("Not a directory");
  93. return;
  94. }
  95.  
  96. File file = root.openNextFile();
  97. while(file)
  98. {
  99. if(file.isDirectory())
  100. {
  101. Serial.printf(" DIR : %s\n", file.name());
  102. // Si levels > 0, on descend dans le sous-dossier
  103. if(levels)
  104. {
  105. listDir(fs, file.path(), levels - 1);
  106. }
  107. }
  108. else
  109. {
  110. Serial.printf(" FILE: %s SIZE: %d bytes\n", file.name(), file.size());
  111. }
  112. file = root.openNextFile();
  113. }
  114. }
  115.  
  116.  
  117. void DAB::ProcessDAB(void)
  118. {
  119. //if (!tuning)
  120. {
  121. Update();
  122. SignalLevel = getRSSI();
  123. }
  124. }
  125.  
  126.  
  127. void DAB::envoi_rssi_vers_ESP_affi()
  128. {
  129. if (send_SLC_en_cours == true) return;
  130.  
  131. Update();
  132. SignalLevel = getRSSI();
  133. String s1;
  134. s1 += "[rssi]<";
  135. s1 += String(SignalLevel);
  136. s1 +=">";
  137. Serial2.println(s1);
  138. }
  139.  
  140.  
  141. // Read back the chip identifier string (e.g. "Si4684").
  142. char* DAB::getChipID(void)
  143. {
  144. SPIbuffer[0] = 0x08;
  145. SPIbuffer[1] = 0x00;
  146. SPIwrite(SPIbuffer, 2);
  147. cts();
  148. SPIread(23);
  149. itoa((SPIbuffer[10] << 8) + SPIbuffer[9], ChipType + 2, 10);
  150. ChipType[0] = 'S';
  151. ChipType[1] = 'I';
  152. ChipType[6] = '\0';
  153. return ChipType;
  154. }
  155.  
  156. // Return the loaded firmware version string ("major.minor.build").
  157. char* DAB::getFirmwareVersion(void)
  158. {
  159. SPIbuffer[0] = 0x12;
  160. SPIbuffer[1] = 0x00;
  161. SPIwrite(SPIbuffer, 2);
  162. cts();
  163. SPIread(12);
  164. char buffer[5];
  165. itoa(SPIbuffer[5], buffer, 10);
  166. FirmwVersion[0] = buffer[0];
  167. FirmwVersion[1] = '.';
  168. itoa(SPIbuffer[6], buffer, 10);
  169. FirmwVersion[2] = buffer[0];
  170. FirmwVersion[3] = '.';
  171. itoa(SPIbuffer[7], buffer, 10);
  172. FirmwVersion[4] = buffer[0];
  173. FirmwVersion[5] = '\0';
  174. return FirmwVersion;
  175. }
  176.  
  177. // Sanity check: query the chip status. Returns true if it looks hung
  178. // (caller responds by reinitialising the chip via doRecovery()).
  179. bool DAB::panic(void)
  180. {
  181. SPIbuffer[0] = 0x09;
  182. SPIbuffer[1] = 0x00;
  183. SPIwrite(SPIbuffer, 2);
  184. cts();
  185. SPIread(6);
  186. if (SPIbuffer[5] == 0x09)
  187. {
  188. return true;
  189. }
  190. return false;
  191. }
  192.  
  193.  
  194. uint16_t DAB::getRSSI(void)
  195. {
  196. SPIbuffer[0] = 0xE5;
  197. SPIbuffer[1] = 0x00;
  198. SPIwrite(SPIbuffer, 2);
  199. cts();
  200. SPIread(6);
  201. int16_t rssi = static_cast<int16_t>((static_cast<int32_t>(SPIbuffer[5] + (SPIbuffer[6] << 8)) * 10) / 256);
  202. if (rssi > 1200) rssi = 1200;
  203. if (rssi < -1000) rssi = -1000;
  204. return rssi;
  205. }
  206.  
  207.  
  208.  
  209.  
  210. // Set the chip's internal audio attenuator (the headphone amp does the
  211. // fine volume; this is mostly a coarse control).
  212. void DAB::vol(uint8_t vol)
  213. {
  214. Set_Property(0x0300, (vol & 0x3F));
  215. }
  216.  
  217.  
  218. // Low-level SPI command write: pulls CS low, transfers `length` bytes,
  219. // then releases CS. No reply data is captured here — use SPIread() after cts()
  220. // when the chip needs to return data.
  221. static void SPIwrite(unsigned char* data, uint32_t length)
  222. {
  223. SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
  224. digitalWrite(slaveSelectPin, LOW);
  225. SPI.transfer(data, length);
  226. digitalWrite(slaveSelectPin, HIGH);
  227. SPI.endTransaction();
  228. }
  229.  
  230. // Low-level SPI reply read: clocks `length` dummy bytes out and stores the
  231. // returned bytes back into SPIbuffer. Expects cts() to have already been
  232. // called so the chip is ready to respond.
  233. static void SPIread(uint16_t length)
  234. {
  235. for (uint16_t i = 0; i < length + 1; i++) SPIbuffer[i] = 0;
  236. SPIwrite(SPIbuffer, length + 1);
  237. }
  238.  
  239. // SET_PROPERTY (cmd 0x13): write one of the chip's internal properties such
  240. // as sample rate, audio output config, FIC interrupt source. See AN649 §6.
  241. static void Set_Property(uint16_t property, uint16_t value)
  242. {
  243. SPIbuffer[0] = 0x13; // cmd 0x13 SET_PROPERTY Sets the value of a property
  244. SPIbuffer[1] = 0x00;
  245. SPIbuffer[2] = property & 0xFF;
  246. SPIbuffer[3] = (property >> 8) & 0xFF;
  247. SPIbuffer[4] = value & 0xFF;
  248. SPIbuffer[5] = (value >> 8) & 0xFF;
  249. SPIwrite(SPIbuffer, 6);
  250. cts();
  251. }
  252.  
  253.  
  254. static void cts(void)
  255. {
  256. bool timeout = false;
  257. uint16_t countdown = 200;
  258.  
  259. while (!(SPIbuffer[1] & 0x80))
  260. {
  261. delay(2);
  262. memset(SPIbuffer, 0, 5);
  263. SPIwrite(SPIbuffer, 5);
  264.  
  265. countdown--;
  266. if (countdown == 0)
  267. {
  268. timeout = true;
  269. break;
  270. }
  271. }
  272.  
  273. if (SPIbuffer[1] & 0x40)
  274. {
  275. memset(SPIbuffer, 0, 5);
  276. }
  277.  
  278. if (timeout && sizeof(SPIbuffer) > 5)
  279. {
  280. SPIbuffer[5] |= (1 << 7);
  281. }
  282. }
  283.  
  284.  
  285. // Cold-start sequence per AN649:
  286. // 1. POWER_UP - configure clock + crystal
  287. // 2. LOAD_INIT + HOST_LOAD - upload the patch + firmware blobs from flash
  288. // 3. BOOT - jump to firmware
  289. // 4. Configure DAB-specific properties (sample rate, audio output, FIC etc.)
  290. // Returns true once the chip reports the DAB image is running.
  291.  
  292. /*
  293.   La broche SSB (Chip Select) : L'ESP32 doit maintenir la broche SSB (Chip Select) à l'état BAS
  294.   pendant toute la durée de la trame SPI
  295.   Si le signal SSB ne descend pas, le Si4684 n'écoute pas le bus.
  296. */
  297.  
  298. bool DAB::begin(uint8_t SSpin)
  299. {
  300. Serial.println("A - DAB::begin()");
  301.  
  302. memset(SPIbuffer, 0, sizeof(SPIbuffer));
  303. if (LittleFS.exists("/temp.img")) LittleFS.remove("/temp.img");
  304.  
  305. slaveSelectPin = SSpin;
  306. pinMode(slaveSelectPin, OUTPUT); // Configure SPI
  307. digitalWrite(slaveSelectPin, HIGH);
  308. delay(3);
  309. SPI.begin(18, 19, 23, SSpin); // CLK, MISO, MOSI, SS ; SPI.begin(14, 16, 13, SSpin);
  310. delay(3);
  311.  
  312. Serial.println("A - GET_SYS_STATE");
  313.  
  314. SPIbuffer[0] = 0x09; // GET_SYS_STATE
  315. SPIbuffer[1] = 0x00;
  316. SPIwrite(SPIbuffer, 2);
  317. cts();
  318. SPIread(6);
  319.  
  320. for(int n=0; n<6; n++)
  321. {
  322. Serial.print(SPIbuffer[n]);
  323. Serial.println("");
  324. }
  325. Serial.println("");
  326.  
  327. bool result;
  328. if (SPIbuffer[1] != 0x80) // 0x80 = 128 décimal
  329. {
  330. result = false; Serial.println("result = false");
  331. }
  332. else
  333. {
  334. result = true; Serial.println("result = true");
  335. }
  336.  
  337. if (SPIbuffer[1] != 2)
  338. {
  339. Serial.println("B - POWER_UP");
  340.  
  341. SPIbuffer[0] = 0x01; // POWER_UP (Power-up the device and set system settings.)
  342. SPIbuffer[1] = 0x00;
  343. SPIbuffer[2] = 0x17;
  344. SPIbuffer[3] = 0x48;
  345. SPIbuffer[4] = 0x00;
  346. SPIbuffer[5] = 0xf8;
  347. SPIbuffer[6] = 0x24;
  348. SPIbuffer[7] = 0x01;
  349. SPIbuffer[8] = 0x1F;
  350. SPIbuffer[9] = 0x10;
  351. SPIbuffer[10] = 0x00;
  352. SPIbuffer[11] = 0x00;
  353. SPIbuffer[12] = 0x00;
  354. SPIbuffer[13] = 0x18;
  355. SPIbuffer[14] = 0x00;
  356. SPIbuffer[15] = 0x00;
  357. SPIwrite(SPIbuffer, 16);
  358. cts();
  359. delayMicroseconds(20);
  360.  
  361. // LOAD_INIT
  362.  
  363. Serial.println("C - first LOAD_INIT ");
  364. SPIbuffer[0] = 0x06; // LOAD_INIT (Prepares the bootloader to receive a new image.)
  365. SPIbuffer[1] = 0x00;
  366. SPIwrite(SPIbuffer, 2);
  367. cts();
  368.  
  369. Serial.println("D - Write bootloader");
  370.  
  371. uint32_t index = 0;
  372. for (uint16_t i = 0; index < sizeof(rom_patch_016); i++) // Write bootloader
  373. {
  374. SPIbuffer[0] = 0x04;
  375. SPIbuffer[1] = 0x00;
  376. SPIbuffer[2] = 0x00;
  377. SPIbuffer[3] = 0x00;
  378. for (uint16_t j = 4; j < 128 && index < sizeof(rom_patch_016); j++, index++)
  379. {
  380. SPIbuffer[j] = pgm_read_byte_near(rom_patch_016 + index);
  381. }
  382. SPIwrite(SPIbuffer, 128);
  383. cts();
  384. }
  385.  
  386.  
  387. Serial.println("D - second LOAD_INIT ");
  388. delay(4);
  389. SPIbuffer[0] = 0x06; // LOAD_INIT (Prepares the bootloader to receive a new image.)
  390. SPIbuffer[1] = 0x00;
  391. SPIwrite(SPIbuffer, 2);
  392. cts();
  393.  
  394. index = 0;
  395. uint16_t i = 0;
  396.  
  397. uint16_t compte1;
  398. Serial.println("E - write firmware ");
  399. while (index < sizeof(firmware)) // ce fichier de 3.2MB en ascii comprend en fait 517kB (en binaire)
  400. {
  401. compte1++;
  402. //Serial.print(compte1); Serial.print(" - ");
  403. Serial.print(".");
  404. //Serial.println(index);
  405. SPIbuffer[0] = 0x04;
  406. SPIbuffer[1] = 0x00;
  407. SPIbuffer[2] = 0x00;
  408. SPIbuffer[3] = 0x00;
  409. for (i = 4; (i < 2048) && (index < sizeof(firmware)); i++)
  410. {
  411. SPIbuffer[i] = pgm_read_byte_near(firmware + index);
  412. index++;
  413. }
  414. SPIwrite(SPIbuffer, i);
  415. cts();
  416. }
  417. Serial.println("");
  418. Serial.print("total = "); Serial.print(index/1000); Serial.println(" kB ");
  419. Serial.println("");
  420.  
  421. Serial.println("E - BOOT");
  422.  
  423. SPIbuffer[0] = 0x07; // BOOT (Boots the image currently loaded in RAM.)
  424. SPIbuffer[1] = 0x00;
  425. SPIwrite(SPIbuffer, 2);
  426. cts();
  427.  
  428. Serial.println("F - Write DAB frequencyplan");
  429. SPIbuffer[0] = 0xB8; // Write DAB frequencyplan
  430. SPIbuffer[1] = 0x26;
  431. SPIbuffer[2] = 0x00;
  432. SPIbuffer[3] = 0x00;
  433. for (i = 0; i < sizeof(DABfrequencyTable_DAB) / sizeof(DABFrequencyLabel_DAB); i++)
  434. {
  435. SPIbuffer[4 + (i * 4)] = DABfrequencyTable_DAB[i].frequency & 0xFF;
  436. SPIbuffer[5 + (i * 4)] = (DABfrequencyTable_DAB[i].frequency >> 8) & 0xFF;
  437. SPIbuffer[6 + (i * 4)] = (DABfrequencyTable_DAB[i].frequency >> 16) & 0xFF;
  438. SPIbuffer[7 + (i * 4)] = (DABfrequencyTable_DAB[i].frequency >> 24) & 0xFF;
  439. }
  440. SPIwrite(SPIbuffer, 4 + (38 * 4));
  441. cts();
  442.  
  443. Serial.println("G - Set properties");
  444.  
  445. Set_Property(0x0200, 0x8000); // Set properties
  446. Set_Property(0x0202, 0x1600);
  447. Set_Property(0x0800, 0x0003);
  448. Set_Property(0x1710, 0xFC4A);
  449. Set_Property(0x1711, 0x00F8);
  450. Set_Property(0x8100, 0x0001);
  451. Set_Property(0x8101, 0x0064);
  452. Set_Property(0xB200, 0x0000);
  453. Set_Property(0xB201, 0x0080);
  454. Set_Property(0xB301, 0x0000);
  455. Set_Property(0xB302, 0x0000);
  456. Set_Property(0xB303, 0x0000);
  457. Set_Property(0xB400, 0x0097);
  458. Set_Property(0xB401, 0x0002);
  459. Set_Property(0xB500, 0x0000);
  460. }
  461. Serial.println("H - Fin du DAB::begin()");
  462.  
  463. return result;
  464. }
  465.  
  466.  
  467. /*
  468. Query DAB ensemble information (RSSI, CNR, FIC quality, sample/lock state,
  469. EID, ensemble label) and populate the public fields. Also fetches the
  470. service list when freshly locked. Called periodically from Update().
  471.  
  472. Interroge les informations d’ensemble DAB (RSSI, CNR, qualité FIC,
  473. état de l’échantillon/verrouillage, EID, étiquette d’ensemble)
  474. et renseigne les champs publics. Récupère également la liste des services lorsqu’elle vient d’être verrouillée.
  475. Appelé périodiquement depuis Update()
  476. */
  477.  
  478. void DAB::EnsembleInfo(void) // appelé toutes les 500ms par 'void DAB::Update(void)'
  479. {
  480. //Serial.println("DAB::EnsembleInfo()");
  481.  
  482. static bool lastSignalLock = false;
  483. static uint8_t lastFic = 0;
  484.  
  485. SPIbuffer[0] = 0xB2; // Get signalstatus
  486. SPIbuffer[1] = 0x09;
  487. SPIwrite(SPIbuffer, 2);
  488. cts();
  489. SPIread(19);
  490. fic = SPIbuffer[9];
  491. cnr = SPIbuffer[10];
  492. if (fic > 0) signallock = true; // bloqueur
  493. else signallock = false;
  494.  
  495. // Log signal changes
  496. if (signallock != lastSignalLock)
  497. {
  498. lastSignalLock = signallock;
  499. }
  500.  
  501. lastFic = fic;
  502. if (signallock)
  503. {
  504.  
  505. // Serial.println("Get servicelist");
  506.  
  507. SPIbuffer[0] = 0x80; // Get servicelist
  508. SPIbuffer[1] = 0x00;
  509. SPIwrite(SPIbuffer, 2);
  510. cts();
  511. SPIread(8);
  512.  
  513. if (SPIbuffer[5] + (SPIbuffer[6] << 8) + 6 < sizeof(SPIbuffer))
  514. {
  515. SPIread(SPIbuffer[5] + (SPIbuffer[6] << 8) + 6);
  516. uint8_t numberofcomponents;
  517.  
  518. numberofservices = SPIbuffer[9];
  519.  
  520. //Serial.print("numberofservices"); Serial.println(numberofservices);
  521.  
  522. /* à voir...
  523.   if (numberofservices > sizeof(service) / sizeof(DABService))
  524.   {
  525.   clearData(); // Handle overflow when signal is crappy
  526.   numberofservices = 0;
  527.   return;
  528.   }
  529. */
  530. uint16_t offset = 13;
  531.  
  532. for (uint8_t i = 0; i < numberofservices; i++)
  533. {
  534.  
  535. /* à voir...
  536.  
  537.   if (i >= sizeof(service) / sizeof(DABService))
  538.   {
  539.   clearData(); // Handle overflow when signal is crappy
  540.   numberofservices = 0;
  541.   return;
  542.   }
  543. */
  544. serviceID = SPIbuffer[offset + 3];
  545. serviceID <<= 8;
  546. serviceID += SPIbuffer[offset + 2];
  547. serviceID <<= 8;
  548. serviceID += SPIbuffer[offset + 1];
  549. serviceID <<= 8;
  550. serviceID += SPIbuffer[offset];
  551. componentID = 0;
  552.  
  553. numberofcomponents = SPIbuffer[offset + 5] & 0x0F;
  554.  
  555. char label_char[17];
  556.  
  557. for (uint16_t j = 0; j < 16; j++) label_char[j] = SPIbuffer[offset + 8 + j];
  558.  
  559. for (int16_t j = 15; j >= 0; j--)
  560. {
  561. if (label_char[j] == ' ' && label_char[j + 1] == '\0')
  562. {
  563. label_char[j] = '\0';
  564. }
  565. else { break; }
  566. }
  567.  
  568. // LST_services[i].Label =(String)label_char;
  569.  
  570. for(int k=0; k<17; k++)
  571. {
  572. LST_services[i].Label[k] = label_char[k];
  573. }
  574.  
  575.  
  576. offset += 24;
  577.  
  578. for (uint16_t j = 0; j < numberofcomponents; j++)
  579. {
  580. if (j == 0)
  581. {
  582. componentID = SPIbuffer[offset + 3];
  583. componentID <<= 8;
  584. componentID += SPIbuffer[offset + 2];
  585. componentID <<= 8;
  586. componentID += SPIbuffer[offset + 1];
  587. componentID <<= 8;
  588. componentID += SPIbuffer[offset];
  589. }
  590. offset += 4;
  591. }
  592. LST_services[i].ServiceID = serviceID;
  593. LST_services[i].CompID = componentID;
  594. }
  595.  
  596. if (numberofservices > 0)
  597. {
  598. qsort(LST_services, numberofservices, sizeof(DABService), compareCompID);
  599. if (CurrentServiceID != LST_services[ServiceIndex].ServiceID)
  600. {
  601. for (byte x = 0; x < numberofservices; x++)
  602. {
  603. if (CurrentServiceID == LST_services[x].ServiceID)
  604. {
  605. ServiceIndex = x;
  606. break;
  607. }
  608. }
  609. }
  610. }
  611.  
  612. for (byte i = 0; i < 5; i++) SPIbuffer[i] = 0;
  613. SPIwrite(SPIbuffer, 5);
  614.  
  615. SPIbuffer[0] = 0xB4; // DAB_GET_ENSEMBLE_INFO - Gets information about the current ensemble
  616. SPIbuffer[1] = 0x00;
  617. SPIwrite(SPIbuffer, 2);
  618. cts();
  619. SPIread(26);
  620.  
  621. uint16_t eidRaw = ((uint16_t)SPIbuffer[6] << 8) | SPIbuffer[5];
  622. if (eidRaw != 0x0000 && eidRaw != 0xFFFF)
  623. {
  624. EnsembleInfoSet = true;
  625.  
  626. // Only set EID/EnsembleLabel/ECC once after tuning; they don't change on the same frequency
  627. // This prevents corrupted data during marginal signal from overwriting valid values
  628. if (EID[0] == '\0' || EnsembleLabel[0] == '\0')
  629. {
  630. EID[2] = (SPIbuffer[5] & 0xF0) >> 4;
  631. EID[3] = (SPIbuffer[5] & 0x0F);
  632. EID[0] = (SPIbuffer[6] & 0xF0) >> 4;
  633. EID[1] = (SPIbuffer[6] & 0x0F);
  634. EID[4] = '\0';
  635.  
  636. for (int i = 0; i < 4; i++)
  637. {
  638. if (EID[i] < 10)
  639. {
  640. EID[i] += '0';
  641. } else
  642. {
  643. EID[i] += 'A' - 10;
  644. }
  645. }
  646. for (uint8_t i = 0; i < 16 && SPIbuffer[7 + i] != '\0'; i++)
  647. {
  648. EnsembleLabel[i] = static_cast<char>(SPIbuffer[7 + i]);
  649. }
  650. EnsembleLabel[16] = '\0';
  651.  
  652. // supprime les espaces inutiles à la fin
  653. for (int8_t i = 15; i >= 0; i--)
  654. {
  655. if (EnsembleLabel[i] == ' ' && EnsembleLabel[i + 1] == '\0')
  656. {
  657. EnsembleLabel[i] = '\0';
  658. }
  659. else { break; }
  660. }
  661. Serial.print("EnsembleLabel= "); Serial.println(EnsembleLabel); // "Métropolitain 2" (nom du Multiplex)
  662.  
  663. EnsembleLabelCharset = SPIbuffer[24];
  664. }
  665. if (ensembleEcc == 0 && SPIbuffer[23] != 0)
  666. {
  667. ensembleEcc = SPIbuffer[23];
  668. }
  669. }
  670. else
  671. {
  672. EnsembleInfoSet = false;
  673. }
  674. }
  675. SPIbuffer[0] = 0xBC;
  676. SPIbuffer[1] = 0x00;
  677. SPIwrite(SPIbuffer, 2);
  678. cts();
  679. SPIread(11);
  680.  
  681. if (!bitRead(SPIbuffer[1], 6))
  682. {
  683. Year = SPIbuffer[5] + ((uint16_t)SPIbuffer[6] << 8);
  684. Months = SPIbuffer[7];
  685. Days = SPIbuffer[8];
  686. /*
  687. Serial.print(Year); Serial.print('-');
  688. Serial.print(Months); Serial.print('-');
  689. Serial.print(Days);
  690. Serial.println("");
  691. */
  692. Hours = SPIbuffer[9];
  693. Minutes = SPIbuffer[10];
  694. Seconds = SPIbuffer[11];
  695. }
  696. }
  697. }
  698.  
  699. // Note: MOT = Multimedia Object Transfer (voir AN649.pdf)
  700. /*
  701. MOT est transmis en tant que segments MOT au niveau du groupe de données.
  702. Par conséquent, les données du MOT seront présentées comme défini dans 5.3.3 de [1]
  703. en tant qu’objets MOT segmentés. Veuillez également consulter la définition
  704. du transport MOT pour le DAB dans [3].
  705. Le Si468x transmettra les groupes de données MOT dans l’ordre d’arrivée.
  706. L’assemblage des groupes de données MOT en segments MOT ne doit pas être
  707. effectué par le Si468x, et laissé au logiciel décodeur MOT sur l’hôte.
  708. Le DAB MSC peut transporter plus d’un objet MOT à la fois.
  709. Pour assembler des segments MOT, l’hôte doit joindre uniquement
  710. les messages d’application MOT
  711. associés au service identifié par l’identifiant de service et l’identifiant de composant.
  712. */
  713.  
  714.  
  715. /*
  716. Pull one bloc of service-data from the chip. Each bloc is either:
  717.  (Extrait un bloc de données de service de la puce. Chaque bloc est soit :)
  718.  - Dynamic Label / Radiotext (group flag 0x02) → copy into ServiceData
  719.  - MOT slideshow header (0x80 0x00 0x12 ...) → record total length, TID;
  720. (TID fait référence à transport ID)
  721.  - MOT slideshow segment (0x00/0x80 ... ) → memcpy into slideshowSegBuf
  722.  Called on every Update() while the receiver has signal lock.
  723. */
  724.  
  725.  
  726. void DAB::getServiceData(void)
  727. {
  728. uint32_t byte_count = 0;
  729. uint32_t byte_number = 0;
  730.  
  731. if (bitRead(SPIbuffer[1], 4))
  732. {
  733. SPIbuffer[0] = 0x84;
  734. SPIbuffer[1] = 0x01;
  735. SPIwrite(SPIbuffer, 2);
  736. cts();
  737. SPIread(20);
  738.  
  739. if ((SPIbuffer[19] + (SPIbuffer[20] << 8)) + 24 < sizeof(SPIbuffer))
  740. {
  741. if ((SPIbuffer[19] + (SPIbuffer[20] << 8)) > 0)
  742. {
  743. cts();
  744. SPIread((SPIbuffer[19] + (SPIbuffer[20] << 8)) + 24);
  745. byte_count = SPIbuffer[19] + (SPIbuffer[20] << 8);
  746.  
  747. // Read Radiotext
  748. if (((SPIbuffer[8] >> 6) & 0x03) == 0x02 && !((SPIbuffer[25] & 0x10) == 0x10))
  749. {
  750. for (byte_number = 0; byte_number < byte_count; byte_number++) ServiceData[byte_number]
  751. = (char)SPIbuffer[27 + byte_number];
  752. ServiceData[byte_number] = '\0';
  753.  
  754. if (String(ServiceData) != memo_ServiceData)
  755. {
  756. memo_ServiceData = ServiceData;
  757. Serial.print("ServiceData= "); Serial.println(String(ServiceData ));
  758.  
  759. String s1, s2;
  760. s2 = String(ServiceData);
  761. s1 += "[serviceData]<";
  762. s1 += s2;
  763. s1 +=">";
  764. Serial.println(s1);
  765. Serial2.println(s1); // vers ESP_AFFI
  766.  
  767. }
  768.  
  769. }
  770.  
  771. // Read Slideshow header - extract total length
  772. else if (((SPIbuffer[8] >> 6) & 0x03) == 0x01 && SPIbuffer[27]
  773. == 0x80 && SPIbuffer[28] == 0x00 && SPIbuffer[29] == 0x12 && byte_count < 200)
  774. {
  775. uint16_t transportID = (SPIbuffer[30] << 8) | SPIbuffer[31];
  776. uint32_t newLength = (((uint16_t)SPIbuffer[35] << 12)
  777. | ((uint16_t)SPIbuffer[36] << 4) | ((uint16_t)SPIbuffer[37] >> 4)) & 0x00FFFF;
  778.  
  779. if (newLength > 0 && newLength != SlideShowLengthOld)
  780. //if (newLength > 0 ) // modif perso - remplace la ligne
  781. //ci-dessus afin de forcer l'affichage de la même image...
  782. {
  783. if (SlideShowLength == 0)
  784. {
  785. // First header - set length and lock onto this image
  786. SlideShowLength = newLength;
  787.  
  788. // If segments were collected with a different TID, discard them
  789. /* if (SlideShowTransportID != 0 && transportID != SlideShowTransportID)
  790.   {
  791.   if (S_Debug) Serial.printf("Header TID=%u != segments TID=%u,
  792.   discarding old segments\n", transportID, SlideShowTransportID);
  793.   clearSegmentBuffer();
  794.  
  795.   SlideShowLength = 0; // ajout IA
  796.  
  797.   SlideShowByteCounter = 0;
  798.   SlideShowHighestSegment = 0;
  799.   SlideShowTotalSegments = 0;
  800.   SlideShowInit = false;
  801.   }
  802. */
  803. SlideShowTransportID = transportID;
  804. SlideShowNew = true;
  805. SlideShowInit = true;
  806. if (S_Debug) Serial.printf("Header received, length=%u, bytes so far=%u, TID=%u\n", SlideShowLength, SlideShowByteCounter, transportID);
  807.  
  808. if (SlideShowByteCounter >= SlideShowLength && allSegmentsReceived())
  809. {
  810. SlideShowTotalSegments = SlideShowHighestSegment + 1;
  811. if (S_Debug) Serial.printf("All segments ready after header, assembling %u segments\n", SlideShowTotalSegments);
  812. assembleSlideshow();
  813. }
  814. }
  815. else if (SlideShowLength == newLength)
  816. {
  817. // Same image, new carousel cycle - update TID to accept segments again
  818. SlideShowTransportID = transportID;
  819. if (S_Debug) Serial.printf("Header confirmed, length=%u, bytes so far=%u, TID=%u\n", SlideShowLength, SlideShowByteCounter, transportID);
  820.  
  821. if (SlideShowByteCounter >= SlideShowLength && allSegmentsReceived())
  822. {
  823. SlideShowTotalSegments = SlideShowHighestSegment + 1;
  824. if (S_Debug) Serial.printf("All segments ready after header, assembling %u segments\n", SlideShowTotalSegments);
  825. assembleSlideshow();
  826. }
  827. }
  828. else
  829. {
  830. // Different length - other carousel image, ignore
  831. if (S_Debug) Serial.printf("Ignoring header length=%u (collecting %u), TID=%u\n", newLength, SlideShowLength, transportID);
  832. }
  833. }
  834.  
  835. else if (newLength > 0 && SlideShowInit)
  836. {
  837. // Same image as already displayed — discard collected segments
  838. if (S_Debug) Serial.printf("Same image (%u bytes), discarding collection\n", newLength);
  839. clearSegmentBuffer();
  840. SlideShowTransportID = 0;
  841. SlideShowByteCounter = 0;
  842. SlideShowHighestSegment = 0;
  843. SlideShowTotalSegments = 0;
  844. SlideShowInit = false;
  845. }
  846.  
  847. // Read Slideshow packets - store each segment (works with or without header)
  848. }
  849. else if (((SPIbuffer[8] >> 6) & 0x03) == 0x01 && (SPIbuffer[27] == 0x00
  850. || SPIbuffer[27] == 0x80) && SPIbuffer[29] == 0x12)
  851. {
  852. uint16_t transportID = (SPIbuffer[30] << 8) | SPIbuffer[31];
  853. uint8_t segmentNumber = SPIbuffer[28];
  854.  
  855. // Check Transport ID
  856. if (SlideShowTransportID == 0)
  857. {
  858. SlideShowTransportID = transportID;
  859. if (S_Debug) Serial.printf("Transport ID set to %u\n", transportID);
  860. }
  861. else if (transportID != SlideShowTransportID)
  862. {
  863. // Different carousel object - skip this segment, don't reset
  864. if (S_Debug) Serial.printf("Skipping segment %u, TID=%u (collecting TID=%u)\n", segmentNumber, transportID, SlideShowTransportID);
  865. }
  866.  
  867. if (transportID == SlideShowTransportID)
  868. {
  869. uint8_t byteIndex = segmentNumber / 8;
  870. uint8_t bitIndex = segmentNumber % 8;
  871.  
  872. // Check if we already have this segment
  873. if (!(SlideShowSegmentBitmap[byteIndex] & (1 << bitIndex)))
  874. {
  875. uint16_t dataLen = byte_count - 11;
  876.  
  877. // Bounds-check: discard segments that don't fit our RAM buffer
  878. if (segmentNumber < SLS_MAX_SEGMENTS && dataLen <= SLS_MAX_SEG_SIZE)
  879. {
  880. memcpy(&slideshowSegBuf[segmentNumber * SLS_MAX_SEG_SIZE], &SPIbuffer[34], dataLen);
  881. slideshowSegLen[segmentNumber] = dataLen;
  882.  
  883. // Mark segment as received and update highest seen
  884. SlideShowSegmentBitmap[byteIndex] |= (1 << bitIndex);
  885. SlideShowByteCounter += dataLen;
  886. if (segmentNumber > SlideShowHighestSegment)
  887. {
  888. SlideShowHighestSegment = segmentNumber;
  889. }
  890. SlideShowInit = true;
  891. SlideShowLastActivity = millis();
  892. if (S_Debug) Serial.printf("Segment %u saved, %u bytes (total %u/%u) TID=%u\n", segmentNumber, dataLen, SlideShowByteCounter, SlideShowLength, transportID);
  893.  
  894. // Check if complete - using byte count + all segments when we have header length
  895. if (SlideShowLength > 0 && SlideShowByteCounter >= SlideShowLength && allSegmentsReceived())
  896. {
  897. SlideShowTotalSegments = SlideShowHighestSegment + 1;
  898. if (S_Debug) Serial.printf("Complete by byte count, assembling %u segments\n", SlideShowTotalSegments);
  899. assembleSlideshow();
  900. }
  901. }
  902. else
  903. {
  904. if (S_Debug) Serial.printf("Drop seg %u (dataLen=%u out of buffer bounds)\n", segmentNumber, dataLen);
  905. }
  906. }
  907. else if (segmentNumber == 0 && SlideShowLength == 0 && SlideShowHighestSegment > 0)
  908. {
  909. // Segment 0 received again (duplicate) - a full broadcast cycle has completed
  910. if (S_Debug) Serial.printf("Segment 0 repeated, highest=%u\n", SlideShowHighestSegment);
  911. if (allSegmentsReceived())
  912. {
  913. // Check if this is the same image we already displayed
  914.  
  915. if (SlideShowLengthOld > 0 && SlideShowByteCounter == SlideShowLengthOld)
  916. {
  917. if (S_Debug) Serial.printf("Same image detected (%u bytes), skipping\n", SlideShowByteCounter);
  918. clearSegmentBuffer();
  919. SlideShowTransportID = 0;
  920. SlideShowByteCounter = 0;
  921. SlideShowHighestSegment = 0;
  922. SlideShowTotalSegments = 0;
  923. SlideShowInit = false;
  924. }
  925. else
  926.  
  927. {
  928. SlideShowTotalSegments = SlideShowHighestSegment + 1;
  929. if (S_Debug) Serial.printf("Complete by cycle detection, assembling %u segments\n", SlideShowTotalSegments);
  930. assembleSlideshow();
  931. }
  932. }
  933. }
  934. }
  935. }
  936. }
  937. }
  938. }
  939. }
  940.  
  941.  
  942.  
  943.  
  944. // Garbage-collect helper for BufferSlideShow: find the oldest /<id>.img file
  945. // (excluding slideshow.img and temp.img) and remove it. Returns false if
  946. // nothing was found to delete.
  947. bool DAB::deleteOldestSlideshow(void)
  948. {
  949. File root = LittleFS.open("/");
  950. if (!root || !root.isDirectory()) return false;
  951.  
  952. String oldestFile = "";
  953. time_t oldestTime = LONG_MAX;
  954.  
  955. File file = root.openNextFile();
  956. while (file)
  957. {
  958. String filename = file.name();
  959. // Only consider {serviceID}.img files (hex name + .img, not slideshow.img or temp.img)
  960. if (filename.endsWith(".img") && filename != "slideshow.img" && filename != "temp.img")
  961. {
  962. time_t fileTime = file.getLastWrite();
  963. if (fileTime < oldestTime)
  964. {
  965. oldestTime = fileTime;
  966. oldestFile = "/" + filename;
  967. }
  968. }
  969. file = root.openNextFile();
  970. }
  971. root.close();
  972.  
  973. if (oldestFile.length() > 0)
  974. {
  975. LittleFS.remove(oldestFile);
  976. return true;
  977. }
  978. return false;
  979. }
  980.  
  981.  
  982.  
  983. // Free up at least `requiredBytes` on LittleFS by deleting cached slideshows
  984. // in oldest-first order. Returns false if even after deleting everything we
  985. // still don't have enough space.
  986. bool DAB::ensureFreeSpace(size_t requiredBytes)
  987. {
  988. size_t freeSpace = LittleFS.totalBytes() - LittleFS.usedBytes();
  989.  
  990. // Keep removing oldest slideshows until we have enough space
  991. while (freeSpace < requiredBytes)
  992. {
  993. if (!deleteOldestSlideshow())
  994. {
  995. return false; // No more files to delete
  996. }
  997. freeSpace = LittleFS.totalBytes() - LittleFS.usedBytes();
  998. }
  999.  
  1000. return true;
  1001. }
  1002.  
  1003.  
  1004.  
  1005. // Forget every buffered slideshow segment. Used on TID switch, duplicate-image
  1006. // detection, assembly completion, and timeouts. Clearing the lengths array is
  1007. // enough — the data bytes in slideshowSegBuf only get read for indices where
  1008. // the corresponding length is non-zero.
  1009. void DAB::clearSegmentBuffer(void)
  1010. {
  1011. memset(slideshowSegLen, 0, sizeof(slideshowSegLen));
  1012. memset(SlideShowSegmentBitmap, 0, sizeof(SlideShowSegmentBitmap));
  1013. }
  1014.  
  1015.  
  1016. // Check if we have every segment from 0..N where N is either:
  1017. // - SlideShowTotalSegments (set from the MOT header when known), or
  1018. // - SlideShowHighestSegment + 1 (best guess until we see segment 0 wrap).
  1019. bool DAB::allSegmentsReceived(void)
  1020. {
  1021. // Determine how many segments to check
  1022. uint8_t segmentsToCheck = SlideShowTotalSegments;
  1023. if (segmentsToCheck == 0)
  1024. {
  1025. // No header received, use highest segment seen + 1
  1026. segmentsToCheck = SlideShowHighestSegment + 1;
  1027. }
  1028.  
  1029. if (segmentsToCheck == 0) return false;
  1030.  
  1031. for (uint8_t i = 0; i < segmentsToCheck; i++)
  1032. {
  1033. uint8_t byteIndex = i / 8;
  1034. uint8_t bitIndex = i % 8;
  1035. if (!(SlideShowSegmentBitmap[byteIndex] & (1 << bitIndex)))
  1036. {
  1037. return false;
  1038. }
  1039. }
  1040. return true;
  1041. }
  1042.  
  1043.  
  1044.  
  1045. // Stitch all buffered segments together, validate the result, and publish it
  1046. // as /slideshow.img on LittleFS. Writes to /temp.img first so the previous
  1047. // slideshow stays intact on validation failure. Optionally also caches a
  1048. // per-service copy as /<serviceID>.img when BufferSlideShow is enabled.
  1049.  
  1050. void DAB::assembleSlideshow(void)
  1051. {
  1052. if (S_Debug) Serial.printf("Assembling: %u segments, %u bytes received, %u bytes expected\n",
  1053. SlideShowTotalSegments, SlideShowByteCounter, SlideShowLength);
  1054.  
  1055. // Ensure enough free space for assembled slideshow
  1056. ensureFreeSpace(SlideShowByteCounter + 4096);
  1057.  
  1058. // Remove any leftover temp file
  1059. if (LittleFS.exists("/temp.img")) LittleFS.remove("/temp.img");
  1060.  
  1061. // Assemble into temp file first, so old slideshow.img is preserved on failure
  1062. File destFile = LittleFS.open("/temp.img", "wb");
  1063. if (!destFile)
  1064. {
  1065. if (S_Debug) Serial.println("Failed to create temp.img");
  1066. clearSegmentBuffer();
  1067. SlideShowTransportID = 0;
  1068. SlideShowByteCounter = 0;
  1069. SlideShowHighestSegment = 0;
  1070. SlideShowTotalSegments = 0;
  1071. SlideShowLength = 0;
  1072. SlideShowInit = false;
  1073. return;
  1074. }
  1075.  
  1076. // Concatenate all segments from RAM in order — single sequential write
  1077. for (uint8_t i = 0; i < SlideShowTotalSegments && i < SLS_MAX_SEGMENTS; i++)
  1078. {
  1079. if (slideshowSegLen[i] > 0)
  1080. {
  1081. destFile.write(&slideshowSegBuf[i * SLS_MAX_SEG_SIZE], slideshowSegLen[i]);
  1082. }
  1083. else if (S_Debug) { Serial.printf("WARNING: segment %u missing!\n", i); }
  1084. }
  1085.  
  1086. destFile.close();
  1087.  
  1088. // Validate assembled file size matches expected length
  1089. if (SlideShowLength > 0)
  1090. {
  1091. File checkFile = LittleFS.open("/temp.img", "rb");
  1092. if (checkFile)
  1093. {
  1094. size_t actualSize = checkFile.size();
  1095. checkFile.close();
  1096.  
  1097. if (actualSize != SlideShowLength)
  1098. {
  1099. if (S_Debug) {Serial.printf("REJECTED: size mismatch (got %u, expected %u)\n", actualSize, SlideShowLength);}
  1100. LittleFS.remove("/temp.img");
  1101. clearSegmentBuffer();
  1102. SlideShowTransportID = 0;
  1103. SlideShowByteCounter = 0;
  1104. SlideShowHighestSegment = 0;
  1105. SlideShowTotalSegments = 0;
  1106. SlideShowLength = 0;
  1107. SlideShowInit = false;
  1108. return;
  1109. }
  1110. }
  1111. }
  1112.  
  1113. // Validate assembled file has a valid image header
  1114. {
  1115. File imgFile = LittleFS.open("/temp.img", "rb");
  1116. if (imgFile)
  1117. {
  1118. uint8_t hdr[8];
  1119. imgFile.read(hdr, sizeof(hdr));
  1120. imgFile.close();
  1121.  
  1122. bool validJPEG = (hdr[0] == 0xFF && hdr[1] == 0xD8 && hdr[2] == 0xFF);
  1123. bool validPNG = (hdr[0] == 0x89 && hdr[1] == 0x50 && hdr[2] == 0x4E && hdr[3] == 0x47 &&
  1124. hdr[4] == 0x0D && hdr[5] == 0x0A && hdr[6] == 0x1A && hdr[7] == 0x0A);
  1125.  
  1126. if (!validJPEG && !validPNG)
  1127. {
  1128. if (S_Debug) Serial.printf("REJECTED: invalid header (%02X %02X %02X %02X)\n", hdr[0], hdr[1], hdr[2], hdr[3]);
  1129. LittleFS.remove("/temp.img");
  1130. clearSegmentBuffer();
  1131. SlideShowTransportID = 0;
  1132. SlideShowByteCounter = 0;
  1133. SlideShowHighestSegment = 0;
  1134. SlideShowTotalSegments = 0;
  1135. SlideShowLength = 0;
  1136. SlideShowInit = false;
  1137. return;
  1138. }
  1139.  
  1140. if (S_Debug) Serial.printf("Validated: %s\n", validJPEG ? "JPEG" : "PNG");
  1141. }
  1142. }
  1143.  
  1144. // Validation passed — replace old slideshow with new one
  1145. Serial.println("Validation passed");
  1146. Serial.println("Replace old slideshow with new one");
  1147. Serial.println("A");
  1148. if (LittleFS.exists("/slideshow.img")) LittleFS.remove("/slideshow.img");
  1149. Serial.println("B");
  1150. if (!LittleFS.rename("/temp.img", "/slideshow.img"))
  1151. {
  1152. Serial.println("C");
  1153. if (S_Debug) Serial.println("rename temp.img -> slideshow.img failed");
  1154. if (LittleFS.exists("/temp.img"))
  1155. {
  1156. Serial.println("D");
  1157. LittleFS.remove("/temp.img");
  1158. }
  1159. clearSegmentBuffer();
  1160. SlideShowTransportID = 0;
  1161. SlideShowByteCounter = 0;
  1162. SlideShowHighestSegment = 0;
  1163. SlideShowTotalSegments = 0;
  1164. SlideShowLength = 0;
  1165. SlideShowInit = false;
  1166. Serial.println("E");
  1167. return;
  1168. }
  1169.  
  1170. // Listing directory / (en mémoire LittleFS) :
  1171. Serial.println("-----------------------");
  1172. listDir(LittleFS, "/", 3);
  1173. Serial.println("-----------------------");
  1174.  
  1175. // Print BASE64 encoded slideshow when debug is enabled
  1176. if (S_Debug)
  1177. {
  1178. File b64File = LittleFS.open("/slideshow.img", "rb");
  1179. if (b64File)
  1180. {
  1181. size_t fileSize = b64File.size();
  1182. Serial.printf("BASE64 (%u bytes):\n", fileSize);
  1183. uint8_t raw[576];
  1184. uint8_t enc[769];
  1185. size_t olen;
  1186. while (b64File.available())
  1187. {
  1188. size_t bytesRead = b64File.read(raw, sizeof(raw));
  1189. if (mbedtls_base64_encode(enc, sizeof(enc), &olen, raw, bytesRead) == 0)
  1190. {
  1191. enc[olen] = '\0';
  1192. Serial.print((char*)enc);
  1193. }
  1194. }
  1195. Serial.println();
  1196. Serial.println("END BASE64");
  1197. b64File.close();
  1198. }
  1199. }
  1200.  
  1201. // Segment-buffer in RAM is cleared at the end of this function (see below).
  1202.  
  1203. // Save to service-specific buffer file if enabled
  1204. if (BufferSlideShow)
  1205. {
  1206. if (LittleFS.exists("/" + getDynamicFilename()))
  1207. {
  1208. LittleFS.remove("/" + getDynamicFilename());
  1209. }
  1210. ensureFreeSpace(100 * 1024);
  1211.  
  1212. File srcFile = LittleFS.open("/slideshow.img", "rb");
  1213. if (srcFile)
  1214. {
  1215. File piFile = LittleFS.open("/" + getDynamicFilename(), "wb");
  1216. if (piFile)
  1217. {
  1218. uint8_t buf[512];
  1219. size_t bytesRead;
  1220. while ((bytesRead = srcFile.read(buf, sizeof(buf))) > 0)
  1221. {
  1222. piFile.write(buf, bytesRead);
  1223. }
  1224. piFile.close();
  1225. }
  1226. srcFile.close();
  1227. }
  1228. if (S_Debug) Serial.printf("Buffered to %s\n", getDynamicFilename().c_str());
  1229. }
  1230.  
  1231. // Update state — use actual file size for dedup (works for both header and segment-0 paths)
  1232. {
  1233. File sizeCheck = LittleFS.open("/slideshow.img", "rb");
  1234. if (sizeCheck)
  1235. {
  1236. SlideShowLengthOld = sizeCheck.size();
  1237. sizeCheck.close();
  1238. }
  1239. else
  1240. {
  1241. SlideShowLengthOld = SlideShowLength;
  1242. }
  1243. }
  1244. SlideShowUpdate = true;
  1245. SlideShowUpdate2 = true;
  1246. SlideShowAvailable = true;
  1247. SlideShowInit = false;
  1248.  
  1249. // Reset collection state so next image can be received
  1250. SlideShowTransportID = 0;
  1251. SlideShowByteCounter = 0;
  1252. SlideShowHighestSegment = 0;
  1253. SlideShowTotalSegments = 0;
  1254. SlideShowLength = 0;
  1255. clearSegmentBuffer();
  1256.  
  1257. if (S_Debug) Serial.println("Slideshow ready for display");
  1258.  
  1259.  
  1260. transfererSlideshow();
  1261.  
  1262.  
  1263. }
  1264.  
  1265.  
  1266. // version IA
  1267. void DAB::transfererSlideshow()
  1268. {
  1269. Serial.println("-----------------------");
  1270. Serial.println("transfererSlideshow()");
  1271.  
  1272. File file = LittleFS.open("/slideshow.img", "r");
  1273. if (!file || file.size() == 0)
  1274. {
  1275. Serial.println("Erreur: Impossible de lire le fichier ou fichier vide.");
  1276. return;
  1277. }
  1278.  
  1279. size_t fileSize = file.size();
  1280.  
  1281. // 1. Lit tout le fichier en mémoire binaire
  1282. uint8_t *buffer = (uint8_t *)malloc(fileSize);
  1283.  
  1284. if (buffer == NULL)
  1285. {
  1286. Serial.println("Erreur d'allocation mémoire pour le transfert");
  1287. file.close();
  1288. return;
  1289. }
  1290. file.read(buffer, fileSize);
  1291. file.close();
  1292.  
  1293. // 2. Encode en Base64
  1294. String base64Data = base64::encode(buffer, fileSize);
  1295. // size_t olen = 0;
  1296. // String base64Data = mbedtls_base64_encode(buffer, fileSize, &olen);
  1297.  
  1298. free(buffer); // Libère la mémoire binaire immédiatment
  1299.  
  1300. // 3. Envoyer le protocole sur la liaison série
  1301.  
  1302. send_SLC_en_cours = true;
  1303.  
  1304. Serial.println("Debut de l'envoi du Slideshow");
  1305. Serial2.print("STARTSLS" + String(base64Data.length()) + '\n');
  1306. //Serial2.print("START_SLS:" + String(fileSize) + "\n");
  1307.  
  1308. // Envoi par blocs pour ne pas saturer les buffers série
  1309. size_t sent = 0;
  1310. size_t totalLen = base64Data.length();
  1311. Serial.print("totalLen= "); Serial.println(totalLen);
  1312.  
  1313. //size_t totalLen = fileSize;
  1314. while (sent < totalLen)
  1315. {
  1316. Serial.print("o"); // affichera ooooooo... sur CuteCom
  1317. size_t bloc = min((size_t)128, totalLen - sent);
  1318. Serial2.print(base64Data.substring(sent, sent + bloc));
  1319. sent += bloc; // AA
  1320. delay(10); // 5 Petit délai pour laisser l'ESP_AFFI respirer
  1321. }
  1322. Serial2.print('\n');
  1323. Serial2.println("ENDSLS");
  1324.  
  1325. send_SLC_en_cours = false;
  1326.  
  1327. Serial.println("");
  1328. Serial.println("[RADIO] Fin de l'envoi.");
  1329. Serial.println("");
  1330. }
  1331.  
  1332.  
  1333.  
  1334. // Filename for the per-service slideshow cache, e.g. "8203.img". Uses only
  1335. // the low 16 bits of the service ID (collisions are accepted as cosmetic).
  1336. String DAB::getDynamicFilename(void)
  1337. {
  1338. uint16_t serviceID = LST_services[ServiceIndex].ServiceID & 0xFFFF;
  1339. return String(serviceID, HEX) + ".img";
  1340. }
  1341.  
  1342. // Populate per-service metadata (PTY, ECC, bitrate, audio mode, sample rate,
  1343. // time/date, protection level) for the currently selected service. The
  1344. // service list itself is filled in EnsembleInfo().
  1345. void DAB::ServiceInfo(void)
  1346. {
  1347. for (byte x = 0; x < numberofservices; x++)
  1348. {
  1349. SPIbuffer[0] = 0xBE;
  1350. SPIbuffer[1] = 0x00;
  1351. SPIbuffer[2] = 0x00;
  1352. SPIbuffer[3] = 0x00;
  1353. SPIbuffer[4] = LST_services[x].ServiceID & 0xFF;
  1354. SPIbuffer[5] = (LST_services[x].ServiceID >> 8) & 0xFF;
  1355. SPIbuffer[6] = (LST_services[x].ServiceID >> 16) & 0xFF;
  1356. SPIbuffer[7] = (LST_services[x].ServiceID >> 24) & 0xFF;
  1357. SPIbuffer[8] = LST_services[x].CompID & 0xFF;
  1358. SPIbuffer[9] = (LST_services[x].CompID >> 8) & 0xFF;
  1359. SPIbuffer[10] = (LST_services[x].CompID >> 16) & 0xFF;
  1360. SPIbuffer[11] = (LST_services[x].CompID >> 24) & 0xFF;
  1361. SPIwrite(SPIbuffer, 12);
  1362. cts();
  1363. SPIread(12);
  1364. LST_services[x].ServiceType = SPIbuffer[5];
  1365. }
  1366.  
  1367. if (ServiceStart)
  1368. {
  1369. SPIbuffer[0] = 0xBD;
  1370. SPIbuffer[1] = 0x00;
  1371. SPIwrite(SPIbuffer, 2);
  1372. cts();
  1373. SPIread(16);
  1374.  
  1375. if (SPIbuffer[1] == 0x80) {
  1376. bitrate = SPIbuffer[5] + (SPIbuffer[6] << 8);
  1377. samplerate = SPIbuffer[7] + (SPIbuffer[8] << 8);
  1378. audiomode = SPIbuffer[9] & 0x03;
  1379. }
  1380.  
  1381. SPIbuffer[0] = 0xBE;
  1382. SPIbuffer[1] = 0x00;
  1383. SPIbuffer[2] = 0x00;
  1384. SPIbuffer[3] = 0x00;
  1385. SPIbuffer[4] = LST_services[ServiceIndex].ServiceID & 0xFF;
  1386. SPIbuffer[5] = (LST_services[ServiceIndex].ServiceID >> 8) & 0xFF;
  1387. SPIbuffer[6] = (LST_services[ServiceIndex].ServiceID >> 16) & 0xFF;
  1388. SPIbuffer[7] = (LST_services[ServiceIndex].ServiceID >> 24) & 0xFF;
  1389. SPIbuffer[8] = LST_services[ServiceIndex].CompID & 0xFF;
  1390. SPIbuffer[9] = (LST_services[ServiceIndex].CompID >> 8) & 0xFF;
  1391. SPIbuffer[10] = (LST_services[ServiceIndex].CompID >> 16) & 0xFF;
  1392. SPIbuffer[11] = (LST_services[ServiceIndex].CompID >> 24) & 0xFF;
  1393. SPIwrite(SPIbuffer, 12);
  1394. cts();
  1395. SPIread(12);
  1396.  
  1397. if (SPIbuffer[1] == 0x80)
  1398. {
  1399. servicetype = SPIbuffer[5];
  1400. protectionlevel = SPIbuffer[6];
  1401. }
  1402.  
  1403. SPIbuffer[0] = 0xC0;
  1404. SPIbuffer[1] = 0x00;
  1405. SPIbuffer[2] = 0x00;
  1406. SPIbuffer[3] = 0x00;
  1407. SPIbuffer[4] = LST_services[ServiceIndex].ServiceID & 0xFF;
  1408. SPIbuffer[5] = (LST_services[ServiceIndex].ServiceID >> 8) & 0xFF;
  1409. SPIbuffer[6] = (LST_services[ServiceIndex].ServiceID >> 16) & 0xFF;
  1410. SPIbuffer[7] = (LST_services[ServiceIndex].ServiceID >> 24) & 0xFF;
  1411. SPIwrite(SPIbuffer, 8);
  1412. cts();
  1413. SPIread(26);
  1414.  
  1415. if (SPIbuffer[1] == 0x80)
  1416. {
  1417. for (byte x = 9; x < 25; x++) PStext[x - 9] = SPIbuffer[x];
  1418.  
  1419. for (int8_t i = 15; i >= 0; i--) {
  1420. if (PStext[i] == ' ' && PStext[i + 1] == '\0') {
  1421. PStext[i] = '\0';
  1422. }
  1423. else { break; }
  1424. }
  1425.  
  1426. pty = (SPIbuffer[5] >> 1) & 0x1F;
  1427. ServiceLabelCharset = SPIbuffer[7];
  1428.  
  1429. // Use service ECC if available, otherwise fall back to ensemble ECC
  1430. // Only set once after service start to prevent corruption during marginal signal
  1431. if (ecc == 0)
  1432. {
  1433. uint8_t srvEcc = SPIbuffer[8];
  1434. serviceHasOwnEcc = (srvEcc != 0);
  1435. ecc = serviceHasOwnEcc ? srvEcc : ensembleEcc;
  1436. }
  1437. }
  1438. }
  1439. }
  1440.  
  1441. // Wipe every cached metadata field. Called when re-tuning so stale labels,
  1442. // PTY etc. from the previous channel don't briefly show up on the display.
  1443. void DAB::clearData(void)
  1444. {
  1445. for (byte x = 0; x < 32; x++)
  1446. {
  1447. LST_services[x].ServiceID = 0;
  1448. LST_services[x].CompID = 0;
  1449. LST_services[x].ServiceType = 0;
  1450. //LST_services[x].Label = "";
  1451. for (uint8_t i=0; i<16; i++) {LST_services[i].Label[i]=0; }
  1452. }
  1453. for (byte x = 0; x < 128; x++) ServiceData[x] = '\0';
  1454. }
  1455.  
  1456. // Tune to channel `freq` (an index into DABfrequencyTable_DAB). Sends the
  1457. // DAB_TUNE_FREQ command, waits up to 5 s for the chip to report lock state.
  1458. void DAB::setFreq(uint8_t freq)
  1459. {
  1460. Serial.println("-----------------------");
  1461. Serial.println("DAB::setFreq(uint8_t freq)");
  1462. Serial.print("freq="); Serial.println(freq);
  1463.  
  1464. memset(SPIbuffer, 0, sizeof(SPIbuffer));
  1465. DataUpdate -= 1000;
  1466. numberofservices = 0;
  1467. //clearData();
  1468.  
  1469. for (byte x = 0; x < 16; x++)
  1470. {
  1471. EnsembleLabel[x] = '\0';
  1472. PStext[x] = '\0';
  1473. }
  1474.  
  1475. EID[0] = '\0';
  1476. SID[0] = '\0';
  1477. pty = 36;
  1478. ecc = 0;
  1479. ensembleEcc = 0;
  1480. serviceHasOwnEcc = false;
  1481. protectionlevel = 0;
  1482. bitrate = 0;
  1483. dataServiceCheck = 0;
  1484. ServiceStart = false;
  1485.  
  1486. // DAB_TUNE_FREQ command
  1487. SPIbuffer[0] = 0xB0;
  1488. SPIbuffer[1] = 0x00;
  1489. SPIbuffer[2] = freq; // index into DABfrequencyTable_DAB
  1490. SPIbuffer[3] = 0x00;
  1491. SPIbuffer[4] = 0x00;
  1492. SPIbuffer[5] = 0x00;
  1493. SPIwrite(SPIbuffer, 6);
  1494. cts();
  1495.  
  1496.  
  1497. uint16_t timeout = 250;
  1498. while (bitRead(SPIbuffer[1], 0) == false)
  1499. {
  1500. delay(20);
  1501. memset(SPIbuffer, 0, 5);
  1502. SPIwrite(SPIbuffer, 5);
  1503. timeout--;
  1504. if (timeout == 0) {
  1505. break;
  1506. }
  1507. }
  1508.  
  1509. SPIbuffer[0] = 0xB2;
  1510. SPIbuffer[1] = 0x01;
  1511. SPIwrite(SPIbuffer, 2);
  1512. cts();
  1513. }
  1514.  
  1515.  
  1516. // code prevenant de la version DABShield.cpp (Arduino)
  1517. static void si468x_start_digital_service(uint32_t sID_i, uint32_t compID_i)
  1518. {
  1519. SPIbuffer[0] = 0x81; // 0x81 - Starts an audio or data service
  1520. SPIbuffer[1] = 0x00;
  1521. SPIbuffer[2] = 0x00;
  1522. SPIbuffer[3] = 0x00;
  1523. SPIbuffer[4] = sID_i & 0xff;
  1524. SPIbuffer[5] = (sID_i >> 8) & 0xff;
  1525. SPIbuffer[6] = (sID_i >> 16) & 0xff;
  1526. SPIbuffer[7] = (sID_i >> 24) & 0xff;
  1527. SPIbuffer[8] = compID_i & 0xff;
  1528. SPIbuffer[9] = (compID_i >> 8) & 0xff;
  1529. SPIbuffer[10] = (compID_i >> 16) & 0xff;
  1530. SPIbuffer[11] = (compID_i >> 24) & 0xff;
  1531. SPIwrite(SPIbuffer, 12);
  1532. cts();
  1533. }
  1534.  
  1535.  
  1536.  
  1537.  
  1538. // Start audio for service[_index] in the current ensemble.
  1539. // Resets the slideshow segment buffer because the new service has its own MOT stream.
  1540. void DAB::setService(uint8_t index_i)
  1541. {
  1542. Serial.println("-----------------------");
  1543. Serial.println("DAB::setService()");
  1544. Serial.print("index_i="); Serial.println(index_i);
  1545. /*
  1546. resultats :
  1547. _index=1
  1548. service[ServiceIndex].ServiceID = 61991
  1549. */
  1550.  
  1551. union
  1552. {
  1553. uint32_t combine;
  1554. uint8_t monoctet[4];
  1555. } u;
  1556.  
  1557. pty = 36;
  1558. bitrate = 0;
  1559. protectionlevel = 0;
  1560. for (byte x = 0; x < 128; x++) ServiceData[x] = '\0';
  1561.  
  1562. ServiceStart = true;
  1563.  
  1564. ecc = 0; // Reset so ServiceInfo() picks up the new service's ECC
  1565. serviceHasOwnEcc = false;
  1566.  
  1567. SPIbuffer[0] = 0x81; // commande START_DIGITAL_SERVICE
  1568. SPIbuffer[1] = 0x00;
  1569. SPIbuffer[2] = 0x00;
  1570. SPIbuffer[3] = 0x00;
  1571. SPIbuffer[4] = LST_services[index_i].ServiceID & 0xff;
  1572. SPIbuffer[5] = (LST_services[index_i].ServiceID >> 8) & 0xff;
  1573. SPIbuffer[6] = (LST_services[index_i].ServiceID >> 16) & 0xff;
  1574. SPIbuffer[7] = (LST_services[index_i].ServiceID >> 24) & 0xff;
  1575. SPIbuffer[8] = LST_services[index_i].CompID & 0xff;
  1576. SPIbuffer[9] = (LST_services[index_i].CompID >> 8) & 0xff;
  1577. SPIbuffer[10] = (LST_services[index_i].CompID >> 16) & 0xff;
  1578. SPIbuffer[11] = (LST_services[index_i].CompID >> 24) & 0xff;
  1579. SPIwrite(SPIbuffer, 12);
  1580. u.combine = LST_services[index_i].ServiceID;
  1581.  
  1582. SID[3] = u.monoctet[0] & 0xF;
  1583. SID[2] = (u.monoctet[0] & 0xF0) >> 4;
  1584. SID[1] = u.monoctet[1] & 0xF;
  1585. SID[0] = (u.monoctet[1] & 0xF0) >> 4;
  1586.  
  1587. for (int i = 0; i < 4; i++)
  1588. {
  1589. if (SID[i] < 10)
  1590. {
  1591. SID[i] += '0';
  1592. }
  1593. else
  1594. {
  1595. SID[i] += 'A' - 10;
  1596. }
  1597. }
  1598. delay(100);
  1599. //envoi_1_station_to_AFFI(index_i);
  1600. //envoi_LST_services_to_AFFI();
  1601. ServiceInfo();
  1602. }
  1603.  
  1604.  
  1605.  
  1606.  
  1607.  
  1608. void envoi_LST_services_to_AFFI()
  1609. {
  1610. if (send_SLC_en_cours == true) return;
  1611.  
  1612. Serial.println("envoi_LST_services_to_AFFI()");
  1613.  
  1614. const uint8_t* rawData = reinterpret_cast<const uint8_t*>(&LST_services);
  1615. size_t dataSize = sizeof(LST_services);
  1616. Serial2.println("LISTING");
  1617. Serial2.write(rawData, dataSize); // Données de la liste des structures
  1618. }
  1619.  
  1620.  
  1621.  
  1622. // Periodic driver pump. Called every loop iteration:
  1623. // - Pull any pending service-data (RT / MOT) packets
  1624. // - Discard the slideshow buffer if no segment has arrived in 30 s
  1625. // - Every 500 ms, refresh EnsembleInfo + ServiceInfo and start a data
  1626. // service for TPEG-like data components on first activation
  1627.  
  1628. void DAB::Update(void)
  1629. {
  1630. if (signallock)
  1631. {
  1632. getServiceData();
  1633. }
  1634.  
  1635. // Timeout for incomplete slideshow collection (30 seconds without new segments)
  1636. if (SlideShowInit && SlideShowLastActivity > 0 && millis() - SlideShowLastActivity > 30000)
  1637. {
  1638. if (S_Debug) Serial.println("Collection timeout, resetting");
  1639. clearSegmentBuffer();
  1640. if (LittleFS.exists("/temp.img")) LittleFS.remove("/temp.img");
  1641. SlideShowTransportID = 0;
  1642. SlideShowByteCounter = 0;
  1643. SlideShowHighestSegment = 0;
  1644. SlideShowTotalSegments = 0;
  1645. SlideShowLength = 0;
  1646. SlideShowInit = false;
  1647. SlideShowLastActivity = 0;
  1648. }
  1649.  
  1650. if (millis() - DataUpdate > 500 || !signallock) {
  1651. EnsembleInfo();
  1652.  
  1653. if (signallock)
  1654. {
  1655. ServiceInfo();
  1656. }
  1657. if (ServiceStart) RecoverSlideShow();
  1658.  
  1659. if (ServiceStart)
  1660. {
  1661. for (int i = 0; i < numberofservices; i++)
  1662. {
  1663. if (service[i].ServiceType == 3 && strstr(service[i].Label, "tpeg") == NULL && strstr(service[i].Label, "TPEG") == NULL)
  1664. {
  1665. if (service[i].CompID != dataServiceCheck)
  1666. {
  1667. SPIbuffer[0] = 0x81;
  1668. SPIbuffer[1] = 0x01;
  1669. SPIbuffer[2] = 0x00;
  1670. SPIbuffer[3] = 0x00;
  1671. SPIbuffer[4] = service[i].ServiceID & 0xff;
  1672. SPIbuffer[5] = (service[i].ServiceID >> 8) & 0xff;
  1673. SPIbuffer[6] = (service[i].ServiceID >> 16) & 0xff;
  1674. SPIbuffer[7] = (service[i].ServiceID >> 24) & 0xff;
  1675. SPIbuffer[8] = service[i].CompID & 0xff;
  1676. SPIbuffer[9] = (service[i].CompID >> 8) & 0xff;
  1677. SPIbuffer[10] = (service[i].CompID >> 16) & 0xff;
  1678. SPIbuffer[11] = (service[i].CompID >> 24) & 0xff;
  1679. SPIwrite(SPIbuffer, 12);
  1680. dataServiceCheck = service[i].CompID;
  1681. break;
  1682. }
  1683. }
  1684. }
  1685. }
  1686. DataUpdate = millis();
  1687. }
  1688. }
  1689.  
  1690.  
  1691. // On service start: if a cached /<serviceID>.img exists, copy it over
  1692. // /slideshow.img so the UI has something to show until a fresh MOT image
  1693. // arrives. Triggered ~800 ms after the service starts via SlideShowRecover.
  1694. void DAB::RecoverSlideShow(void) {
  1695. if (BufferSlideShow && SlideShowRecover && millis() - SlideShowRecoverTimer > 800) {
  1696. if (LittleFS.exists("/" + getDynamicFilename())) {
  1697. File sourceFile = LittleFS.open("/" + getDynamicFilename(), "rb");
  1698. if (sourceFile) {
  1699. if (LittleFS.exists("/slideshow.img")) LittleFS.remove("/slideshow.img");
  1700. File destinationFile = LittleFS.open("/slideshow.img", "wb");
  1701.  
  1702. if (destinationFile) {
  1703. uint8_t buf[512];
  1704. size_t bytesRead;
  1705. while ((bytesRead = sourceFile.read(buf, sizeof(buf))) > 0) {
  1706. destinationFile.write(buf, bytesRead);
  1707. }
  1708. destinationFile.close();
  1709. SlideShowAvailable = true;
  1710. SlideShowNew = false;
  1711. }
  1712. sourceFile.close();
  1713. }
  1714. }
  1715. SlideShowRecover = false;
  1716. }
  1717. }
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723. /*
  1724. void DAB::Update(void)
  1725. {
  1726.   if (signallock)
  1727.   {
  1728.   getServiceData();
  1729.   }
  1730.  
  1731.   if (millis() - DataUpdate > 500 || !signallock)
  1732.   {
  1733.   EnsembleInfo();
  1734.  
  1735.   if (signallock)
  1736.   {
  1737.   ServiceInfo();
  1738.   }
  1739.  
  1740.   if (ServiceStart)
  1741.   {
  1742.   for (int i = 0; i < numberofservices; i++)
  1743.   {
  1744.   if (LST_services[i].ServiceType == 3 && (LST_services[i].Label, "tpeg") == NULL && (LST_services[i].Label, "TPEG") == NULL)
  1745.   {
  1746.   if (LST_services[i].CompID != dataServiceCheck)
  1747.   {
  1748.   SPIbuffer[0] = 0x81;
  1749.   SPIbuffer[1] = 0x01;
  1750.   SPIbuffer[2] = 0x00;
  1751.   SPIbuffer[3] = 0x00;
  1752.   SPIbuffer[4] = LST_services[i].ServiceID & 0xff;
  1753.   SPIbuffer[5] = (LST_services[i].ServiceID >> 8) & 0xff;
  1754.   SPIbuffer[6] = (LST_services[i].ServiceID >> 16) & 0xff;
  1755.   SPIbuffer[7] = (LST_services[i].ServiceID >> 24) & 0xff;
  1756.   SPIbuffer[8] = LST_services[i].CompID & 0xff;
  1757.   SPIbuffer[9] = (LST_services[i].CompID >> 8) & 0xff;
  1758.   SPIbuffer[10] = (LST_services[i].CompID >> 16) & 0xff;
  1759.   SPIbuffer[11] = (LST_services[i].CompID >> 24) & 0xff;
  1760.   SPIwrite(SPIbuffer, 12);
  1761.   dataServiceCheck = LST_services[i].CompID;
  1762.   break;
  1763.   }
  1764.   }
  1765.   }
  1766.   }
  1767.   DataUpdate = millis();
  1768.   }
  1769. }
  1770. */
  1771.  
  1772.  
  1773.  
  1774. // Convert a label/text from the DAB-side character set to UTF-8 for the TFT.
  1775. // charset 0 = ETSI EBU Latin (the most common), uses a lookup table via
  1776. // charConverter()+convertToUTF8(). All other charsets are assumed UTF-8 already.
  1777. // Also auto-detects already-UTF-8 input to avoid double conversion.
  1778. String DAB::ASCII(const char* input, uint8_t charset)
  1779. {
  1780. if (!input) return String();
  1781. String result;
  1782. if (charset != 0) return String(input);
  1783.  
  1784. bool looksLikeUTF8 = false;
  1785. for (size_t i = 0; input[i] != '\0'; i++)
  1786. {
  1787. uint8_t c = (uint8_t)input[i];
  1788.  
  1789. if ((c & 0xE0) == 0xC0) {
  1790. uint8_t c2 = (uint8_t)input[i + 1];
  1791. if ((c2 & 0xC0) == 0x80)
  1792. {
  1793. looksLikeUTF8 = true;
  1794. break;
  1795. }
  1796. } else if ((c & 0xF0) == 0xE0)
  1797. {
  1798. uint8_t c2 = (uint8_t)input[i + 1];
  1799. uint8_t c3 = (uint8_t)input[i + 2];
  1800. if ((c2 & 0xC0) == 0x80 && (c3 & 0xC0) == 0x80) {
  1801. looksLikeUTF8 = true;
  1802. break;
  1803. }
  1804. }
  1805. }
  1806.  
  1807. if (looksLikeUTF8)
  1808. {
  1809. return String(input);
  1810. }
  1811.  
  1812. wchar_t temp[128];
  1813. charConverter(input, temp, sizeof(temp) / sizeof(wchar_t));
  1814. result = convertToUTF8(temp);
  1815.  
  1816. return result;
  1817. }
  1818.  
  1819.  
  1820. // qsort() comparator: order services by component ID low byte ascending.
  1821. static int compareCompID(const void* a, const void* b)
  1822. {
  1823. uint32_t compID_a = (*((DABService*)a)).CompID & 0xFF;
  1824. uint32_t compID_b = (*((DABService*)b)).CompID & 0xFF;
  1825.  
  1826. if (compID_a < compID_b) return -1;
  1827. if (compID_a > compID_b) return 1;
  1828. return 0;
  1829. }
  1830.  
  1831. // Translate an EBU-Latin (ETSI EN 300 401) byte string into Unicode code
  1832. // points, handling the DAB-specific shift/escape encodings. Output is a
  1833. // wchar_t buffer that convertToUTF8() later serialises as UTF-8.
  1834. static void charConverter(const char* input, wchar_t* output, size_t outSize)
  1835. {
  1836. return;
  1837.  
  1838. }
  1839.  
  1840. // Substring helper that operates on code-points (not bytes) so cutting a
  1841. // UTF-8 string at index N doesn't slice a multi-byte sequence in half.
  1842. static String extractUTF8Substring(const String& utf8String, size_t start, size_t length) {
  1843. String substring;
  1844. size_t utf8Length = utf8String.length();
  1845. size_t utf8Index = 0;
  1846. size_t charIndex = 0;
  1847.  
  1848. while (utf8Index < utf8Length && charIndex < start + length)
  1849. {
  1850. uint8_t currentByte = utf8String.charAt(utf8Index);
  1851. uint8_t numBytes = 0;
  1852.  
  1853. if (currentByte < 0x80)
  1854. {
  1855. numBytes = 1;
  1856. }
  1857. else if ((currentByte >> 5) == 0x6)
  1858. {
  1859. numBytes = 2;
  1860. }
  1861. else if ((currentByte >> 4) == 0xE)
  1862. {
  1863. numBytes = 3;
  1864. }
  1865. else if ((currentByte >> 3) == 0x1E)
  1866. {
  1867. numBytes = 4;
  1868. }
  1869.  
  1870. if (charIndex >= start) {
  1871. substring += utf8String.substring(utf8Index, utf8Index + numBytes);
  1872. }
  1873.  
  1874. utf8Index += numBytes;
  1875. charIndex++;
  1876. }
  1877.  
  1878. return substring;
  1879. }
  1880.  
  1881. // Encode the wchar_t code points produced by charConverter() into a UTF-8
  1882. // String suitable for the TFT and the serial protocol.
  1883. static String convertToUTF8(const wchar_t* input)
  1884. {
  1885. String output;
  1886. while (*input)
  1887. {
  1888. uint32_t unicode = *input;
  1889. if (unicode < 0x80)
  1890. {
  1891. output += (char)unicode;
  1892. }
  1893. else if (unicode < 0x800)
  1894. {
  1895. output += (char)(0xC0 | (unicode >> 6));
  1896. output += (char)(0x80 | (unicode & 0x3F));
  1897. }
  1898. else if (unicode < 0x10000)
  1899. {
  1900. output += (char)(0xE0 | (unicode >> 12));
  1901. output += (char)(0x80 | ((unicode >> 6) & 0x3F));
  1902. output += (char)(0x80 | (unicode & 0x3F));
  1903. }
  1904. else {
  1905. output += (char)(0xF0 | (unicode >> 18));
  1906. output += (char)(0x80 | ((unicode >> 12) & 0x3F));
  1907. output += (char)(0x80 | ((unicode >> 6) & 0x3F));
  1908. output += (char)(0x80 | (unicode & 0x3F));
  1909. }
  1910. input++;
  1911. }
  1912. return output;
  1913.  
  1914. }
  1915.  
  1916.  
  1917. // ******************************************************************************************************
  1918. // par IA
  1919. // ******************************************************************************************************
  1920.  
  1921.  
  1922. //### 1. Récupérer la liste des stations d'un ensemble
  1923.  
  1924. // Après avoir fait DAB_TUNE_FREQ + wait STC
  1925.  
  1926.  
  1927.  
  1928. static void si468x_responseN(int len)
  1929. {
  1930. int i;
  1931.  
  1932. for (i = 0; i < len + 1; i++)
  1933. {
  1934. SPIbuffer[i] = 0;
  1935. }
  1936. //DABSpiMsg(SPIbuffer, len + 1);
  1937. SPIread(len + 1) ;
  1938. }
  1939.  
  1940.  
  1941.  
  1942. #define CMD_RD_REPLY 0x00
  1943.  
  1944.  
  1945. // IA : fonction si4684_readResp()
  1946. // Voilà celle que j'utilise pour ton cas ESP32, stable en SPI.
  1947. // Bloquant mais sûr - lit la réponse complète du Si4684
  1948. // Retourne le nombre d'octets lus, 0 si timeout
  1949.  
  1950. int DAB::readResp(uint8_t *buf, int maxLen)
  1951. {
  1952. const int TIMEOUT_MS = 100; // 100ms max
  1953. unsigned long start = millis();
  1954.  
  1955. // 1. Attendre que CTS = 1 et que INT tombe (broche IRQ)
  1956.  
  1957. while (millis() - start < TIMEOUT_MS)
  1958. {
  1959. // Lecture du status byte seul
  1960. digitalWrite(slaveSelectPin, LOW);
  1961. SPI.transfer(0x00); // demande status
  1962. uint8_t status = SPI.transfer(0x00);
  1963. digitalWrite(slaveSelectPin, HIGH);
  1964.  
  1965. if (status & 0x80)
  1966. { // bit 7 = CTS
  1967.  
  1968. // 2. CTS OK, on lit tout le buffer
  1969. digitalWrite(slaveSelectPin, LOW);
  1970. SPI.transfer(0x00); // encore une fois pour lancer la lecture
  1971. // Le Si4684 renvoie : [STATUS] [LEN_L] [LEN_H] [DATA...]
  1972. buf[0] = status;
  1973. // Beaucoup de drivers oublient ces 2 octets de longueur
  1974. uint8_t lenL = SPI.transfer(0x00);
  1975. uint8_t lenH = SPI.transfer(0x00);
  1976. int payloadLen = lenL | (lenH << 8);
  1977.  
  1978. int toRead = payloadLen;
  1979. if (toRead > maxLen - 1) toRead = maxLen - 1;
  1980.  
  1981. for (int i = 1; i <= toRead; i++)
  1982. {
  1983. buf[i] = SPI.transfer(0x00);
  1984. }
  1985. digitalWrite(slaveSelectPin, HIGH);
  1986.  
  1987. // Le total = 1 status + payload
  1988. return toRead + 1;
  1989. }
  1990. delay(1);
  1991. }
  1992. Serial.println("ERR: si4684_readResp TIMEOUT CTS");
  1993. return 0;
  1994. }
  1995.  
  1996.  
  1997. //Conversion from extended EBU Latin (DAB/RDS) to LCD charset (0x80 to 0xFF)
  1998. const char EBULatintoLCD[0x80] = {0x08,0x08,0x09,0x09,0x0A,0x0A,0x0B,0x0B,0x0C,0x0C,'N', 'C', 'S', 0xE2,'i', 'Y',
  1999. 0x08,0x08,0x09,0x09,0x0A,0x0A,0x0B,0x0B,0x0C,0x0C,'n', 'c', 's', 'g', 'i', 'y',
  2000. 'a', 'a', 'c', '/', 'G', 'e', 'n', 0x0B,0xF7,'$', '$', '$', 0x7F,'^', 0x7E,'v',
  2001. '0', '1', '2', '3', '+', 'I', 'n', 0x0C,0xE4,'?', 0xFD,0xDF,'_', '_', '_', '_',
  2002. 'A', 'A', 'E', 'E', 'I', 'I', 'O', 'O', 'U', 'U', 'R', 'C', 'S', 'Z', 'D', 'L',
  2003. 'A', 'A', 'E', 'E', 'I', 'I', 'O', 'O', 'U', 'U', 'r', 'c', 's', 'z', 'd', 'l',
  2004. 'A', 'A', 'E', 'E', 'y', 'Y', 'O', 'O', 'p', 'n', 'R', 'C', 'S', 'Z', 't', 'd',
  2005. 0x08,0x08,'e', 'e', 'w', 'y', 'O', 'o', 'p', 'n', 'r', 'c', 's', 'z', 't', ' '};
  2006.  
  2007. void replaceSpecialCharsInplace(uint8_t * p, int len)
  2008. {
  2009. for (int j = 0; j < (len); j++)
  2010. {
  2011. //correct wrong chars for our LCD display
  2012. unsigned char * cc = (unsigned char*) &p[j];
  2013. if(*cc > 0x7F)
  2014. *cc = EBULatintoLCD[*cc - 0x80];
  2015. }
  2016. }
  2017.  
  2018.  
  2019.  
  2020. //1. Récupérer la liste des stations d'un ensemble
  2021. // Après avoir fait DAB_TUNE_FREQ + wait cts
  2022.  
  2023. void DAB::getServiceList() // peuple la 'liste_labels' (id + label)
  2024. {
  2025. Serial.println("-----------------------");
  2026. Serial.println("DAB::getServiceList()");
  2027.  
  2028. for(int n=0; n<16; n++)
  2029. {
  2030. LST_services[n].ServiceID = 0;
  2031. for(int i=0; i<16; i++) { LST_services[n].Label[i] = ' ';}
  2032. }
  2033.  
  2034. // Cette commande demande au composant la liste complète des services disponibles
  2035. // dans l'ensemble (le multiplex) actuellement syntonisé
  2036. SPIbuffer[0] = 0x80; // Get servicelist
  2037. SPIbuffer[1] = 0x00;
  2038. SPIwrite(SPIbuffer, 2);
  2039. cts();
  2040. delay(500);
  2041.  
  2042. uint8_t resp[512] = {0}; // 512
  2043. int len = readResp(resp, sizeof(resp));
  2044.  
  2045. String s1;
  2046. String s2;
  2047. String s3="";
  2048. String s_out="";
  2049.  
  2050.  
  2051. Serial.println("lecture du nb of bytes in the digital service list");
  2052. uint8_t L = resp[0]; Serial.print("L= "); Serial.println(L);
  2053. uint8_t H = resp[1]; Serial.print("H= "); Serial.println(H);
  2054. int nb_octets = L + 256*H; Serial.print("nb octets= "); Serial.println(nb_octets);
  2055.  
  2056. Serial.println("lecture du number of services ");
  2057. uint8_t nb_services = resp[5]; Serial.print("nb_services= ");
  2058. Serial.println(nb_services); // voir AN649.pdf page 421
  2059.  
  2060. uint8_t sx;
  2061. for(int n=0; n<18; n++)
  2062. {
  2063. sx = resp[n];
  2064. s1 += String(sx);
  2065. s1 += " - ";
  2066. }
  2067. Serial.println(s1); //result: 128 - 0 - 192 - 114 - 1 - 67 - 2 - 13 - 0 - 0 - 0 - 38 - 242 - 0 - 0 - 0 - 1 - 0 -
  2068.  
  2069. int i =18;
  2070. int j = 0;
  2071. int num = 0;
  2072. s1="";
  2073.  
  2074. while (i<len)
  2075. {
  2076. if(resp[i]<0x30) {resp[i] = ' ';} // ajout perso : suppression des caractères non-alphabétiques
  2077.  
  2078. //Serial.print((char)resp[i]); // un caractère
  2079. s1 += (char)resp[i]; // 'label' se constitue caractere par caractere ici
  2080. i++;
  2081. j++;
  2082.  
  2083. if(j==15) // le label est constitué ('label' est complet pour 1 station)
  2084. {
  2085. j=0;
  2086. i+=13;
  2087. num++;
  2088.  
  2089. uint32_t serv_id_n = LST_services[num].ServiceID; // 61954
  2090. String s4 = convert_Dec_To_Hex(serv_id_n); // "F201"
  2091. Serial.println(s4); // pour test
  2092.  
  2093.  
  2094. s2 = String(num);
  2095. if (num <10) s2= "0" + s2; // mise en forme sur 2 chiffres
  2096. s_out =" " + s4 + " " +s1; //
  2097. Serial.print("s_out = "); Serial.println(s_out);
  2098.  
  2099. // LST_services[num].ServiceID = s4; // ajout du numero à la liste des labels;
  2100. //LST_services[num].Label = s1; // ajout du label à la liste des labels;
  2101. s1="";
  2102. }
  2103. }
  2104.  
  2105.  
  2106. }
  2107.  
  2108.  
  2109.  
  2110. /*
  2111. source AN649.pdf:
  2112.  
  2113. GET_DIGITAL_SERVICE_DATA obtient un bloc de données associé à l’un
  2114. des composants de données activés d’un service numérique.
  2115. Les informations sur ce bloc de données se trouvent dans l’en-tête
  2116. des données renvoyé au début du bloc de données.
  2117. Afin de déterminer le nombre idéal d’octets PAYLOAD à lire,
  2118. les informations de l’en-tête peuvent être lues en premier,
  2119. suivies d’une seconde lecture de la longueur complète (en-tête + PAYLOAD) -
  2120.  
  2121. il est inutile d’appeler GET_DIGITAL_SERVICE_DATA deux fois
  2122. pour utiliser cette méthode.
  2123. Les données associées à cette transaction seront supprimées
  2124. lors de la réception d’une prochaine
  2125. commande GET_DIGITAL_SERVICE_DATA si STATUS_ONLY = 0.
  2126. Lire au-delà de la fin du tampon entraînera des zéros
  2127. pour les octets non valides.
  2128.  
  2129. Veuillez vous référer au document iBiquity : SY_IDD_1019s Rév F (sections 5 et 6)
  2130. pour le format des données du service de données HD Radio.
  2131. La commande est terminée lorsque le bit CTS (et l’interruption facultative) est défini.
  2132. Le bit ERR (et l’interruption facultative) est défini si un argument non valide est envoyé.
  2133.  Notez qu’une seule interruption se produit si les deux bits CTS et ERR sont définis.
  2134. La commande ne peut être envoyée qu’en mode powerup.
  2135. */
  2136.  
  2137. String DAB::getServiceLabel(uint32_t serviceId)
  2138. {
  2139. Serial.println("-----------------------");
  2140. Serial.println("DAB::getServiceLabel(uint32_t serviceId) ");
  2141. Serial.print("serviceId= "); Serial.println(serviceId);
  2142.  
  2143. uint8_t cmd[9] = {0x84, 0,0,0,0,0,0,0,0}; // DAB_GET_SERVICE_INFO
  2144. cmd[4] = serviceId & 0xFF;
  2145. cmd[5] = (serviceId>>8) & 0xFF;
  2146. cmd[6] = (serviceId>>16) & 0xFF;
  2147. cmd[7] = (serviceId>>24) & 0xFF;
  2148. SPIwrite(cmd, 9);
  2149. cts;
  2150.  
  2151. uint8_t resp[64];
  2152. SPIread(64);
  2153. // Le label est à resp[18] sur 16 bytes, encodé EBU Latin
  2154. char label[17];
  2155.  
  2156. memcpy(label, &resp[18], 16);
  2157. label[16]=0;
  2158.  
  2159. Serial.print("label A ="); Serial.println(String(label));
  2160.  
  2161. for(int i=0; i<16; i++) if(label[i]<32) label[i]=0; // nettoie les 0x00
  2162.  
  2163. Serial.println("-----------------------");
  2164.  
  2165. return String(label);
  2166. }
  2167.  
  2168.  

7 main_AFFI.cpp

CODE SOURCE en C++
  1. /************************************************************
  2.   * Si4684 ESP_AFFI
  3.  
  4. - pilote un afficheur 320x240 ILI9341 avec un ESP32 (connecté par ma carte "Carte_ILI9341_ESP32")
  5. - utilise l'écran tactile (XPT2046)
  6. - lit et écrit sur la SDcard connectée au dos de l'afficheur
  7. - affiche des images bmp565
  8. - effectue des capture d'écran
  9. - décode et affiche les images jpg
  10. - affiche et gère des boutons graphiques
  11. - affiche et gère des panels de boutons graphiques exclusifs (1 seul bouton 'enfoncé' à la fois)
  12.  
  13.  *************************************************************/
  14.  
  15.  
  16. #include <Arduino.h>
  17.  
  18. //----------------------------------
  19. String version = "2026-12-01";
  20. //----------------------------------
  21.  
  22. #include "main_AFFI.h"
  23.  
  24. #include "TJpg_Decoder.h" // Décodeur JPEG matériel/logiciel optimisé ESP32
  25. #include "mbedtls/base64.h" // encodeur/décodeur en format 'base64'
  26.  
  27. #include "bouton.h"
  28. #include "etiquette.h"
  29. #include "page_texte.h"
  30.  
  31. #include "TFT_eSPI.h"
  32.  
  33. #define SPI_READ_FREQUENCY 16000000
  34.  
  35. #define XPT2046_IRQ 36
  36. #define XPT2046_MOSI 32 //T_DI 32
  37. #define XPT2046_MISO 39 //T_DO 39
  38. #define XPT2046_CLK 25
  39. #define XPT2046_CS 33
  40.  
  41. //attention: ces valeurs ne sont pas celles par défaut pour SDA et SCL
  42.  
  43. uint16_t ROUGE = 63488;
  44. uint16_t ORANGE = 62400;
  45. uint16_t JAUNE = 65504;
  46. uint16_t VERT = 2016;
  47. uint16_t BLEU = 31;
  48. uint16_t BLEU_CLAIR = 26079;
  49. uint16_t CYAN = 2047;
  50. uint16_t NOIR = 0x000;
  51. uint16_t GRIS_1 = (27 << 11) | (54 << 5) | 27;
  52. uint16_t GRIS_2 = (24 << 11) | (48 << 5) | 24;
  53. uint16_t GRIS_3 = (20 << 11) | (40 << 5) | 20;
  54. uint16_t GRIS_4 = (15 << 11) | (30 << 5) | 15;
  55. uint16_t GRIS_5 = (13 << 11) | (26 << 5) | 13;
  56. uint16_t GRIS_6 = (5 << 11) | (10 << 5) | 5;
  57.  
  58. uint16_t BLANC = 65535;
  59.  
  60. uint16_t color565px;
  61.  
  62. const int GPIO_SDA = 21;
  63. const int GPIO_SCL = 22;
  64.  
  65. const int analogPin = 35;
  66.  
  67. const int _DX = 320;
  68. const int _DY = 240;
  69.  
  70. SPIClass mySpi = SPIClass(VSPI);
  71. XPT2046_Touchscreen ts(XPT2046_CS, XPT2046_IRQ);
  72.  
  73. SPIClass mySpi2 = SPIClass(HSPI);
  74.  
  75. TFT_eSPI TFT = TFT_eSPI(); // Configurer le fichier User_Setup.h de la bibliothèque TFT_eSPI au préalable
  76.  
  77. TFT_eSprite sprite_frq = TFT_eSprite(&TFT);
  78.  
  79. struct ETALON_TS // etalon touch screen
  80. {
  81. int16_t x0;
  82. int16_t dx;
  83. int16_t y0;
  84. int16_t dy;
  85. };
  86.  
  87. ETALON_TS eTS;
  88.  
  89. struct POINT
  90. {
  91. uint16_t x;
  92. uint16_t y;
  93. };
  94.  
  95. // coordonnées des points de calibrage de l'écran tactile
  96. POINT A, B;
  97.  
  98. uint8_t n_mult_0 =0; // index dans la liste; enregistré sur la SDcard
  99. uint8_t n_mult_1 =0;
  100. uint8_t n_mult_2 =0;
  101. uint8_t n_mult_3 =0;
  102.  
  103. // sélection d'une station au démarrage, mais plus par la suite
  104. // prévoir d'enregistrer ces 2 infos sur la SDcard (afin de rappeler la dernière station écoutée)
  105. uint8_t btm = 2; // 10C
  106. uint8_t bts = 10; // FRANCE MUSIQUE
  107.  
  108. uint8_t memo_n_bt_cat=0;
  109.  
  110. uint16_t x_touch, y_touch;
  111. uint16_t memo_x_touch, memo_y_touch;
  112.  
  113. uint8_t SDcardOk=0;
  114.  
  115. boolean do_capt_screen = false;
  116.  
  117. float raddeg = M_PI/180.0;
  118. float deg_to_rad = 2.0 * M_PI /360.0;
  119.  
  120. boolean test_touch_screen = false; // mettre true pour activer le test
  121. unsigned long previousMillis = 0;
  122.  
  123. ETIQUETTE etiquette_rssi;
  124. ETIQUETTE etiquette_ID;
  125. ETIQUETTE etiquette_LABEL1; // en mode 'expert'
  126. ETIQUETTE etiquette_LABEL2; // en bas, sous le catalogue
  127. ETIQUETTE etiquette_Radiotext1; // en mode 'expert'
  128. ETIQUETTE etiquette_Radiotext2; // tout en bas, en mode 'catalogue'
  129.  
  130.  
  131. PAGE_TEXTE page_stations;
  132.  
  133. TOUCH_BOUTON bt_SCAN_stations;
  134. TOUCH_BOUTON bt_param; // d'affichage
  135. TOUCH_BOUTON bt_mode_expert; // situé sur la page 'catalogue' pour basculer en mode 'expert'
  136. TOUCH_BOUTON bt_mode_catalogue; // situé sur la page 'expert' pour basculer en mode 'catalogue'
  137.  
  138.  
  139. TOUCH_BOUTON bt_LOGO; // bouton caché sous le logo de la station, sert à l'afficher en tout-écran
  140. TOUCH_BOUTON bt_img2; // caché sous l'image reçue (celle affichée sous le "catalogue")
  141. TOUCH_BOUTON bt_stop_tout_ecran; // petit bouton en haut à gauche
  142.  
  143. TOUCH_BOUTON bt_to_SD; // save params to SDcard
  144. TOUCH_BOUTON bt_cal; // calibrage du tactile
  145.  
  146. TOUCH_BOUTON_IMG bt_img1;
  147.  
  148. TOUCH_BOUTON bt_capture_ecran;
  149.  
  150.  
  151. PANEL_BOUTONS panel_bt_multiplex;
  152. PANEL_BOUTONS panel_bt_stations;
  153.  
  154. GRID_PAD gridPad1; // boutons invisibles sous l'image du "catalogue" de sélection de station (en tout-écran)
  155.  
  156. String libels_stations0[13]={"-","-","-","-","-","-","-","-","-","-","-","-","-"};
  157. String libels_stations1[13]={"-","-","-","-","-","-","-","-","-","-","-","-","-"};
  158. String libels_stations2[13]={"-","-","-","-","-","-","-","-","-","-","-","-","-"};
  159. String libels_stations3[13]={"-","-","-","-","-","-","-","-","-","-","-","-","-"};
  160.  
  161. String RadioText;
  162. uint8_t decal_tx=0;
  163.  
  164. struct STATION
  165. {
  166. uint8_t n_ml; // 0..3
  167. uint8_t n_st; // 0..12
  168. String s; // "/slideshows/generiques/320x240/F2F8_NRJ.jpg"; // sur SDcard
  169. };
  170.  
  171. STATION lst_sta[52]; // liste des stations; 4 multiplex de 13 stations
  172.  
  173.  
  174. String incomingBase64 = "";
  175. boolean receivingSLS = false;
  176.  
  177. uint8_t num_bt_M; // 0..3
  178. uint8_t num_M; // ex : 21
  179. //uint8_t num_bt_M;
  180.  
  181. boolean choix_mutiplex_ok = false;
  182.  
  183. uint8_t num_bt_S;
  184. uint8_t num_S;
  185.  
  186. uint32_t Sid;
  187. uint16_t compte=0;
  188. uint16_t couleur_fond_ecran = 229; // outil : https://rgbcolorpicker.com/565
  189.  
  190. enum GENERAL_MODE {MODE_EXPERT, MODE_PARAM, MODE_CATALOGUE};
  191. GENERAL_MODE mode_general;
  192.  
  193. enum AFFI_MODE {MODE_PETITE, MODE_TOUT_ECRAN}; // de l'image
  194. AFFI_MODE mode_affi;
  195.  
  196. //boolean LOGO_tt_ecran= false;
  197.  
  198.  
  199. // États de la machine à états de réception
  200. enum RX_STATE { WAIT_START, RECEIVING_DATA };
  201. RX_STATE rxState = WAIT_START;
  202.  
  203.  
  204. #define MAX_SLIDE_SIZE 51200 // Buffer statique de 50 Ko (suffisant (?) pour un MOT Slideshow DAB+ de 320x240)
  205. uint8_t currentSlideBuffer[MAX_SLIDE_SIZE];
  206. size_t currentSlideSize = 0;
  207.  
  208. size_t imgRAM_Size = 0; // taille de l'image enregistrée en RAM
  209.  
  210.  
  211. String base64Buffer = "";
  212. size_t expectedLen = 0;
  213.  
  214. String logo_generique_en_cours;
  215. String memo_logo_generique_en_cours; // propre à la station, par défaut
  216.  
  217. String logo_en_cours;
  218. String memo_logo_en_cours;
  219. boolean logo_courant = false;
  220.  
  221.  
  222. //-----------------------------------------------------------------------------------
  223. float degTOrad(float angle) {return (angle * M_PI / 180.0);}
  224.  
  225. uint8_t decToBcd(int val) {return (uint8_t) ((val / 10 * 16) + (val % 10));}
  226. uint16_t Color_To_565(uint8_t r, uint8_t g, uint8_t b) {return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3);}
  227.  
  228.  
  229.  
  230. void RGB565_to_888(uint16_t color565, uint8_t *R, uint8_t *G, uint8_t *B)
  231. {
  232. *R=(color565 & 0xF800) >> 8;
  233. *G=(color565 & 0x7E0) >> 3;
  234. *B=(color565 & 0x1F) << 3 ;
  235. }
  236.  
  237.  
  238.  
  239.  
  240. String desaccentue(String str)
  241. {
  242. String out = "";
  243. uint8_t c;
  244. for (int i = 0; i < str.length(); i++)
  245. {
  246. c = str[i];
  247. if (c < 128){out += (char)c;}
  248.  
  249. switch (c)
  250. {
  251. case 0x90:
  252. case 0x81:
  253. out += 'a';
  254. break;
  255. case 0x82:
  256. case 0x83:
  257. case 0x92:
  258. case 0x93:
  259. out += 'e';
  260. break;
  261. case 0x89: // ù
  262. out += 'u';
  263. break;
  264. case 0x9B: // ç
  265. out += 'c';
  266. break;
  267. }
  268. }
  269. return out;
  270. }
  271.  
  272.  
  273.  
  274. void TS_calibrate() // calibrage de l'écran tactile
  275. {
  276. uint8_t L = 20;
  277. boolean ok;
  278. String s1;
  279.  
  280. TFT.setTextColor(BLANC, NOIR);
  281. TFT.setFreeFont(FF1);
  282.  
  283. // traitement point A
  284. TFT.fillScreen(NOIR);
  285. TFT.drawString("Cliquez sur le point A", 20, 50);
  286. delay(300);
  287. TFT.drawFastVLine(10, 0, L, JAUNE);
  288. TFT.drawFastHLine(0, 10, L, JAUNE);
  289. ok = false;
  290. while (! ok)
  291. {
  292. if (ts.tirqTouched() && ts.touched())
  293. {
  294. memo_y_touch = y_touch;
  295. TS_Point p = ts.getPoint();
  296. s1 = "Ax=" + String(p.x) + " "; TFT.drawString(s1, 50, 100);
  297. s1 = "Ay=" + String(p.y) + " "; TFT.drawString(s1, 50, 120);
  298. delay(100);
  299.  
  300. if( (p.x<600) && (p.y < 600)) // évite de valider une position irréaliste
  301. {
  302. A.x = p.x; // point A : variable globale
  303. A.y = p.y;
  304. ok = true;
  305. }
  306. }
  307. }
  308.  
  309. // traitement point B
  310. TFT.fillScreen(NOIR);
  311. delay(300);
  312. TFT.drawString("Cliquez sur le point B", 20, 70);
  313. TFT.drawFastVLine(310, 230-L/2, L, JAUNE);
  314. TFT.drawFastHLine(310-L/2, 230, L, JAUNE);
  315. ok = false;
  316. while (! ok)
  317. {
  318. if (ts.tirqTouched() && ts.touched())
  319. {
  320. memo_y_touch = y_touch;
  321. TS_Point p = ts.getPoint();
  322. s1 = "Bx=" + String(p.x) + " "; TFT.drawString(s1, 50, 150);
  323. s1 = "By=" + String(p.y) + " "; TFT.drawString(s1, 50, 170);
  324. delay(100);
  325.  
  326. if( (p.x>3600) && (p.y > 3400)) // évite de valider une position irréaliste
  327. {
  328. B.x = p.x;
  329. B.y = p.y;
  330. ok = true;
  331. }
  332. }
  333. }
  334.  
  335. if(SDcardOk==1)
  336. {
  337. TFT.fillScreen(NOIR);
  338. TFT.drawString("Ok", 20, 60);
  339. TFT.setFreeFont(FF0);
  340. TFT.drawString("Write fichier params sur la SD", 10, 90);
  341. write_params_tactile_SD();
  342. delay(1000);
  343. }
  344. TFT.fillScreen(NOIR);
  345. }
  346.  
  347.  
  348. void init_sprites()
  349. {
  350. sprite_frq.createSprite(220, 55);
  351. sprite_frq.loadFont(digitfont1);
  352. //sprite_frq.setTextColor(JAUNE_2, NOIR);
  353. sprite_frq.setTextDatum(MR_DATUM); // alignement du texte
  354. }
  355.  
  356.  
  357. void init_SDcard()
  358. {
  359. Serial.println("---------------------");
  360. Serial.println("init_SDcard()");
  361. String s1;
  362.  
  363. TFT.fillRect(0, 0, 480, 320, NOIR); // efface
  364. TFT.setTextColor(BLANC, NOIR);
  365. TFT.setFreeFont(FF1);
  366.  
  367. if(!SD.begin(5, mySpi2))
  368. {
  369. Serial.println("Card Mount Failed");
  370. SDcardOk=0;
  371. }
  372. else
  373. {
  374. Serial.println("SDcard OK");
  375. SDcardOk=1;
  376. TFT.fillRect(0, 0, 480, 320, VERT);
  377. delay(100);
  378. }
  379.  
  380. uint8_t cardType = SD.cardType();
  381.  
  382. if(cardType == CARD_NONE)
  383. {
  384. Serial.println("NO SDcard");
  385. SDcardOk=0;
  386. return;
  387. }
  388.  
  389. Serial.print("SDcard Type: ");
  390. if(cardType == CARD_SD) {Serial.print("SDSC");}
  391. else if(cardType == CARD_SDHC) {Serial.println("SDHC");}
  392.  
  393. uint32_t cardSize = SD.cardSize() / (1024 * 1024);
  394. s1=(String)cardSize + " GB";
  395. Serial.println(s1); Serial.println();
  396.  
  397. delay (100);
  398. TFT.fillRect(0, 0, 480, 320, NOIR); // efface
  399. }
  400.  
  401.  
  402. uint16_t read_16(File fp)
  403. {
  404. uint8_t low;
  405. uint16_t high;
  406. low = fp.read();
  407. high = fp.read();
  408. return (high<<8)|low;
  409. }
  410.  
  411.  
  412. uint32_t read_32(File fp)
  413. {
  414. uint16_t low;
  415. uint32_t high;
  416. low = read_16(fp);
  417. high = read_16(fp);
  418. return (high<<8)|low;
  419. }
  420.  
  421.  
  422. void write_TFT_on_SDcard(String filename) // capture image bmp 320x240 RGB565 (5+6+5 = 16bits/px)
  423. {
  424. // Fonction optimisée pour l'afficheur ILI9341 avec la library 'TFT_eSPI'
  425. // ne convient PAS pour les ESP32 Wroom + afficheur 3.5" TFT 480x320
  426. Serial.println("write_TFT_on_SDcard()");
  427.  
  428. Serial.print("SDcardOk = "); Serial.println(SDcardOk);
  429.  
  430. if (SDcardOk==0) {return;}
  431. uint8_t lineBuffer8[(320*2)];
  432. uint16_t lineBuffer16[320];
  433. uint8_t octet_A, octet_B;
  434.  
  435. TFT.readRect(0, 100, 320, 1, lineBuffer16); // lit une seule ligne
  436. TFT.drawString("A", 310, 230); // pour terminer par une écriture sinon pas de write sur la SD plus bas
  437.  
  438. //File file1 = SD.open("/bmp565/capture.bmp", FILE_WRITE);
  439. File file1 = SD.open(filename, FILE_WRITE);
  440. if (file1)
  441. {
  442. // création entête bmp565 - 138 octets; voir bmp565_header[] dans le fichier main.h
  443. for(uint8_t i=0; i<138; i++) { file1.write(bmp565_header[i]); }
  444.  
  445. for (int16_t y=240; y>0; y--)
  446. {
  447. TFT.readRect(0, y, 320, 1, lineBuffer16); // lit une ligne
  448. TFT.drawString("A", 310, 230); // pour terminer par une écriture
  449.  
  450. uint16_t i=0;
  451. for (int16_t x=0; x<320; x++) //320
  452. {
  453. color565px = lineBuffer16[x]; // BBBBBrrr rrrVVVVV
  454. octet_A = (color565px & 0b1111111100000000) >> 8;
  455. octet_B = (color565px & 0b0000000011111111);
  456.  
  457. lineBuffer8[i] = octet_A;
  458. lineBuffer8[i+1] = octet_B;
  459. i+=2;
  460. }
  461. file1.write(lineBuffer8, sizeof(lineBuffer8));
  462. }
  463. Serial.println("write end - Ok");
  464. file1.close(); // referme le fichier
  465. //TFT.fillRect(170, 115, 20, 8, VERT);
  466. }
  467. }
  468.  
  469.  
  470.  
  471. void affi_BMP_from_SD(String filename, uint16_t x0, uint16_t y0)
  472. {
  473. Serial.println("----------------------------");
  474. Serial.println("affi_BMP_from_SD()");
  475.  
  476. uint8_t bmp_data[2]={0,0};
  477. uint8_t a, b;
  478. uint16_t x=0;
  479. uint16_t y=0;
  480. int16_t xmax;
  481.  
  482. uint32_t seekOffset;
  483. uint16_t w, h, row, col;
  484.  
  485.  
  486. File fp = SD.open(filename, "r");
  487. if (!fp) { Serial.println("ERREUR open file on SD"); return; }
  488.  
  489. uint16_t etiq1 = read_16(fp);
  490.  
  491. // test bmp_header
  492. if (etiq1 == 0x4D42)
  493. {
  494. read_32(fp);
  495. read_32(fp);
  496. seekOffset = read_32(fp);
  497. Serial.print("seekOffset ="); Serial.println(seekOffset); // 138
  498.  
  499. Serial.print("seekOffset= "); Serial.println(seekOffset);
  500. read_32(fp);
  501. w = read_32(fp);
  502. h = read_32(fp);
  503. Serial.print("w= "); Serial.println(w); // 75
  504. Serial.print("h= "); Serial.println(h); // 50
  505. Serial.println(read_16(fp)); // 1
  506. Serial.println(read_16(fp)); // 16
  507. Serial.println(read_16(fp)); // 3
  508. fp.seek(seekOffset);
  509. }
  510.  
  511. y += h;
  512. xmax = w;
  513. if(xmax%2 == 1) {xmax +=1;}
  514.  
  515. uint16_t padding = (4 - ((w * 2) & 2)) & 2;
  516. uint8_t lineBuffer[(w*2) + padding];
  517.  
  518. for (row = 0; row < h; row++)
  519. {
  520. fp.read(lineBuffer, sizeof(lineBuffer));
  521. uint8_t* bptr = lineBuffer;
  522. uint16_t* tptr = (uint16_t*)lineBuffer;
  523.  
  524. for (uint16_t col = 0; col < w; col++)
  525. {
  526. a = *bptr++;
  527. b = *bptr++;
  528. *tptr++ = (a <<8 | b);
  529. }
  530. TFT.pushImage(x0 + x, y0 + y, w, 1, (uint16_t*)lineBuffer);
  531. y--;
  532. }
  533. fp.close();
  534. }
  535.  
  536.  
  537.  
  538. void affi_jpg_from_SD(String filename, uint16_t x0, uint16_t y0)
  539. {
  540. //affichage direct de l'image contenue sur la SDcard
  541. TFT.fillRect(x0, y0, 178, 136, NOIR);
  542. TJpgDec.setJpgScale(2); // Échelle
  543. TJpgDec.setCallback(tft_output);
  544. TJpgDec.drawSdJpg(x0+4, y0+3, logo_en_cours);
  545. }
  546.  
  547.  
  548.  
  549. void affi_jpg_from_RAM( uint16_t x0, uint16_t y0, uint8_t echelle)
  550. {
  551. TJpgDec.setJpgScale(echelle); // 1 = grand
  552. TJpgDec.setCallback(tft_output);
  553. TJpgDec.drawJpg(x0, y0, currentSlideBuffer, currentSlideSize); // variables globales
  554. }
  555.  
  556.  
  557.  
  558. void copie_jpg_from_SD_to_RAM(String filename)
  559. {
  560. File file1 = SD.open(filename, FILE_READ);
  561. if (!file1) { Serial.println("Erreur : impossible d'ouvrir le fichier");}
  562. size_t imageSize = file1.size();
  563. size_t bytesRead = file1.read(currentSlideBuffer, imageSize); //image en SD -> RAM
  564. currentSlideSize = imageSize;
  565. file1.close();
  566. }
  567.  
  568.  
  569.  
  570.  
  571. void write_params_multiplex_SD() // sur la SDcard
  572. {
  573. Serial.println("write fichier '/params_multiplex.txt'");
  574.  
  575. File file1 = SD.open("/params_multiplex.txt", FILE_WRITE);
  576. String s1;
  577.  
  578. // enregistrement des numéros des multiplex de la région
  579. s1 ="[n_mult_0]"; s1 += "<"; s1 += String(n_mult_0); s1 +=">";
  580. file1.println(s1);
  581.  
  582. s1 ="[n_mult_1]"; s1 += "<"; s1 += String(n_mult_1); s1 +=">";
  583. file1.println(s1);
  584.  
  585. s1 ="[n_mult_2]"; s1 += "<"; s1 += String(n_mult_2); s1 +=">";
  586. file1.println(s1);
  587.  
  588. s1 ="[n_mult_3]"; s1 += "<"; s1 += String(n_mult_3); s1 +=">";
  589. file1.println(s1);
  590.  
  591. file1.close();
  592. delay(100);
  593. }
  594.  
  595.  
  596.  
  597. void write_params_stations_SD(uint8_t multiplex, String libels[13]) // sur la SDcard
  598. {
  599. Serial.println("write fichier '/params_stations.txt'");
  600.  
  601. File file1 = SD.open("/params_stations.txt", FILE_APPEND); // ajoute à la fin sans effacer les données présentes
  602. String s1;
  603.  
  604. // enregistrement des numéros des labels des stations
  605.  
  606. for(int n=0; n<13; n++)
  607. {
  608. String sn = String(n); if (n<10) {sn = '0' + sn;}
  609. String mpx = String(multiplex); if (multiplex<10) {mpx = '0' + mpx;}
  610.  
  611. String s_L = libels[n];
  612. Serial.print("s_L= "); Serial.println(s_L);
  613.  
  614. s_L= s_L.substring(0, 20); //5 char pour l'ID + 15 char pour le label
  615. s1 ="[label_"; s1+=mpx; s1+="_"; s1+=sn; s1+="]<"; s1+=s_L; s1+=">"; // [label_01_06]<NOSTALGIE>
  616. Serial.print("s1= "); Serial.println(s1);
  617.  
  618. file1.println(s1);
  619. }
  620. file1.println("----");
  621.  
  622. file1.close();
  623. delay(100);
  624. }
  625.  
  626.  
  627. size_t getJpegSize(const uint8_t* buffer, size_t maxBufferSize)
  628. {
  629. // On cherche la séquence 0xFF 0xD9 (End Of Image)
  630. for (size_t i = 0; i < maxBufferSize - 1; i++)
  631. {
  632. if (buffer[i] == 0xFF && buffer[i + 1] == 0xD9)
  633. {
  634. return i + 2; // On inclut les 2 octets de fin dans la taille totale
  635. }
  636. }
  637. return 0; // Marqueur non trouvé (image corrompue ou trop grande)
  638. }
  639.  
  640.  
  641. int compte_Fichiers(fs::FS &fs, const char * dirname)
  642. {
  643. int compteur = 0;
  644. File root = fs.open(dirname);
  645.  
  646. if (!root || !root.isDirectory()) {return -1;} // Erreur d'ouverture ou n'est pas un dossier
  647.  
  648. File file = root.openNextFile();
  649. while (file)
  650. {
  651. if (!file.isDirectory()) {compteur++; }
  652. file = root.openNextFile();
  653. }
  654. return compteur;
  655. }
  656.  
  657.  
  658. // Cherche, ouvre et lit le premier fichier commençant par "ABCD" à la racine "/"
  659. // absolute_path(SD, "/", "ABCD");
  660. String absolute_path(fs::FS &fs, const char * dirname, String prefixe)
  661. {
  662. String cheminComplet;
  663. File root = fs.open(dirname);
  664.  
  665. if(!root || !root.isDirectory())
  666. {
  667. Serial.println("Erreur d'ouverture du repertoire");
  668. return ("");
  669. }
  670.  
  671. File file = root.openNextFile();
  672. bool trouve = false;
  673. while(file)
  674. {
  675. if(!file.isDirectory())
  676. {
  677. String nomFichier = String(file.name());
  678. // Si le fichier commence par le préfixe
  679. if(nomFichier.startsWith(prefixe))
  680. {
  681. //Serial.println("Fichier trouve");
  682. trouve = true;
  683.  
  684. // Sur l'ESP32, file.name() inclut déjà le '/' initial si on est à la racine.
  685. // Pour être sûr du chemin absolu (surtout dans un sous-dossier), on reconstruit le chemin complet :
  686. cheminComplet = String(dirname) + (String(dirname).endsWith("/") ? "" : "/") + nomFichier;
  687.  
  688. }
  689. file = root.openNextFile();
  690. }
  691. }
  692. root.close();
  693.  
  694. Serial.println(cheminComplet);
  695. return cheminComplet;
  696. }
  697.  
  698.  
  699.  
  700. void write_image_jpg_to_SD(uint8_t *jpgBuffer)
  701. {
  702. Serial.println("write_image_jpg_to_SD");
  703.  
  704. uint16_t nb_fichiers;
  705. String filename;
  706. //const size_t TAILLE_MAX = 20480;
  707.  
  708. boolean next = true;
  709. uint16_t n = 0;
  710. while(next && (n < 1000) )
  711. {
  712. filename = "/slideshows/courants/" + String(n) + ".jpg";
  713. if (! SD.exists(filename))
  714. {
  715. File file1 = SD.open(filename, FILE_WRITE);
  716. size_t length = getJpegSize(jpgBuffer, MAX_SLIDE_SIZE);
  717. Serial.println("AAA");
  718. Serial.print("length= "); Serial.println(length); // ok
  719. currentSlideSize = length;
  720. size_t bytesWritten = file1.write(jpgBuffer, length);
  721. file1.close();
  722. // memo_logo_en_cours = filename;
  723. next = false;
  724. }
  725. n++;
  726. }
  727. }
  728.  
  729.  
  730. void write_params_tactile_SD()
  731. {
  732. Serial.println("write fichier '/params_tactile.txt'");
  733.  
  734. File file1 = SD.open("/params_tactile.txt", FILE_WRITE);
  735. String s1;
  736.  
  737. // enregistrement de la calibration de l'écran tactile :
  738.  
  739. s1 ="[Ax]"; s1 += "<"; s1 += String(A.x); s1 +=">";
  740. file1.println(s1);
  741.  
  742. s1 ="[Ay]"; s1 += "<"; s1 += String(A.y); s1 +=">";
  743. file1.println(s1);
  744.  
  745. s1 ="[Bx]"; s1 += "<"; s1 += String(B.x); s1 +=">";
  746. file1.println(s1);
  747.  
  748. s1 ="[By]"; s1 += "<"; s1 += String(B.y); s1 +=">";
  749. file1.println(s1);
  750.  
  751. file1.println("----");
  752.  
  753. file1.close();
  754. delay(100);
  755.  
  756. }
  757.  
  758.  
  759.  
  760. String read_line_params(uint16_t line_num, String filename)
  761. {
  762. Serial.println("read_line_params()");
  763.  
  764. int i = 1;
  765. char buffer[64];
  766. String s;
  767.  
  768. File file = SD.open(filename, "r");
  769.  
  770. while (file.available())
  771. {
  772. int l = file.readBytesUntil('\n', buffer, sizeof(buffer));
  773. buffer[l] = 0;
  774. if (line_num == i)
  775. {
  776. s = buffer;
  777. file.close();
  778. return(s);
  779. }
  780. i++;
  781. }
  782. return "";
  783. }
  784.  
  785.  
  786. int32_t extract_valeur(String ligne, String label)
  787. {
  788. String s2;
  789. uint32_t valeur = 0;
  790. int p1, p2;
  791.  
  792. p1 = ligne.indexOf('['); p2 = ligne.indexOf(']');
  793. s2 = ligne.substring(p1+1, p2);
  794.  
  795. if (s2 == label)
  796. {
  797. p1 = ligne.indexOf('<'); p2 = ligne.indexOf('>');
  798. s2 = ligne.substring(p1+1, p2);
  799. valeur = s2.toInt();
  800. return valeur;
  801. }
  802. return -1;
  803. }
  804.  
  805.  
  806.  
  807. String extract_texte(String ligne, String label)
  808. {
  809. Serial.println("extract_texte()");
  810.  
  811. String s1;
  812. String s2="";
  813. int p1, p2, p3;
  814.  
  815. String sx = "[" + label + "]";
  816. int L= sx.length();
  817. p1 = ligne.indexOf(sx);
  818.  
  819. p2 = ligne.indexOf('<', p1); p3 = ligne.indexOf('>', p2);
  820. s2 = ligne.substring(p2+1, p3);
  821. return s2;
  822. }
  823.  
  824.  
  825.  
  826.  
  827. void read_fichier_params_tactile() // lecture du fichier '/params_tactile.txt' en SD
  828. {
  829. Serial.println("lecture du fichier 'params_tactile.txt' en SD");
  830. String s1;
  831. int valeur;
  832.  
  833. s1 = "Z";
  834. uint8_t n=1;
  835. while (s1 !="")
  836. {
  837. s1 = read_line_params(n, "/params_tactile.txt"); // retourne (par exemple): [Ax]<534>
  838.  
  839. // calibrage de l'écran tactile :
  840. valeur = extract_valeur(s1, "Ax");
  841. if(valeur != -1) {A.x = valeur;}
  842.  
  843. valeur = extract_valeur(s1, "Ay");
  844. if(valeur != -1) {A.y = valeur;}
  845.  
  846. valeur = extract_valeur(s1, "Bx");
  847. if(valeur != -1) {B.x = valeur;}
  848.  
  849. valeur = extract_valeur(s1, "By");
  850. if(valeur != -1) {B.y = valeur;}
  851.  
  852. n++;
  853. }
  854. }
  855.  
  856.  
  857. void read_params_multiplex()
  858. {
  859. String s1;
  860. int valeur;
  861.  
  862. s1 = "Z";
  863. uint8_t n=1;
  864. while (s1 !="")
  865. {
  866. s1 = read_line_params(n, "/params_multiplex.txt"); // retourne (par exemple): [couleur_fond]<267>
  867.  
  868. // numéros de 4 multiplex de la région
  869. valeur = extract_valeur(s1, "n_mult_0");
  870. if(valeur != -1) {n_mult_0= valeur;}
  871.  
  872. valeur = extract_valeur(s1, "n_mult_1");
  873. if(valeur != -1) {n_mult_1 = valeur;}
  874.  
  875. valeur = extract_valeur(s1, "n_mult_2");
  876. if(valeur != -1) {n_mult_2 = valeur;}
  877.  
  878. valeur = extract_valeur(s1, "n_mult_3");
  879. if(valeur != -1) {n_mult_3 = valeur;}
  880.  
  881. n++;
  882. }
  883. }
  884.  
  885.  
  886. // voir aussi 'write_params_stations_SD('
  887. void read_fichier_params_stations() // lecture du fichier '/params_stations.txt' en SD
  888. {
  889. String ligne_i;
  890. String label_i;
  891. String smult, sbouton;
  892. uint8_t n_bouton;
  893. uint8_t n_mult;
  894.  
  895. ligne_i= "Z";
  896. uint8_t p1, p2, p3, p4;
  897. String s1, s2;
  898.  
  899. for(int n=1; n<56; n++) // 56 ok (le fichier fait 56 lignes, 4 + 13*4 )
  900. {
  901. ligne_i = read_line_params(n, "/params_stations.txt"); // retourne (par exemple): [label_02_10]<FRANCE MUSIQUE>
  902. Serial.print("ligne_i= "); Serial.println(ligne_i);
  903. // [label_02_10]<FRANCE MUSIQUE> le 1er nombre est le n° du multiplex; le second est le numéro de la station
  904.  
  905. p1 = ligne_i.indexOf('_');
  906. s1 = ligne_i.substring(p1+1, p1+3);
  907. n_mult = s1.toInt();
  908.  
  909. p2 = ligne_i.indexOf('_', p1+2); // le second
  910. s2 = ligne_i.substring(p2+1, p2+3);
  911. n_bouton = s2.toInt();
  912.  
  913. p3 = ligne_i.indexOf('<'); p4 = ligne_i.indexOf('>', p3);
  914. label_i = ligne_i.substring(p3+1, p4);
  915.  
  916. if(n_mult==0) { libels_stations0[n_bouton] = label_i;}
  917. if(n_mult==1) { libels_stations1[n_bouton] = label_i;}
  918. if(n_mult==2) { libels_stations2[n_bouton] = label_i;}
  919. if(n_mult==3) { libels_stations3[n_bouton] = label_i;}
  920.  
  921. // libels_stations[n_mult][n_bouton] = label_i;
  922.  
  923. }
  924. }
  925.  
  926.  
  927. void affi_page_info()
  928. {
  929. TFT.fillScreen(NOIR);
  930. TFT.setTextColor(JAUNE, NOIR); TFT.setFreeFont(FF1);
  931. uint16_t y=0;
  932. TFT.drawString("Radio DAB+ Si4684 ", 0, y); y+=20;
  933. String s1="version " + version;
  934. TFT.drawString(s1, 0, y); y+=20;
  935.  
  936. TFT.setTextColor(CYAN, NOIR);
  937. TFT.drawString("Silicium628", 0, y); y+=40;
  938. }
  939.  
  940.  
  941. void trace_sinusoide()
  942. {
  943. float y;
  944. float v;
  945. for (uint16_t n=0; n<320; n++)
  946. {
  947. v = (float)n/20.0;
  948. y = 180-50*sin(v);
  949. TFT.drawPixel(n, (int)y, VERT);
  950. }
  951. }
  952.  
  953. //rappel:
  954. //void PANEL_BOUTONS::init( x_i, y_i, dxT_i, dyT_i, nb_boutons_i, String nom_i, String s_i[6], char sens_i, TFT_eSPI *TFTi)
  955.  
  956. void affichage_boutons_stations()
  957. {
  958. //panel_bt_stations.init(10, 3, 120, 220, 13,"Stations", libels_stations2, 'V', &TFT);
  959.  
  960. if(num_bt_M == 0) { panel_bt_stations.init(10, 10, 120, 213, 13,"Stations", libels_stations0, 'V', &TFT); }
  961. if(num_bt_M == 1) { panel_bt_stations.init(10, 10, 120, 213, 13,"Stations", libels_stations1, 'V', &TFT); }
  962. if(num_bt_M == 2) { panel_bt_stations.init(10, 10, 120, 213, 13,"Stations", libels_stations2, 'V', &TFT); }
  963. if(num_bt_M == 3) { panel_bt_stations.init(10, 10, 120, 213, 13,"Stations", libels_stations3, 'V', &TFT); }
  964.  
  965. // panel_bt_stations.init(10, 10, 120, 213, 13,"Stations", libels_stations[num_bt_M], 'V', &TFT);
  966.  
  967. panel_bt_stations.efface(&TFT);
  968. panel_bt_stations.affiche(&TFT);
  969.  
  970. }
  971.  
  972.  
  973. void affichages_widgets_expert()
  974. {
  975. etiquette_rssi.init(130, 28, 45, 20, "", &TFT); // etiquette_rssi.init(130, 28, 45, 20, "rssi:", &TFT);
  976. etiquette_rssi.affiche("0", 0, 1, &TFT);
  977.  
  978. etiquette_ID.init(180, 28, 48, 20, "", &TFT); // etiquette_ID.init(180, 28, 48, 20, "ID:", &TFT);
  979. etiquette_ID.affiche("0", 0, 1, &TFT);
  980.  
  981. bt_mode_catalogue.init(270, 28, 35, 18, 3, GRIS_5);
  982. bt_mode_catalogue.label =" CAT"; // goto catalogue
  983. bt_mode_catalogue.affiche(BLANC, VERT, 1, &TFT);
  984. affi_BMP_from_SD("/bmp565/stations2.bmp", 269, 24); // toute petite image du cataloque
  985. TFT.drawRect(268, 24, 42, 23, BLANC);
  986.  
  987. bt_param.init(230, 28, 35, 18, 3, GRIS_5);
  988. bt_param.label ="PARAM";
  989. bt_param.affiche(BLANC, VERT, 1, &TFT);
  990.  
  991.  
  992. bt_LOGO.init(150, 90, 140, 80, 1, BLEU);
  993. //bt_LOGO.affiche(BLANC, VERT, 1, &TFT);
  994.  
  995.  
  996. etiquette_LABEL1.init(130, 50, 180, 18, "", &TFT); // en haut
  997. etiquette_LABEL1.affiche("-", 0, 1, &TFT);
  998.  
  999. String libels_mutiplex[13];
  1000. String s1;
  1001. s1 = " "; s1 += Table_Multiplex[n_mult_0].label; libels_mutiplex[0] = s1; // (lu sur la SDcard)
  1002. s1 = " "; s1 += Table_Multiplex[n_mult_1].label; libels_mutiplex[1] = s1;
  1003. s1 = " "; s1 += Table_Multiplex[n_mult_2].label; libels_mutiplex[2] = s1;
  1004. s1 = " "; s1 += Table_Multiplex[n_mult_3].label; libels_mutiplex[3] = s1;
  1005.  
  1006. panel_bt_multiplex.init(135, 5, 180, 20, 4,"", libels_mutiplex, 'H', &TFT);
  1007. panel_bt_multiplex.affiche(&TFT);
  1008.  
  1009. etiquette_Radiotext1.init(0, 215, 310, 18, "", &TFT);// 305
  1010. etiquette_Radiotext1.affiche("-", 0, 1, &TFT);
  1011.  
  1012. //affichage_boutons_stations();
  1013.  
  1014. page_stations.init(130, 73, 180, 140, GRIS_5, "", &TFT);
  1015.  
  1016. if (mode_general == MODE_PARAM)
  1017. {
  1018. page_stations.init(130, 73, 180, 140, BLEU, "", &TFT);
  1019.  
  1020. bt_to_SD.init(140, 110, 50, 20, 3, GRIS_5);
  1021. bt_to_SD.label =" -> SD";
  1022. bt_to_SD.affiche(BLANC, VERT, 1, &TFT);
  1023.  
  1024. bt_cal.init(140, 140, 50, 20, 3, GRIS_5);
  1025. bt_cal.label ="CALIB";
  1026. bt_cal.affiche(BLANC, VERT, 1, &TFT);
  1027.  
  1028. bt_SCAN_stations.init(140, 80, 50, 20, 3, GRIS_5);
  1029. bt_SCAN_stations.label = " SCAN";
  1030. bt_SCAN_stations.affiche(BLANC, VERT, 1, &TFT);
  1031. }
  1032.  
  1033. // TFT.drawRect(150, 90, 140, 80, BLANC); while(1); // pour test
  1034.  
  1035. }
  1036.  
  1037.  
  1038.  
  1039. void affichages_widgets_catalogue()
  1040. {
  1041. etiquette_ID.init(170, 197, 48, 20, "", &TFT);
  1042. etiquette_ID.affiche("0", 0, 1, &TFT);
  1043.  
  1044. etiquette_Radiotext2.init(170, 220, 150, 18, "", &TFT);
  1045.  
  1046.  
  1047. bt_img2.init(82, 175, 85, 65, 1, BLEU);
  1048. //bt_img2.affiche(BLANC, VERT, 1, &TFT); pour test positionnement
  1049.  
  1050. bt_mode_expert.init(270, 198, 48, 20, 3, GRIS_5);
  1051. bt_mode_expert.label =" EXPERT";
  1052. bt_mode_expert.affiche(BLANC, VERT, 1, &TFT); // seulement CE bouton
  1053. }
  1054.  
  1055.  
  1056.  
  1057. void encadre_bouton_catalogue(uint8_t n)
  1058. {
  1059. uint16_t x, y, dx, dy;
  1060.  
  1061. x = gridPad1.bt_grid[memo_n_bt_cat].x0;
  1062. y = gridPad1.bt_grid[memo_n_bt_cat].y0;
  1063. dx = gridPad1.bt_grid[memo_n_bt_cat].dx;
  1064. dy = gridPad1.bt_grid[memo_n_bt_cat].dy;
  1065. TFT.drawRect(x, y, dx, dy, NOIR); // efface
  1066.  
  1067. x = gridPad1.bt_grid[n].x0;
  1068. y = gridPad1.bt_grid[n].y0;
  1069. dx = gridPad1.bt_grid[n].dx;
  1070. dy = gridPad1.bt_grid[n].dy;
  1071.  
  1072. TFT.drawRect(x, y, dx, dy, BLANC);
  1073.  
  1074. memo_n_bt_cat=n;
  1075.  
  1076. }
  1077.  
  1078.  
  1079. String convert_Dec_To_Hex(uint32_t n)
  1080. {
  1081. String hexNum;
  1082. long reste;
  1083.  
  1084. while (n > 0)
  1085. {
  1086. reste = n % 16;
  1087. n = n / 16;
  1088. if (reste < 10)
  1089. {
  1090. hexNum = String(reste) + hexNum;
  1091. }
  1092. else
  1093. {
  1094. switch (reste)
  1095. {
  1096. case 10: hexNum = "A" + hexNum; break;
  1097. case 11: hexNum = "B" + hexNum; break;
  1098. case 12: hexNum = "C" + hexNum; break;
  1099. case 13: hexNum = "D" + hexNum; break;
  1100. case 14: hexNum = "E" + hexNum; break;
  1101. case 15: hexNum = "F" + hexNum; break;
  1102. }
  1103. }
  1104. }
  1105. return hexNum;
  1106. }
  1107.  
  1108.  
  1109. void send_multiplex_to_ESP_radio(uint8_t n_multiplex) // voir la fonction 'void reception()' dans le fichier 'main_RADIO.cpp'
  1110. {
  1111. Serial.println("send_multiplex_to_ESP_radio()");
  1112. Serial.print("multiplex="); Serial.println(n_multiplex);
  1113. String s1;
  1114. s1 += "[multiplex]<";
  1115. s1 += String(n_multiplex);
  1116. s1 +="> ";
  1117. Serial2.println(s1);
  1118. delay(100);
  1119. }
  1120.  
  1121.  
  1122.  
  1123. void send_station_to_ESP_radio(uint8_t n_station) // voir la fonction 'void reception()' dans le fichier 'main_RADIO.cpp'
  1124. {
  1125. Serial.println("send_station_to_ESP_radio()");
  1126. Serial.print("station="); Serial.println(n_station);
  1127. String s1;
  1128. s1 += "[station]<";
  1129. s1 += String(n_station);
  1130. s1 +=">";
  1131. Serial2.println(s1);
  1132. }
  1133.  
  1134.  
  1135.  
  1136. // Multiplex Montpellier étendu, Canal 11C - 220.352 MHz
  1137.  
  1138. void calcul_num_M(uint8_t n_bt_mlt)
  1139. {
  1140. delay(100);
  1141. switch (n_bt_mlt)
  1142. {
  1143. case 0: {num_M = n_mult_0; } break; // 9C n_mult_0 =18;
  1144. case 1: {num_M = n_mult_1; } break; // 10B n_mult_1 =21;
  1145. case 2: {num_M = n_mult_2; } break; // 10C n_mult_2 =22;
  1146. case 3: {num_M = n_mult_3; } break; // 11C n_mult_3 =26;
  1147. default: {;} break;
  1148. }
  1149. delay(100);
  1150. }
  1151.  
  1152.  
  1153. void calcul_num_S(uint8_t n_bt_sta)
  1154. {
  1155. num_S = n_bt_sta; // à ajuster le cas échéant...
  1156. }
  1157.  
  1158.  
  1159. // Fonction de "callback" obligatoire pour TJpg_Decoder
  1160. // Elle indique au décodeur comment pousser les blocs de pixels (MCU) sur l'écran TFT
  1161. bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap)
  1162. {
  1163. // Si le bloc sort de l'écran, on arrête
  1164. if (y >= TFT.height()) return false;
  1165. // Dessine le bloc de pixels converti à l'écran
  1166. TFT.pushImage(x, y, w, h, bitmap);
  1167. return true; // Retourne true pour dire au décodeur de continuer
  1168. }
  1169.  
  1170. /*
  1171. // Fonction récursive pour lister les fichiers et dossiers
  1172. void listDir(fs::FS &fs, const char * dirname, uint8_t levels)
  1173. {
  1174.   Serial.printf("Listing directory: %s\n", dirname);
  1175.  
  1176.   File root = fs.open(dirname);
  1177.   if(!root){
  1178.   Serial.println("Failed to open directory");
  1179.   return;
  1180.   }
  1181.   if(!root.isDirectory())
  1182.   {
  1183.   Serial.println("Not a directory");
  1184.   return;
  1185.   }
  1186.  
  1187.   File file = root.openNextFile();
  1188.   while(file)
  1189.   {
  1190.   if(file.isDirectory())
  1191.   {
  1192.   Serial.printf(" DIR : %s\n", file.name());
  1193.   // Si levels > 0, on descend dans le sous-dossier
  1194.   if(levels)
  1195.   {
  1196.   listDir(fs, file.path(), levels - 1);
  1197.   }
  1198.   }
  1199.   else
  1200.   {
  1201.   Serial.printf(" FILE: %s SIZE: %d bytes\n", file.name(), file.size());
  1202.   }
  1203.   file = root.openNextFile();
  1204.   }
  1205. }
  1206. */
  1207.  
  1208. void show_boutons_selected()
  1209. {
  1210. panel_bt_multiplex.bt_P[btm].selected = 1;
  1211. panel_bt_multiplex.bt_P[btm].affiche(NOIR, VERT, 1, &TFT); // concerne 1 seul bouton
  1212.  
  1213. panel_bt_stations.bt_P[bts].selected = 1;
  1214. panel_bt_stations.bt_P[bts].affiche(NOIR, VERT, 1, &TFT); // concerne 1 seul bouton
  1215. }
  1216.  
  1217.  
  1218.  
  1219. void setup_catalogue() // suite du setup en mode 'catalogue'
  1220. {
  1221. affi_BMP_from_SD("/bmp565/stations.bmp", 0, 0); // image du catalogue (tous les 49 boutons)
  1222. //cette image a été constituée une fois pour toutes lors de la 1ere utilisation (voir plus haut)
  1223. gridPad1.init(0, 0); // boutons virtuels invisibles sous les imagettes du catalogue
  1224. TFT.fillRect(0, 175, 320, 65, GRIS_6);
  1225.  
  1226. TFT.drawRect(82, 175, 85, 65, GRIS_3); // cadre en trait blanc sous le catalogue, autour de l'imagette reçue
  1227. TFT.setTextColor(GRIS_3);
  1228. TFT.setFreeFont(0);
  1229. TFT.drawString("image recue", 90, 180);
  1230.  
  1231. etiquette_LABEL2.init(170, 174, 149, 22, "", &TFT); // en bas
  1232.  
  1233. TJpgDec.setJpgScale(4); // Échelle
  1234. TJpgDec.drawSdJpg(0, 178, "/slideshows/generiques/320x240/dab+.jpg"); // par défaut; (le "petit poste vert")
  1235.  
  1236. bt_capture_ecran.init(300, 220, 20, 20, 1, GRIS_5);
  1237. bt_capture_ecran.affiche(BLANC, VERT, 1, &TFT);
  1238.  
  1239.  
  1240. }
  1241.  
  1242.  
  1243.  
  1244. void setup_expert() // suite du setup en mode ''expert''
  1245. {
  1246. affichages_widgets_expert();
  1247. panel_bt_multiplex.affiche(&TFT);
  1248. affichage_boutons_stations();
  1249. // delay(10);
  1250. show_boutons_selected();
  1251.  
  1252. bt_capture_ecran.init(300, 220, 20, 20, 1, GRIS_5);
  1253. bt_capture_ecran.affiche(BLANC, VERT, 1, &TFT);
  1254. }
  1255.  
  1256.  
  1257.  
  1258.  
  1259. void setup()
  1260. {
  1261. // étalonnage touch screen; ces valeurs peuvent varier d'un afficheur à l'autre
  1262. eTS.x0 = -30; eTS.y0 = -30;
  1263. eTS.dx = 11; eTS.dy = 14;
  1264.  
  1265. Serial.begin(115200); // par l'USB
  1266. delay(20);
  1267.  
  1268. Serial2.setRxBufferSize(4096); // augmenté pour éviter de perdre des caractères pendant le transfert.
  1269. Serial2.begin(921600, SERIAL_8N1, 16, 17); // RX, TX // filaire vers l'autre ESP
  1270. // incomingBase64.reserve(20000); // 20000 Évite la fragmentation de la RAM
  1271.  
  1272. Wire.begin(GPIO_SDA, GPIO_SCL, 921600);
  1273.  
  1274. // Start the SPI for the touch screen and init the TS library
  1275. mySpi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
  1276. ts.begin(mySpi);
  1277. ts.setRotation(3);
  1278.  
  1279. // mySpi2 -> pour le lecteur de SDcard
  1280. // mySpi2 -> partage du bus SPI - mêmes valeurs de GPIO (sck=14, miso=12)
  1281. // que pour l'afficheur ILI9341 , sauf CS=5. Voir sur le schéma ainsi que le fichier User_Setup.h
  1282. mySpi2.begin(14, 12, 13, 5);
  1283.  
  1284. init_SDcard();
  1285. delay(20);
  1286.  
  1287. if (SDcardOk == true)
  1288. {
  1289. read_fichier_params_tactile(); // sur la SDcard
  1290. read_params_multiplex();
  1291. read_fichier_params_stations();
  1292. }
  1293.  
  1294. TFT.init();
  1295. TFT.setRotation(3); // 0..3 à voir, suivant disposition de l'afficheur
  1296. TFT.fillScreen(NOIR);
  1297.  
  1298. init_sprites();
  1299.  
  1300. affi_page_info();
  1301. delay(500);
  1302. TFT.fillScreen(NOIR);
  1303. TFT.drawRect(0, 0, 320, 240, BLANC); // cadre principal pourtour de l'écran
  1304.  
  1305. // si les coordonnées des points de calibrage sont aux fraises...
  1306. if ( (A.x <300) || (A.x >700) || (A.y <200) || (A.y >600) ||
  1307. (B.x < 3500) || (B.x > 3900) || (B.y <3400) || (A.y >3800) )
  1308. {
  1309. TS_calibrate();
  1310. }
  1311.  
  1312. TJpgDec.setSwapBytes(true);
  1313. TJpgDec.setCallback(tft_output);
  1314.  
  1315. mode_general = MODE_EXPERT;
  1316. //mode= MODE_CATALOGUE;
  1317.  
  1318. String s0 = "/slideshows/generiques/320x240/";
  1319. uint8_t n=0;
  1320. uint8_t n_mul=0;
  1321. uint8_t n_sta=0;
  1322.  
  1323. lst_sta[n].n_ml=1; lst_sta[n].n_st=1; lst_sta[n].s=s0+"F2F6_RTL2.jpg"; n++;
  1324. lst_sta[n].n_ml=1; lst_sta[n].n_st=2; lst_sta[n].s=s0+"F2F7_FUN RADIO.jpg"; n++;
  1325. lst_sta[n].n_ml=1; lst_sta[n].n_st=3; lst_sta[n].s=s0+"F2F8_NRJ.jpg"; n++;
  1326. lst_sta[n].n_ml=1; lst_sta[n].n_st=4; lst_sta[n].s=s0+"F2F9_CHERIE FM.jpg"; n++;
  1327. lst_sta[n].n_ml=1; lst_sta[n].n_st=6; lst_sta[n].s=s0+"F2FA_NOSTALGIE.jpg"; n++;
  1328. lst_sta[n].n_ml=2; lst_sta[n].n_st=2; lst_sta[n].s=s0+"F2FD_BFM RADIO.jpg"; n++;
  1329. lst_sta[n].n_ml=1; lst_sta[n].n_st=9; lst_sta[n].s=s0+"F2FE_AIRZEN RADIO.jpg"; n++;
  1330. lst_sta[n].n_ml=3; lst_sta[n].n_st=9; lst_sta[n].s=s0+"F6D5_RADIO LANGA DOC.jpg"; n++;
  1331. lst_sta[n].n_ml=3; lst_sta[n].n_st=3; lst_sta[n].s=s0+"F6FD_100p100.jpg"; n++;
  1332. lst_sta[n].n_ml=3; lst_sta[n].n_st=4; lst_sta[n].s=s0+"F9F1_FUEGO.jpg"; n++;
  1333. lst_sta[n].n_ml=3; lst_sta[n].n_st=10; lst_sta[n].s=s0+"F9F5_MELODY.jpg"; n++;
  1334. lst_sta[n].n_ml=3; lst_sta[n].n_st=0; lst_sta[n].s=s0+"F20A_ICI HERAULT.jpg"; n++;
  1335. lst_sta[n].n_ml=2; lst_sta[n].n_st=4; lst_sta[n].s=s0+"F20D_RFM.jpg"; n++;
  1336. lst_sta[n].n_ml=2; lst_sta[n].n_st=5; lst_sta[n].s=s0+"F20E_Europe 2.jpg"; n++;
  1337. lst_sta[n].n_ml=3; lst_sta[n].n_st=2; lst_sta[n].s=s0+"F21B_ado.jpg"; n++;
  1338. lst_sta[n].n_ml=1; lst_sta[n].n_st=11; lst_sta[n].s=s0+"F21C_LATINA.jpg"; n++;
  1339. lst_sta[n].n_ml=3; lst_sta[n].n_st=5; lst_sta[n].s=s0+"F21D_Oui FM.jpg"; n++;
  1340. lst_sta[n].n_ml=3; lst_sta[n].n_st=8; lst_sta[n].s=s0+"F22A_RADIO NOVA.jpg"; n++;
  1341. lst_sta[n].n_ml=3; lst_sta[n].n_st=6; lst_sta[n].s=s0+"F22F_JAZZ RADIO.jpg"; n++;
  1342. lst_sta[n].n_ml=1; lst_sta[n].n_st=8; lst_sta[n].s=s0+"F24E_NOSTALGIE 60 70.jpg"; n++;
  1343. lst_sta[n].n_ml=2; lst_sta[n].n_st=11; lst_sta[n].s=s0+"F24F_MON PETIT INTER.jpg"; n++;
  1344. lst_sta[n].n_ml=2; lst_sta[n].n_st=7; lst_sta[n].s=s0+"F201_FRANCE INTER.jpg"; n++;
  1345. lst_sta[n].n_ml=2; lst_sta[n].n_st=9; lst_sta[n].s=s0+"F202_FRANCE_CULTURE.jpg"; n++;
  1346. lst_sta[n].n_ml=2; lst_sta[n].n_st=10; lst_sta[n].s=s0+"F203_FRANCE MUSIQUE.jpg"; n++;
  1347. lst_sta[n].n_ml=2; lst_sta[n].n_st=8; lst_sta[n].s=s0+"F204_FIP.jpg"; n++;
  1348. lst_sta[n].n_ml=2; lst_sta[n].n_st=6; lst_sta[n].s=s0+"F206_FRANCE INFO.jpg"; n++;
  1349. lst_sta[n].n_ml=0; lst_sta[n].n_st=0; lst_sta[n].s=s0+"F211_RTL.jpg"; n++;
  1350. lst_sta[n].n_ml=3; lst_sta[n].n_st=3; lst_sta[n].s=s0+"F213_EUROPE 1.jpg"; n++;
  1351. lst_sta[n].n_ml=1; lst_sta[n].n_st=7; lst_sta[n].s=s0+"F214_SKYROCK.jpg"; n++;
  1352. lst_sta[n].n_ml=1; lst_sta[n].n_st=10; lst_sta[n].s=s0+"F221_RADIO CLASSIQUE.jpg"; n++;
  1353. lst_sta[n].n_ml=1; lst_sta[n].n_st=12; lst_sta[n].s=s0+"F225_M RADIO.jpg"; n++;
  1354. lst_sta[n].n_ml=1; lst_sta[n].n_st=5; lst_sta[n].s=s0+"F226_RIRE et CHANSONS.jpg"; n++;
  1355. lst_sta[n].n_ml=2; lst_sta[n].n_st=1; lst_sta[n].s=s0+"F227_BFM BUSINESS.jpg"; n++;
  1356. lst_sta[n].n_ml=3; lst_sta[n].n_st=11; lst_sta[n].s=s0+"F650_SUD RADIO.jpg"; n++;
  1357. lst_sta[n].n_ml=2; lst_sta[n].n_st=0; lst_sta[n].s=s0+"F216_RMC.jpg"; n++;
  1358.  
  1359. //------------------------------------------------------------------------------------------------
  1360. if(0) // 1 pour la première utilisation, 0 ensuite
  1361. {
  1362. // on va afficher toutes les petites vignettes pour constituer un tableau visuel
  1363. // ensuite on fait une capture d'écran pour sauvegarder ce visuel sur la SDcard
  1364. // Le but est d'obtenir par la suite un affichage beaucoup plus rapide de cette grande image unique
  1365. uint8_t num=0;
  1366. uint8_t n_max=34;
  1367. for(uint8_t ny=0; ny<7; ny++)
  1368. {
  1369. for(uint8_t nx=0; nx<7; nx++)
  1370. {
  1371. bt_img1.init(4+45*nx, 4+34*ny, 8);
  1372. //bt_img1.img_path = "/slideshows/generiques/40x30/F2F8_NRJ.jpg"; // sur SDcard
  1373. bt_img1.img_path = lst_sta[num].s; // sur SDcard
  1374. bt_img1.affiche();
  1375. num++;
  1376. if(num>34) break;
  1377. }
  1378. if(num>34) break;
  1379. }
  1380. write_TFT_on_SDcard("/bmp565/stations.bmp");
  1381. TFT.fillScreen(0);
  1382. TFT.setFreeFont(FF0);
  1383. TFT.drawString("Capture ecran sauvee sur SDcard", 0, 0);
  1384. TFT.drawString("/bmp565/stations.bmp", 0, 20);
  1385. delay(4000);
  1386. }
  1387. //------------------------------------------------------------------------------------------------
  1388.  
  1389. //affi_BMP_from_SD("/bmp565/2.bmp", 0, 0);
  1390. //delay(1000);
  1391. TFT.fillScreen(couleur_fond_ecran);
  1392.  
  1393. TJpgDec.setJpgScale(2); // Échelle : 1 (taille réelle), 2 (moitié), 4 (quart), 8 (huitième)
  1394. TJpgDec.setSwapBytes(true); // INDISPENSABLE pour que les couleurs RGB565 soient justes sur ILI9341
  1395. TJpgDec.setCallback(tft_output); // Set the sketch callback function to render decoded blocks
  1396.  
  1397. bt_stop_tout_ecran.init(280, 2, 30, 30, 1, GRIS_6);
  1398. bt_stop_tout_ecran.label ="X";
  1399.  
  1400. // bt_stop_tout_ecran.selected=true; bt_stop_tout_ecran.affiche(VERT, VERT, 1, &TFT); while(1); // POUR TEST
  1401.  
  1402. num_bt_M = btm;
  1403. affichage_boutons_stations(); // concerne tous les boutons; les libellé sont définits
  1404. // voir le fonction (read_fichier_params_stations() // lecture du fichier '/params_stations.txt' en SD )
  1405.  
  1406. if (mode_general == MODE_CATALOGUE)
  1407. {
  1408. setup_catalogue();
  1409. affichages_widgets_catalogue();
  1410.  
  1411. }
  1412.  
  1413. if(mode_general == MODE_EXPERT)
  1414. {
  1415. setup_expert();
  1416.  
  1417. execute_bouton_multiplex(2); // 10C
  1418. execute_bouton_station(10); // FRANCE MUSIQUE
  1419. show_boutons_selected();
  1420.  
  1421.  
  1422.  
  1423. // ne pas envoyer ce qui suit dans la fonction 'setup_expert()' sinon en renvoit la config à la radio inutilement
  1424. /* calcul_num_M(btm);
  1425.   send_multiplex_to_ESP_radio(num_M);
  1426.   choix_mutiplex_ok = true;
  1427.   delay(10);
  1428.   calcul_num_S(bts);
  1429.   send_station_to_ESP_radio(num_S);
  1430. */
  1431. }
  1432.  
  1433. }
  1434.  
  1435.  
  1436.  
  1437. void get_XY_touch() // pour affi 320 x 240px
  1438. {
  1439. TS_Point p = ts.getPoint();
  1440. float dx = B.x - A.x;
  1441. float ech_x = 290.0 / dx;//300
  1442. float x0 = A.x;
  1443.  
  1444. float dy = B.y - A.y;
  1445. float ech_y = 210.0 / dy; //230
  1446. float y0 = A.y;
  1447.  
  1448. memo_x_touch = x_touch;
  1449. memo_y_touch = y_touch;
  1450.  
  1451. x_touch = 12 + uint16_t( (p.x - x0) * ech_x); //x_touch = 10 + uint16_t( (p.x - x0) * ech_x);
  1452. if(x_touch > 319){x_touch = 0;}
  1453. y_touch = 15 + uint16_t( (p.y - y0) * ech_y); //y_touch = 10 + uint16_t( (p.y - y0) * ech_y);
  1454. if(y_touch > 239){y_touch = 0;}
  1455. }
  1456.  
  1457.  
  1458. void affiche_page_stations()
  1459. {
  1460. page_stations.efface(&TFT);
  1461. String s1, s2, s3, s4;
  1462. for(int n=0; n<13; n++)
  1463. {
  1464. s1 = String(n);
  1465. if (n<10) {s1 = "0" + s1;}
  1466.  
  1467. uint32_t compid = LST_services[n].CompID;
  1468. s2 = convert_Dec_To_Hex(compid);
  1469. s2 = s2.substring(s2.length() - 1);
  1470.  
  1471. uint32_t servid = LST_services[n].ServiceID;
  1472. s3 = convert_Dec_To_Hex(servid);
  1473.  
  1474. s4 = String(LST_services[n].Label);
  1475.  
  1476. page_stations.set_texte(s1 + " " + s2 + " " + s3 + " " + s4, n);
  1477. }
  1478.  
  1479. page_stations.affiche(1, &TFT);
  1480. }
  1481.  
  1482.  
  1483. /*
  1484. // par IA
  1485. void afficherImageBase64(const String& base64Data, int posX = 0, int posY = 0)
  1486. {
  1487. Serial.println("void afficherImageBase64()");
  1488.  
  1489.   size_t inputLength = base64Data.length();
  1490.   size_t maxOutputLength = (inputLength * 3) / 4 + 4;
  1491.  
  1492.   uint8_t* jpgBuffer = (uint8_t*)malloc(maxOutputLength);
  1493.   if (jpgBuffer == NULL)
  1494.   {
  1495.   Serial.println("Erreur : Memoire RAM insuffisante");
  1496.   return;
  1497.   }
  1498.  
  1499.   size_t actualJpgLength = 0;
  1500.  
  1501.   // Décodage Base64 -> Binaire JPG
  1502.   int result = mbedtls_base64_decode(
  1503.   jpgBuffer,
  1504.   maxOutputLength,
  1505.   &actualJpgLength,
  1506.   (const unsigned char*)base64Data.c_str(),
  1507.   inputLength
  1508.   );
  1509.  
  1510.   if (result == 0)
  1511.   {
  1512.   // Dessine l'image aux coordonnées (posX, posY) directement depuis la RAM
  1513.   JRESULT res = TJpgDec.drawJpg(posX, posY, jpgBuffer, actualJpgLength);
  1514.   if (res != JDR_OK) { Serial.printf("Erreur decodage JPG : %d\n", res); }
  1515.   }
  1516.   else { Serial.printf("Erreur Base64 : -0x%04X\n", -result); }
  1517.  
  1518.   free(jpgBuffer); // Libération de la mémoire
  1519. }
  1520. */
  1521.  
  1522.  
  1523. // par IA
  1524. void processBase64Image(const String& b64Data) // recu de l'ESP_radio
  1525. {
  1526. size_t inputLen = b64Data.length();
  1527. size_t outputLen = 0;
  1528.  
  1529. // Estimation de la taille max du JPG (3 octets décodés pour 4 octets Base64)
  1530. size_t maxOutputLen = (inputLen * 3) / 4 + 2;
  1531. uint8_t* jpgBuffer = (uint8_t*)malloc(maxOutputLen); // permet de réserver de la mémoire dynamiquement sur le «tas»
  1532.  
  1533. if (jpgBuffer == NULL) { Serial.println("Erreur : RAM insuffisante pour le decodage."); return; }
  1534.  
  1535. // Décodage mbedtls
  1536. int result = mbedtls_base64_decode(
  1537. currentSlideBuffer, //jpgBuffer,
  1538. maxOutputLen,
  1539. &outputLen,
  1540. (const unsigned char*)b64Data.c_str(),
  1541. inputLen
  1542. );
  1543.  
  1544. if (result == 0)
  1545. {
  1546. logo_courant = true; // pour éviter d'écraser (plus tard) le logo courant avec un logo générique
  1547.  
  1548. Serial.printf("Decodage OK. Affi JPG (%d octets)...\n", outputLen);
  1549. if(mode_general != MODE_PARAM) // pour ne pas écraser les boutons du mode paramétrage
  1550. {
  1551. if(mode_general == MODE_EXPERT)
  1552. {
  1553.  
  1554. TFT.fillRect(131, 75, 178, 136, NOIR);
  1555. TFT.startWrite();
  1556. TJpgDec.drawJpg(131, 77, currentSlideBuffer, outputLen); // AFFICHE LE LOGO RECU
  1557. currentSlideSize = outputLen;
  1558.  
  1559. //affi_jpg_from_RAM(131, 75, outputLen);
  1560. }
  1561.  
  1562. if(mode_general == MODE_CATALOGUE)
  1563. {
  1564. TFT.startWrite();
  1565. TJpgDec.drawJpg(84, 178, currentSlideBuffer, outputLen);
  1566. }
  1567.  
  1568. TFT.endWrite();
  1569. }
  1570.  
  1571. // write_image_jpg_to_SD(currentSlideBuffer); // copie sur la SDcard (ajout)
  1572. }
  1573.  
  1574. receivingSLS = false; // permet la gestion des boutons et la réception rssi, label, texte...
  1575. }
  1576.  
  1577.  
  1578.  
  1579. void affi_RadioText()
  1580. {
  1581. if(mode_general == MODE_EXPERT)
  1582. {
  1583. etiquette_Radiotext1.efface(&TFT);
  1584. etiquette_Radiotext1.couleur_txt = CYAN;
  1585. String s1 = RadioText.substring(0,51);
  1586. etiquette_Radiotext1.affiche(s1, 0, 0, &TFT);
  1587. }
  1588.  
  1589. if(mode_general == MODE_CATALOGUE)
  1590. {
  1591. etiquette_Radiotext2.efface(&TFT);
  1592. etiquette_Radiotext2.couleur_txt = CYAN;
  1593. //String s1 = RadioText.substring(0,24);
  1594. etiquette_Radiotext2.affiche(RadioText,decal_tx, 0, &TFT);
  1595.  
  1596. bt_capture_ecran.affiche(BLANC, VERT, 1, &TFT);
  1597. }
  1598. }
  1599.  
  1600.  
  1601.  
  1602. void show_btm_bts() // tout en haut, à gauche, pour test...
  1603. {
  1604. TFT.setFreeFont(FF0);
  1605. TFT.setTextColor(JAUNE, NOIR);
  1606. String s1;
  1607. s1 = String(btm) +" "; TFT.drawString(s1, 20, 0);
  1608. s1 = String(bts) +" "; TFT.drawString(s1, 40, 0);
  1609. }
  1610.  
  1611.  
  1612.  
  1613.  
  1614. void toutes_les_500ms()
  1615. {
  1616. if (rxState == RECEIVING_DATA) {return;}
  1617.  
  1618.  
  1619. if((mode_general == MODE_CATALOGUE) && (mode_affi == MODE_PETITE))
  1620. {
  1621. TFT.setFreeFont(0);
  1622. TFT.setTextColor(JAUNE);
  1623. TFT.setTextDatum(0); // left
  1624. TFT.drawString("C", 0, 0);
  1625.  
  1626. if(RadioText.length() > 24)
  1627. {
  1628. decal_tx++;
  1629. if(decal_tx > 20)
  1630. {
  1631. decal_tx =0;
  1632. delay(300);
  1633.  
  1634. }
  1635. }
  1636. affi_RadioText();
  1637. }
  1638.  
  1639. // if(mode_general == MODE_EXPERT)
  1640. // {
  1641. // TFT.setTextDatum(0); // left
  1642. // TFT.drawString("E", 0, 0);
  1643. // }
  1644. // show_btm_bts(); // pour test
  1645. }
  1646.  
  1647.  
  1648.  
  1649.  
  1650. void RECEPTION()
  1651. {
  1652. // ****************************** RECEPTION ********************
  1653.  
  1654. if(Serial2.available())
  1655. {
  1656. uint16_t valeur1;
  1657. String s_in, s1, s2;
  1658. int p1, p2, p3;
  1659.  
  1660. s_in = Serial2.readStringUntil('\n');
  1661.  
  1662. Serial.print("s_in= "); Serial.println(s_in);
  1663.  
  1664.  
  1665. // Lecture ligne par ligne pour intercepter les commandes STARTSLS et ENDSLS
  1666. //String ligne = Serial2.readStringUntil('\n');
  1667.  
  1668. //s1.trim(); // Nettoie les \r ou espaces invisibles
  1669. if (rxState == WAIT_START)
  1670. {
  1671. if (s_in.startsWith("STARTSLS"))
  1672. {
  1673. // RECEPTION SLIDESHOW
  1674. Serial.println("-----------------------");
  1675. receivingSLS = true; // bloque les autres actions pendant la réception de l'image "SlideShow"
  1676.  
  1677. TFT.fillCircle(302, 80, 5, ROUGE);
  1678.  
  1679. // Extraction de la taille numérique collée après STARTSLS
  1680. String lenStr = s_in.substring(8);
  1681. Serial.print("lenStr= "); Serial.println(lenStr);
  1682.  
  1683. expectedLen = lenStr.toInt();
  1684.  
  1685. base64Buffer = "";
  1686. if (expectedLen > 0)
  1687. {
  1688. base64Buffer.reserve(expectedLen + 10); // Prévient la fragmentation RAM
  1689. }
  1690.  
  1691. rxState = RECEIVING_DATA;
  1692. Serial.printf("Debut reception SLS (Taille attendue : %d)\n", expectedLen);
  1693. }
  1694. }
  1695. else if (rxState == RECEIVING_DATA)
  1696. {
  1697. if (s_in.startsWith("ENDSLS"))
  1698. {
  1699. // FIN de la réception de l'image (après plusieurs passages de réception (ci-dessus) de tous les paquets)
  1700. rxState = WAIT_START;
  1701.  
  1702. if (base64Buffer.length() == expectedLen) // Validation stricte de l'intégrité avant décodage
  1703. {
  1704. TFT.fillCircle(302, 80, 5, ORANGE);
  1705. Serial.println("Donnees completes. Traitement...");
  1706. processBase64Image(base64Buffer); // et affichage
  1707. delay(50);
  1708. TFT.fillCircle(302, 80, 5, VERT);
  1709. TFT.drawCircle(302, 80, 5, GRIS_3);
  1710. }
  1711. else { Serial.printf("Erreur transfert : Recu %d octets sur %d attendus.\n", base64Buffer.length(), expectedLen);}
  1712. }
  1713. else
  1714. {
  1715. base64Buffer += s_in; // Accumulation des blocs Base64 reçus
  1716. }
  1717. }
  1718.  
  1719.  
  1720. if ((receivingSLS == false) && (mode_affi == MODE_PETITE))
  1721. {
  1722. p1 = s_in.indexOf("label");
  1723. if(p1 != -1)
  1724. {
  1725. s1 = extract_texte(s_in, "label");
  1726. s1 = s1.substring(0, 16); // pour ne pas dépasser du cadre
  1727. if(mode_general == MODE_EXPERT)
  1728. {
  1729. etiquette_LABEL1.efface(&TFT);
  1730. etiquette_LABEL1.couleur_txt = JAUNE;
  1731. etiquette_LABEL1.affiche(s1, 0, 1, &TFT);
  1732. }
  1733.  
  1734. if(mode_general == MODE_CATALOGUE)
  1735. {
  1736. etiquette_LABEL2.efface(&TFT);
  1737. etiquette_LABEL2.couleur_txt = JAUNE;
  1738. etiquette_LABEL2.affiche(s1, 0, 1, &TFT);
  1739. }
  1740.  
  1741. }
  1742.  
  1743. p1 = s_in.indexOf("LISTING");
  1744. if(p1 != -1)
  1745. {
  1746. //DABService LST_services_recu[16];
  1747.  
  1748. Serial2.readBytes(reinterpret_cast<uint8_t*>(&LST_services), sizeof(LST_services));
  1749.  
  1750. for(int n=0; n<13; n++)
  1751. {
  1752. Serial.println(n);
  1753. uint32_t compid = LST_services[n].CompID;
  1754. //Serial.print("CompID= "); Serial.println(convert_Dec_To_Hex(compid));
  1755.  
  1756. uint32_t servid = LST_services[n].ServiceID;
  1757. s1 = convert_Dec_To_Hex(servid);
  1758.  
  1759. s2 = String(LST_services[n].Label);
  1760. s2 = s2.substring(0, 15);
  1761. Serial.print("label= "); Serial.println(s2);
  1762.  
  1763. if(num_bt_M == 0) { libels_stations0[n] = s1 +'=' +s2;}
  1764. if(num_bt_M == 1) { libels_stations1[n] = s1 +'=' +s2;}
  1765. if(num_bt_M == 2) { libels_stations2[n] = s1 +'=' +s2;}
  1766. if(num_bt_M == 3) { libels_stations3[n] = s1 +'=' +s2;}
  1767.  
  1768. //libels_stations[num_bt_M] [n]= s1 +'=' +s2;
  1769.  
  1770. }
  1771. choix_mutiplex_ok = true;
  1772. affiche_page_stations();
  1773. affichage_boutons_stations();
  1774. }
  1775.  
  1776. p1 = s_in.indexOf("rssi");
  1777. if(p1 != -1)
  1778. {
  1779. if(mode_general == MODE_EXPERT)
  1780. {
  1781. s1 = extract_texte(s_in, "rssi");
  1782. etiquette_rssi.efface(&TFT);
  1783. etiquette_rssi.couleur_txt = BLEU_CLAIR;
  1784. etiquette_rssi.affiche(s1, 0, 1, &TFT);
  1785. }
  1786. }
  1787.  
  1788. p1 = s_in.indexOf("serviceID"); // "F203"
  1789. if(p1 != -1)
  1790. {
  1791. s1 = extract_texte(s_in, "serviceID");
  1792. etiquette_ID.efface(&TFT);
  1793. if(s1[0] == 'F')
  1794. {
  1795. s1=s1.substring(0, 4); // au cas où le texte reçu serait >4 caractères
  1796. if ((s1=="F20C") || (s1=="F20F")||(s1=="F200")) // pas de radios religieuses ici !
  1797. {
  1798.  
  1799. btm = 2; // 10C
  1800. bts = 10; // FRANCE MUSIQUE
  1801. execute_bouton_station(bts);
  1802. }
  1803. etiquette_ID.couleur_txt = VERT;
  1804. etiquette_ID.affiche(s1, 0, 1, &TFT);
  1805. }
  1806. }
  1807.  
  1808.  
  1809. // texte long, dit 'RadioText' ou 'serviceData'
  1810. p1 = s_in.indexOf("serviceData");
  1811. if(p1 != -1)
  1812. {
  1813. String rt1 = extract_texte(s_in, "serviceData");
  1814. //RadioText = rt1;
  1815. RadioText = desaccentue(rt1) ;
  1816. decal_tx =0;
  1817. affi_RadioText();
  1818. }
  1819.  
  1820.  
  1821. p1 = s_in.indexOf("<ACQ>"); // Acquiescement reçu du module radio
  1822. if(p1 != -1)
  1823. {
  1824. page_stations.efface(&TFT);
  1825. page_stations.set_texte("Scan OK", 2);
  1826. page_stations.set_texte("Affichage listing...", 3);
  1827. page_stations.affiche(1, &TFT);
  1828.  
  1829. // on demande l'affichage du résultat (qui figure dans l'ESP_radio)
  1830. String s1;
  1831. s1 += "[bt_affi_LST]<";
  1832. s1 += "1";
  1833. s1 +=">";
  1834. Serial2.println(s1);
  1835. }
  1836. }
  1837. }
  1838. }
  1839.  
  1840.  
  1841. void execute_bouton_multiplex(uint8_t n)
  1842. {
  1843. num_bt_M = n;
  1844.  
  1845. memo_logo_generique_en_cours="";
  1846. logo_courant = false; // pour afficher le logo générique dès qu'on change de station
  1847. page_stations.efface(&TFT);
  1848. //send_num_M_to_ESP_radio(26); // 18 - 21 - 22 - 26
  1849. etiquette_ID.efface(&TFT);
  1850. etiquette_LABEL1.efface(&TFT);
  1851.  
  1852. affichage_boutons_stations();
  1853.  
  1854. calcul_num_M(num_bt_M);
  1855. send_multiplex_to_ESP_radio(num_M);
  1856. delay(10);
  1857. calcul_num_S(num_bt_S);
  1858. send_station_to_ESP_radio(num_S);
  1859. delay(10);
  1860. choix_mutiplex_ok = true;
  1861. btm = num_bt_M;
  1862. }
  1863.  
  1864.  
  1865.  
  1866.  
  1867. void execute_bouton_station(uint8_t n)
  1868. {
  1869. num_bt_S = n;
  1870. //bts = num_bt_S;
  1871. memo_logo_generique_en_cours="";
  1872. //logo_courant = false; // pour afficher le logo générique
  1873. etiquette_ID.efface(&TFT);
  1874. etiquette_LABEL1.efface(&TFT);
  1875.  
  1876. String s1;
  1877. if(num_bt_M==0) {s1= libels_stations0[num_bt_S];}
  1878. if(num_bt_M==1) {s1= libels_stations1[num_bt_S];}
  1879. if(num_bt_M==2) {s1= libels_stations2[num_bt_S];}
  1880. if(num_bt_M==3) {s1= libels_stations3[num_bt_S];}
  1881.  
  1882. //s1= libels_stations[num_bt_M][num_bt_S];
  1883.  
  1884. s1=s1.substring(0, 4);
  1885. if ((s1=="") || (s1=="F20C") || (s1=="F20F")){return; } //pas de radios confessionnelles sur ce récepteur !
  1886. etiquette_ID.couleur_txt = VERT;
  1887. etiquette_ID.affiche(s1, 0, 1, &TFT); // très rapidement dès le clic sur 1 bouton station
  1888.  
  1889. // if (logo_courant == false) // alors on affiche le logo générique de la station
  1890. {
  1891. // rappel : absolute_path(SD, "/", "ABCD") cherche, ouvre et lit le premier fichier commençant par "ABCD" à la racine "/"
  1892. logo_en_cours = absolute_path(SD, "/slideshows/generiques/320x240", s1);
  1893.  
  1894. if (logo_en_cours != memo_logo_en_cours) // évite les réaffichages intempestifs du même logo
  1895. {
  1896. memo_logo_en_cours = logo_en_cours;
  1897. // Serial.print("generique= "); Serial.println(s2); // = "/slideshows/generiques/F2FA_NOSTALGIE.jpg"
  1898.  
  1899. affi_jpg_from_SD(logo_en_cours, 131, 75);
  1900.  
  1901. // copie en RAM de cette image pour pouvoir l'afficher ultérieurement en différents formats
  1902. // remarque: la réception (radio) d'une image actualisée écrasera cette image RAM
  1903. copie_jpg_from_SD_to_RAM(logo_en_cours);
  1904. }
  1905. }
  1906.  
  1907. calcul_num_M(num_bt_M);
  1908. send_multiplex_to_ESP_radio(num_M);
  1909. delay(10);
  1910. calcul_num_S(num_bt_S);
  1911. send_station_to_ESP_radio(num_S);
  1912. delay(10);
  1913.  
  1914. //affichage_boutons_stations();
  1915. }
  1916.  
  1917.  
  1918.  
  1919.  
  1920. void loop()
  1921. {
  1922. unsigned long currentMillis = millis();
  1923.  
  1924. if (currentMillis - previousMillis >= 500)
  1925. {
  1926. previousMillis = currentMillis;
  1927. if(receivingSLS == false)
  1928. {
  1929. toutes_les_500ms();
  1930. }
  1931. }
  1932.  
  1933. RECEPTION(); //de l'ESP32_RADIO par la liaison Serial2 // ******* commenter pour TEST *******
  1934.  
  1935. //---------------------------------------------------------------------------------------------
  1936. // ***** TRAITEMENT DES BOUTONS VIRTUELS LOCAUX ********
  1937. //---------------------------------------------------------------------------------------------
  1938.  
  1939. if (ts.tirqTouched() && ts.touched())
  1940. {
  1941. memo_y_touch = y_touch;
  1942. get_XY_touch();
  1943.  
  1944. // on invalide les boutons dans les modes LOGO plein écran et catalogue
  1945. if((mode_affi != MODE_TOUT_ECRAN) && (mode_general != MODE_CATALOGUE))
  1946. {
  1947.  
  1948. // BOUTONS MULTIPLEX
  1949. uint8_t memo_num_bt_M = num_bt_M;
  1950. num_bt_M = panel_bt_multiplex.traite_boutons(x_touch, y_touch, 4, &TFT);
  1951. if (num_bt_M != 255)
  1952. {
  1953. execute_bouton_multiplex(num_bt_M);
  1954. }
  1955. else {num_bt_M = memo_num_bt_M;} // on reprend la valeur précédente, sinon on la perd à chaque passage
  1956.  
  1957. // BOUTONS STATION
  1958. uint8_t memo_num_bt_S = num_bt_S;
  1959. num_bt_S = panel_bt_stations.traite_boutons(x_touch, y_touch, 13, &TFT);
  1960. if (num_bt_S != 255)
  1961. {
  1962. if(choix_mutiplex_ok == true)
  1963. {
  1964. execute_bouton_station(num_bt_S);
  1965. }
  1966. else
  1967. {
  1968. page_stations.efface(&TFT);
  1969. page_stations.set_texte("CHOISIR UN MULTIPLEX !", 1);
  1970. page_stations.affiche(1, &TFT);
  1971. }
  1972. }
  1973. else {num_bt_S = memo_num_bt_S;} // on reprend la valeur précédente
  1974.  
  1975. // BOUTON SCAN
  1976. bt_SCAN_stations.test_clic(x_touch, y_touch);
  1977. if(bt_SCAN_stations.cliked == true)
  1978. {
  1979. page_stations.efface(&TFT);
  1980. page_stations.set_texte("scan en cours...", 4);
  1981. page_stations.affiche(1, &TFT);
  1982.  
  1983. bt_SCAN_stations.cliked = false;
  1984. bt_SCAN_stations.selected = 1; bt_SCAN_stations.affiche(BLANC, VERT, 1, &TFT); delay(100);
  1985. bt_SCAN_stations.selected = 0; bt_SCAN_stations.affiche(BLANC, VERT, 1, &TFT); delay(100);
  1986.  
  1987. String s1;
  1988. s1 += "[btLST]<";
  1989. s1 += "1";
  1990. s1 +=">";
  1991. Serial2.println(s1);
  1992. }
  1993.  
  1994. // BOUTON PARAM
  1995. bt_param.test_clic(x_touch, y_touch);
  1996. if(bt_param.cliked == true)
  1997. {
  1998. bt_param.cliked = false;
  1999.  
  2000. page_stations.efface(&TFT);
  2001. //page_stations.set_texte("", 2);
  2002. //page_stations.affiche(1, &TFT);
  2003.  
  2004. if (mode_general == MODE_EXPERT)
  2005. {
  2006. mode_general = MODE_PARAM;
  2007. bt_param.selected = 1;
  2008. bt_param.affiche(BLANC, ROUGE, 1, &TFT);
  2009.  
  2010. }
  2011. else
  2012. {
  2013. mode_general = MODE_EXPERT;
  2014. bt_param.selected = 1;
  2015. bt_param.affiche(NOIR, VERT, 1, &TFT);
  2016. }
  2017. affichages_widgets_expert();
  2018. delay(500);
  2019. }
  2020.  
  2021. // BOUTON CAT (pour basculer en mode catalogue)
  2022. bt_mode_catalogue.test_clic(x_touch, y_touch);
  2023. if(bt_mode_catalogue.cliked == true)
  2024. {
  2025. bt_mode_catalogue.cliked = false;
  2026. //bt_mode_catalogue.selected = 1;
  2027. //bt_mode_catalogue.affiche(BLANC, VERT, 1, &TFT);
  2028. //delay(300);
  2029.  
  2030. mode_general = MODE_CATALOGUE;
  2031.  
  2032. TFT.fillScreen(NOIR);
  2033. setup_catalogue();
  2034. affichages_widgets_catalogue();
  2035. delay(500);
  2036. }
  2037.  
  2038. // BOUTON CAL (calibrage du tactile)
  2039. if(mode_general == MODE_PARAM)
  2040. {
  2041. bt_cal.test_clic(x_touch, y_touch); // calibrage du tactile
  2042. if(bt_cal.cliked == true)
  2043. {
  2044. bt_cal.cliked = false;
  2045. TS_calibrate();
  2046. setup();
  2047. }
  2048.  
  2049. bt_to_SD.test_clic(x_touch, y_touch);
  2050. if(bt_to_SD.cliked == true)
  2051. {
  2052. bt_to_SD.cliked = false;
  2053. bt_to_SD.selected = 1; bt_to_SD.affiche(BLANC, VERT, 1, &TFT); delay(100);
  2054. bt_to_SD.selected = 0; bt_to_SD.affiche(BLANC, VERT, 1, &TFT); delay(100);
  2055.  
  2056. write_params_stations_SD(0,libels_stations0); // écriture sur la SDcard
  2057. write_params_stations_SD(1,libels_stations1);
  2058. write_params_stations_SD(2,libels_stations2);
  2059. write_params_stations_SD(3,libels_stations3);
  2060.  
  2061. //write_params_stations_SD(0,libels_stations[0]); // écriture sur la SDcard
  2062. //write_params_stations_SD(1,libels_stations[1]);
  2063. //write_params_stations_SD(2,libels_stations[2]);
  2064. //write_params_stations_SD(3,libels_stations[3]);
  2065.  
  2066.  
  2067. page_stations.set_texte("Params saved OK", 5);
  2068. page_stations.affiche(1, &TFT);
  2069. }
  2070. }
  2071. }
  2072. // -----------------------------------------------------------------------------------------
  2073. // ce qui suit reste en fonction même en mode LOGO tout-écran, sauf en MODE_PARAM
  2074.  
  2075. bt_capture_ecran.test_clic(x_touch, y_touch); // calibrage du tactile
  2076. if(bt_capture_ecran.cliked == true)
  2077. {
  2078. bt_capture_ecran.cliked = false;
  2079.  
  2080. String filename;
  2081. boolean next = true;
  2082. uint16_t n = 0;
  2083. while(next && (n < 1000) )
  2084. {
  2085. filename = "/bmp565/captures/" + String(n) + ".bmp";
  2086. if (! SD.exists(filename))
  2087. {
  2088. write_TFT_on_SDcard(filename);
  2089. TFT.drawString("Capture ecran to SDcard OK", 0, 0);
  2090. TFT.drawString(filename, 0, 20);
  2091. next = false;
  2092. }
  2093. n++;
  2094. }
  2095. }
  2096.  
  2097.  
  2098. if(mode_general == MODE_CATALOGUE)
  2099. {
  2100. uint8_t num_bouton = gridPad1.test_clic(x_touch, y_touch);
  2101. if (num_bouton <= 35) // 7x5
  2102. {
  2103. // CLIC sur un "bouton" du catalogue
  2104.  
  2105. encadre_bouton_catalogue(num_bouton);
  2106. RadioText = "";
  2107. decal_tx =0;
  2108. TFT.fillRect(82, 175, 85, 65, NOIR); // efface imagette reçue
  2109. TFT.drawRect(82, 175, 85, 65, GRIS_3); // retrace le cadre
  2110. TFT.setTextColor(GRIS_3);
  2111. TFT.setFreeFont(0);
  2112. TFT.drawString("image recue", 90, 180);
  2113.  
  2114. String s1 = String(num_bouton);
  2115. if (num_bouton<10) s1 = " " +s1;
  2116. TFT.setTextColor(JAUNE, NOIR);
  2117. //TFT.drawString(s1, 100, 100);
  2118.  
  2119. String img_path = lst_sta[num_bouton-1].s;
  2120. String s2 = img_path.substring(36, 55);
  2121.  
  2122. String aSupprimer = ".jpg";
  2123. int index = s2.indexOf(aSupprimer);
  2124. if (index != -1)
  2125. { // Vérifie si le texte est présent
  2126. s2.remove(index, aSupprimer.length());
  2127. }
  2128. s2 = s2.substring(0, 15);
  2129.  
  2130. TJpgDec.setJpgScale(4); // Échelle
  2131. TJpgDec.drawSdJpg(0, 178, img_path); // lu sur la SDcard
  2132.  
  2133. etiquette_ID.efface(&TFT);
  2134. etiquette_LABEL2.couleur_txt = JAUNE;
  2135. etiquette_LABEL2.efface(&TFT);
  2136. etiquette_LABEL2.affiche(s2, 0, 1, &TFT);
  2137.  
  2138. //num_M = lst_sta[num_bouton-1].n_ml;
  2139. calcul_num_M(lst_sta[num_bouton-1].n_ml);
  2140. send_multiplex_to_ESP_radio(num_M);
  2141. send_multiplex_to_ESP_radio(num_M); //(oui deux fois ! sinon foire)
  2142. delay(100);
  2143. calcul_num_S(lst_sta[num_bouton-1].n_st);
  2144. send_station_to_ESP_radio(num_S);
  2145. send_station_to_ESP_radio(num_S); //(oui deux fois ! sinon foire)
  2146. //delay(100);
  2147. }
  2148.  
  2149.  
  2150. // CLIC sur l'imagette au bas du mode catalogue
  2151. bt_img2.test_clic(x_touch, y_touch);
  2152. if(bt_img2.cliked == true)
  2153. {
  2154. bt_img2.cliked = false;
  2155. affi_jpg_from_RAM(0, 0, 1); // grande
  2156. mode_affi = MODE_TOUT_ECRAN;
  2157. bt_stop_tout_ecran.affiche(BLANC, GRIS_6, 2, &TFT);
  2158. }
  2159.  
  2160. // CLIC sur le bouton pour basculer en mode 'expert'
  2161. bt_mode_expert.test_clic(x_touch, y_touch);
  2162. if(bt_mode_expert.cliked == true)
  2163. {
  2164. bt_mode_expert.cliked = false;
  2165.  
  2166. // juste un flash
  2167. bt_mode_expert.selected = 1; bt_mode_expert.affiche(BLANC, VERT, 1, &TFT); delay(100);
  2168. bt_mode_expert.selected = 0; bt_mode_expert.affiche(BLANC, VERT, 1, &TFT); delay(100);
  2169.  
  2170. mode_general = MODE_EXPERT;
  2171.  
  2172. TFT.fillScreen(NOIR);
  2173. setup_expert();
  2174. affichages_widgets_expert();
  2175. }
  2176.  
  2177. }
  2178.  
  2179. if((mode_general != MODE_PARAM) && (mode_general != MODE_CATALOGUE))// on invalide le LOGO tout-écran, dans le MODE_PARAM
  2180. {
  2181. // BOUTON LOGO (bouton caché sous l'imagette : bascule en tout-écran)
  2182. bt_LOGO.test_clic(x_touch, y_touch);
  2183.  
  2184. if(bt_LOGO.cliked == true)
  2185. {
  2186. if(mode_affi == MODE_PETITE)
  2187. {
  2188. mode_affi = MODE_TOUT_ECRAN;
  2189. bt_LOGO.cliked = false;
  2190. TFT.fillScreen(GRIS_1);
  2191. TJpgDec.setJpgScale(1); // grand
  2192. TJpgDec.setCallback(tft_output);
  2193. TJpgDec.drawJpg(0, 0, currentSlideBuffer, currentSlideSize); // affiche l'image stockée en RAM
  2194.  
  2195. bt_stop_tout_ecran.affiche(BLANC, GRIS_6, 2, &TFT);
  2196. }
  2197. delay(300);
  2198. }
  2199. }
  2200.  
  2201. // CLIC sur le petit bouton de retour ('x' en haut à droite)
  2202. if (mode_affi == MODE_TOUT_ECRAN)
  2203. {
  2204. bt_stop_tout_ecran.test_clic(x_touch, y_touch);
  2205. if(bt_stop_tout_ecran.cliked == true)
  2206. {
  2207. bt_stop_tout_ecran.cliked = false;
  2208.  
  2209. TFT.fillScreen(NOIR);
  2210. delay(100);
  2211. mode_affi = MODE_PETITE;
  2212. if(mode_general == MODE_EXPERT)
  2213. {
  2214. setup_expert();
  2215. affichages_widgets_expert();
  2216. show_boutons_selected();
  2217. affi_jpg_from_RAM(131, 77, 2); // petite
  2218. }
  2219. if(mode_general == MODE_CATALOGUE)
  2220. {
  2221. setup_catalogue();
  2222. affichages_widgets_catalogue();
  2223. affi_jpg_from_RAM(84, 178, 4); // petite
  2224. }
  2225. }
  2226. }
  2227. }
  2228. }
  2229.  
  2230.  

8 Documents

Tous les documents techniques (codes sources complets, implantations Kicad, datas...) sont disponibles ici:

9 -

Liens...


Pour me joindre : silicium628@free.fr
Un site complémentaire à celui-ci ; Electro & Robot

41