PowerTGS440

mp3_main_library.cpp

Feb 17th, 2021 (edited)
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.39 KB | None | 0 0
  1. // ******************************************************************************************************************* //
  2. // *** W I K I M P 3 L I B R A R Y ********************************************************************************* //
  3. // ******************************************************************************************************************* //
  4. // WIKIMP3.cpp //
  5. // //
  6. // biblioteka obsługi odtwarzacza mp3 dla MD_YX5300.h //
  7. // //
  8. // version : 0.1 BETA - codename : Music Is Play //
  9. // build date : 31.01.2021 //
  10. // code by : Wiktoria //
  11. // //
  12. // ******************************************************************************************************************* //
  13.  
  14.  
  15. #ifndef _wikimp3_h
  16. #include "wikimp3.h"
  17. #endif
  18.  
  19. #ifndef _arduino_h
  20. #include "Arduino.h"
  21. #endif
  22.  
  23. #ifndef _SoftwareSerial_h
  24. #include <SoftwareSerial.h>
  25. #endif
  26.  
  27. // 28364 - 2444
  28. // ------------------------------------------------------------------------------------------------------------- //
  29. // --- B T S ----------------------------------------------------------------------------------------------- //
  30. // ------------------------------------------------------------------------------------------------------------- //
  31. const unsigned int btsfile000 [] PROGMEM = { 0, 0, 1 };
  32. const unsigned int btsfile001 [] PROGMEM = { 1, 245, 1 };
  33. const unsigned int btsfile002 [] PROGMEM = { 2, 266, 1 };
  34. const unsigned int btsfile003 [] PROGMEM = { 3, 257, 1 };
  35. const unsigned int btsfile004 [] PROGMEM = { 4, 255, 1 };
  36. const unsigned int btsfile005 [] PROGMEM = { 5, 265, 1 };
  37. const unsigned int btsfile006 [] PROGMEM = { 6, 268, 1 };
  38. const unsigned int btsfile007 [] PROGMEM = { 7, 42, 1 };
  39. const unsigned int btsfile008 [] PROGMEM = { 8, 236, 1 };
  40. const unsigned int btsfile009 [] PROGMEM = { 9, 242, 1 };
  41. const unsigned int btsfile010 [] PROGMEM = { 10, 226, 1 };
  42. const unsigned int btsfile011 [] PROGMEM = { 11, 221, 1 };
  43. const unsigned int btsfile012 [] PROGMEM = { 12, 235, 1 };
  44. const unsigned int btsfile013 [] PROGMEM = { 13, 228, 1 };
  45. const unsigned int btsfile014 [] PROGMEM = { 14, 217, 1 };
  46. const unsigned int btsfile015 [] PROGMEM = { 15, 224, 1 };
  47. const unsigned int btsfile016 [] PROGMEM = { 16, 234, 1 };
  48. const unsigned int btsfile017 [] PROGMEM = { 17, 227, 1 };
  49. const unsigned int btsfile018 [] PROGMEM = { 18, 237, 1 };
  50. const unsigned int btsfile019 [] PROGMEM = { 19, 323, 1 };
  51. const unsigned int btsfile020 [] PROGMEM = { 20, 277, 1 };
  52. const unsigned int btsfile021 [] PROGMEM = { 21, 300, 1 };
  53. const unsigned int btsfile022 [] PROGMEM = { 22, 197, 1 };
  54. const unsigned int btsfile023 [] PROGMEM = { 23, 241, 1 };
  55. const unsigned int btsfile024 [] PROGMEM = { 24, 241, 1 };
  56. const unsigned int btsfile025 [] PROGMEM = { 25, 230, 1 };
  57. const unsigned int btsfile026 [] PROGMEM = { 26, 211, 1 };
  58. const unsigned int btsfile027 [] PROGMEM = { 27, 222, 1 };
  59. const unsigned int btsfile028 [] PROGMEM = { 28, 276, 1 };
  60. const unsigned int btsfile029 [] PROGMEM = { 29, 219, 1 };
  61. const unsigned int btsfile030 [] PROGMEM = { 30, 233, 1 };
  62. const unsigned int btsfile031 [] PROGMEM = { 31, 282, 1 };
  63. const unsigned int btsfile032 [] PROGMEM = { 32, 285, 1 };
  64. const unsigned int btsfile033 [] PROGMEM = { 33, 85, 1 };
  65. const unsigned int btsfile034 [] PROGMEM = { 34, 243, 1 };
  66. const unsigned int btsfile035 [] PROGMEM = { 35, 230, 1 };
  67. const unsigned int btsfile036 [] PROGMEM = { 36, 226, 1 };
  68. const unsigned int btsfile037 [] PROGMEM = { 37, 249, 1 };
  69. const unsigned int btsfile038 [] PROGMEM = { 38, 223, 1 };
  70. const unsigned int btsfile039 [] PROGMEM = { 39, 220, 1 };
  71. const unsigned int btsfile040 [] PROGMEM = { 40, 244, 1 };
  72. const unsigned int btsfile041 [] PROGMEM = { 41, 199, 1 };
  73. const unsigned int btsfile042 [] PROGMEM = { 42, 248, 1 };
  74. const unsigned int btsfile043 [] PROGMEM = { 43, 293, 1 };
  75. const unsigned int btsfile044 [] PROGMEM = { 44, 245, 1 };
  76. const unsigned int btsfile045 [] PROGMEM = { 45, 77, 1 };
  77. const unsigned int btsfile046 [] PROGMEM = { 46, 75, 1 };
  78. const unsigned int btsfile047 [] PROGMEM = { 47, 255, 1 };
  79. const unsigned int btsfile048 [] PROGMEM = { 48, 237, 1 };
  80. const unsigned int btsfile049 [] PROGMEM = { 49, 233, 1 };
  81. const unsigned int btsfile050 [] PROGMEM = { 50, 334, 1 };
  82. const unsigned int btsfile051 [] PROGMEM = { 51, 232, 1 };
  83. const unsigned int btsfile052 [] PROGMEM = { 52, 235, 1 };
  84. const unsigned int btsfile053 [] PROGMEM = { 53, 222, 1 };
  85. const unsigned int btsfile054 [] PROGMEM = { 54, 248, 1 };
  86. const unsigned int btsfile055 [] PROGMEM = { 55, 212, 1 };
  87. const unsigned int btsfile056 [] PROGMEM = { 56, 353, 1 };
  88. const unsigned int btsfile057 [] PROGMEM = { 57, 96, 1 };
  89. const unsigned int btsfile058 [] PROGMEM = { 58, 122, 1 };
  90. const unsigned int btsfile059 [] PROGMEM = { 59, 217, 1 };
  91. const unsigned int btsfile060 [] PROGMEM = { 60, 230, 1 };
  92. const unsigned int btsfile061 [] PROGMEM = { 61, 216, 1 };
  93. const unsigned int btsfile062 [] PROGMEM = { 62, 216, 1 };
  94. const unsigned int btsfile063 [] PROGMEM = { 63, 190, 1 };
  95. const unsigned int btsfile064 [] PROGMEM = { 64, 234, 1 };
  96. const unsigned int btsfile065 [] PROGMEM = { 65, 212, 1 };
  97. const unsigned int btsfile066 [] PROGMEM = { 66, 226, 1 };
  98. const unsigned int btsfile067 [] PROGMEM = { 67, 242, 1 };
  99. const unsigned int btsfile068 [] PROGMEM = { 68, 294, 1 };
  100. const unsigned int btsfile069 [] PROGMEM = { 69, 213, 1 };
  101. const unsigned int btsfile070 [] PROGMEM = { 70, 193, 1 };
  102. const unsigned int btsfile071 [] PROGMEM = { 71, 273, 1 };
  103. const unsigned int btsfile072 [] PROGMEM = { 72, 144, 1 };
  104. const unsigned int btsfile073 [] PROGMEM = { 73, 139, 1 };
  105. const unsigned int btsfile074 [] PROGMEM = { 74, 238, 1 };
  106. const unsigned int btsfile075 [] PROGMEM = { 75, 205, 1 };
  107. const unsigned int btsfile076 [] PROGMEM = { 76, 232, 1 };
  108. const unsigned int btsfile077 [] PROGMEM = { 77, 268, 1 };
  109. const unsigned int btsfile078 [] PROGMEM = { 78, 200, 1 };
  110. const unsigned int btsfile079 [] PROGMEM = { 79, 246, 1 };
  111. const unsigned int btsfile080 [] PROGMEM = { 80, 236, 1 };
  112. const unsigned int btsfile081 [] PROGMEM = { 81, 272, 1 };
  113. const unsigned int btsfile082 [] PROGMEM = { 82, 241, 1 };
  114. const unsigned int btsfile083 [] PROGMEM = { 83, 285, 1 };
  115. const unsigned int btsfile084 [] PROGMEM = { 84, 212, 1 };
  116. const unsigned int btsfile085 [] PROGMEM = { 85, 173, 1 };
  117. const unsigned int btsfile086 [] PROGMEM = { 86, 207, 1 };
  118. const unsigned int btsfile087 [] PROGMEM = { 87, 222, 1 };
  119. const unsigned int btsfile088 [] PROGMEM = { 88, 255, 1 };
  120. const unsigned int btsfile089 [] PROGMEM = { 89, 180, 1 };
  121. const unsigned int btsfile090 [] PROGMEM = { 90, 202, 1 };
  122. const unsigned int btsfile091 [] PROGMEM = { 91, 240, 1 };
  123. const unsigned int btsfile092 [] PROGMEM = { 92, 205, 1 };
  124. const unsigned int btsfile093 [] PROGMEM = { 93, 199, 1 };
  125. const unsigned int btsfile094 [] PROGMEM = { 94, 171, 1 };
  126. const unsigned int btsfile095 [] PROGMEM = { 95, 230, 1 };
  127. const unsigned int btsfile096 [] PROGMEM = { 96, 226, 1 };
  128. const unsigned int btsfile097 [] PROGMEM = { 97, 227, 1 };
  129. const unsigned int btsfile098 [] PROGMEM = { 98, 250, 1 };
  130. const unsigned int btsfile099 [] PROGMEM = { 99, 261, 1 };
  131. const unsigned int btsfile100 [] PROGMEM = { 100, 198, 1 };
  132. const unsigned int btsfile101 [] PROGMEM = { 101, 181, 1 };
  133. const unsigned int btsfile102 [] PROGMEM = { 102, 236, 1 };
  134. const unsigned int btsfile103 [] PROGMEM = { 103, 217, 1 };
  135. const unsigned int btsfile104 [] PROGMEM = { 104, 247, 1 };
  136. const unsigned int btsfile105 [] PROGMEM = { 105, 227, 1 };
  137. const unsigned int btsfile106 [] PROGMEM = { 106, 251, 1 };
  138. const unsigned int btsfile107 [] PROGMEM = { 107, 233, 1 };
  139. const unsigned int btsfile108 [] PROGMEM = { 108, 200, 1 };
  140. const unsigned int btsfile109 [] PROGMEM = { 109, 209, 1 };
  141. const unsigned int btsfile110 [] PROGMEM = { 110, 239, 1 };
  142. const unsigned int btsfile111 [] PROGMEM = { 111, 263, 1 };
  143. const unsigned int btsfile112 [] PROGMEM = { 112, 192, 1 };
  144.  
  145. // --------------------------------------------------------------------------------------------------
  146. const unsigned int * const btsfile[] PROGMEM = {
  147. btsfile000, btsfile001, btsfile002, btsfile003, btsfile004,
  148. btsfile005, btsfile006, btsfile007, btsfile008, btsfile009,
  149. btsfile010, btsfile011, btsfile012, btsfile013, btsfile014,
  150. btsfile015, btsfile016, btsfile017, btsfile018, btsfile019,
  151. btsfile020, btsfile021, btsfile022, btsfile023, btsfile024,
  152. btsfile025, btsfile026, btsfile027, btsfile028, btsfile029,
  153. btsfile030, btsfile031, btsfile032, btsfile033, btsfile034,
  154. btsfile035, btsfile036, btsfile037, btsfile038, btsfile039,
  155. btsfile040, btsfile041, btsfile042, btsfile043, btsfile044,
  156. btsfile045, btsfile046, btsfile047, btsfile048, btsfile049,
  157. btsfile050, btsfile051, btsfile052, btsfile053, btsfile054,
  158. btsfile055, btsfile056, btsfile057, btsfile058, btsfile059,
  159. btsfile060, btsfile061, btsfile062, btsfile063, btsfile064,
  160. btsfile065, btsfile066, btsfile067, btsfile068, btsfile069,
  161. btsfile070, btsfile071, btsfile072, btsfile073, btsfile074,
  162. btsfile075, btsfile076, btsfile077, btsfile078, btsfile079,
  163. btsfile080, btsfile081, btsfile082, btsfile083, btsfile084,
  164. btsfile085, btsfile086, btsfile087, btsfile088, btsfile089,
  165. btsfile090, btsfile091, btsfile092, btsfile093, btsfile094,
  166. btsfile095, btsfile096, btsfile097, btsfile098, btsfile099,
  167. btsfile100, btsfile101, btsfile102, btsfile103, btsfile104,
  168. btsfile105, btsfile106, btsfile107, btsfile108, btsfile109,
  169. btsfile110, btsfile111, btsfile112
  170. };
  171.  
  172. // --- Z M I E N N E E X T E R N ----------------------------------------------------------------------------------- //
  173. extern volatile uint_fast8_t godzina; // --- aktualna godzina dla MP3 - która godzina minęła -------- //
  174. //
  175. extern volatile uint_fast8_t progressBar[16]; // --- progress bar ------------------------------------------- //
  176. extern bool F_music_play; // --- flaga globalna --- czy muzyka jest odtwarzana ---------- //
  177. extern bool F_music_start; // --- flaga globalna --- muzyka zaczęła grać ----------------- //
  178. extern bool F_music_stop; // --- flaga globalna --- muzyka się skonczyla ---------------- //
  179. extern bool F_music_auto; // --- flaga globalna --- dla wątku jeślu TRUE to wywołuj ----- //
  180. // --- funkcję MP3Play(); jeśli trwa odtwarzanie lub jeśli ---- //
  181. // --- F_mp3_is_play przestawione na FALSE wywołaj MP3Start --- //
  182. extern bool F_timer_auto; // --- flaga globalna --- powiedz ktora godzina --------------- //
  183. extern bool F_NeoFire_stop; // --- ustaw na TRUE jeśli mp3_STOP --------------------------- //
  184. extern bool F_NeoFire_play; // --- ustaw na TRUE jeśli mp3 PLAY --------------------------- //
  185. extern volatile uint_fast16_t data[4]; // --- bieżąca data [0] -> to dzień tygodnia, od 1 do 7 //
  186. // --- I N I T ------------------------------------------------------------------------------------------------------- //
  187. void WIKIMP3::init() //
  188. { //
  189. mp3.volume(mp3_volume); // --- volume na 60 (max 67, HEX: 0x43) //
  190. sizeBTS = sizeof(btsfile)/2; // --- ile plików mp3 --- policz ------------------------------ //
  191. } //
  192. // --- M P 3 P L A Y ----------------------------------------------------------------------------------------------- //
  193. void WIKIMP3::MP3Play() //
  194. { //
  195. unsigned int progress = 0; // --- przechowuj tu zmapowany stan progress BAR -------------- //
  196. //
  197. // --- jesli trwa odtwarzanie ------------------------------------------------------------------------------------ //
  198. if(F_mp3_is_play) //
  199. { //
  200. mp3_current_time++; // czas utworu +1 ---------------- //
  201. progress = map(mp3_current_time, 0, mp3_playing_time, 1, 17); // mapuj czas do progress BAR ---- //
  202. for(byte index = 0; index < progress; index ++) progressBar[index] = 1; // zapisz tablicę progress BAR --- //
  203. // --- komunikacja SERIAL ------------------------------------------------------------------------------------ //
  204. #if DEBUG_WIKIMP3
  205. static byte slow_debug = 0; //
  206. slow_debug ++; //
  207. if(slow_debug > 9) //
  208. { //
  209. Serial.print(F("Inside: MP3Play(); Music is now Play !!! Nr.Pliku : ")); //
  210. Serial.print(mp3_current_file); //
  211. Serial.print(F(" Real Time: ")); //
  212. Serial.print(mp3_current_time); //
  213. Serial.print(F(" of ")); //
  214. Serial.println(mp3_playing_time); //
  215. slow_debug = 0; //
  216. } //
  217. //
  218. #endif //
  219. } //
  220. // --- jeśli skończył się utwót ---------------------------------------------------------------------------------- //
  221. if(mp3_current_time>=mp3_playing_time) //
  222. { //
  223. F_mp3_is_play = false; // odtwarzacz WOLNY -------------- //
  224. F_music_stop = true; // dla LCD -> usuń progress BAR -- //
  225. //
  226. if(mp3_current_file<sizeBTS) mp3_current_file++; // ustaw znacznik na kolejny plik //
  227. else mp3_current_file=1; // koniec playlisty, RESET LOOP -- //
  228. // --- komunikacja SERIAL ------------------------------------------------------------------------------------ //
  229. #if DEBUG_WIKIMP3
  230. static byte slow_debug = 0; //
  231. slow_debug ++; //
  232. if(slow_debug > 10) //
  233. { //
  234. Serial.print(F("Inside: MP3Play(); Music is end Play !!! Nr.Pliku nastepnego: ")); //
  235. Serial.println(mp3_current_file); //
  236. slow_debug = 0; //
  237. } //
  238. #endif //
  239. //
  240. } //
  241. } //
  242. // --- M P 3 S T A R T --------------------------------------------------------------------------------------------- //
  243. void WIKIMP3::MP3Start() //
  244. { //
  245. // jesli muzyka nie jest odtwarzana uruchom od bieżącego pliku --------------------------------------------------- //
  246. if(!F_mp3_is_play) //
  247. {
  248. unsigned int * ptr = (unsigned int*) pgm_read_word(&btsfile[mp3_current_file]); // wskaźnik do PROGMEM --- //
  249. mp3_current_file = pgm_read_word ( & ptr[0] ); // wyłuskaj nr. pliku ---- //
  250. mp3_playing_time = pgm_read_word ( & ptr[1] ); // wyłuskaj czas trwania - //
  251. //mp3_current_dir = pgm_read_word ( & ptr[2] ); // wyluskaj folder plikow //
  252. mp3_current_time = 0; // zeruj czas ------------ //
  253. //
  254. mp3.playSpecific(1, mp3_current_file); // uruchom odtwarzanie ----------------------------- //
  255. //
  256. F_mp3_is_play = true; // flaga TRUE jeśli trwa odtwarzanie //
  257. F_music_play = true; // flaga dla LCD, jesli TRUE to progress BAR //
  258. F_music_stop = false; // ??? --------------------------------------------- //
  259. F_music_start = true; // flaga dla LCD, jeśli start to rysuj progress //
  260. //
  261. // potem jest przestawiania na FALSE by nie drukować //
  262. // poraz kolejny, tylko uzupełniany postęp pliku //
  263. F_music_auto = true; // flaga wątku (jeśli TRUE sprawdzaj co 1 sekundę) //
  264. F_timer_auto = false; // flaga TimeSpeaker --- FALSE jesli blokada ------- //
  265. F_NeoFire_play = true; // uruchom wątek dla FireLed ----------------------- //
  266. // --- komunikacja SERIAL ------------------------------------------------------------------------------------ //
  267. #if DEBUG_WIKIMP3
  268. Serial.print(F("Inside: MP3Start(); Start Music Play !!! Uruchomiono plik, nr: "));
  269. Serial.println(mp3_current_file);
  270. #endif //
  271. } //
  272. // jeśli muzyka jest odtwarzana to : STOP i reset flag ----------------------------------------------------------- //
  273. else //
  274. { //
  275. mp3.playStop(); // zatrzymaj muzykę //
  276. F_music_play = false; // dla wyświetlacza LCD, nie wyświetlaj progress BAR //
  277. F_music_auto = false; // dla wątku, nie uruchamiaj funkcji PlayerUpdate //
  278. F_mp3_is_play = false; // flaga FALSE jeśli nie trwa odtwarzanie //
  279. F_music_stop = true; // flaga dla LCD -> jest STOP wyczyść progress BAR //
  280. F_timer_auto = true; // pozwolenie na TimeSpeaker ----------------------- //
  281. F_NeoFire_stop = true; // zatrzymaj wątek dla FireLed --------------------- //
  282. // --- komunikacja SERIAL ------------------------------------------------------------------------------------ //
  283. #if DEBUG_WIKIMP3
  284. Serial.print(F("Inside: MP3Start(); Stop Music Play !!! Zatrzymano na pliku, nr: "));
  285. Serial.println(mp3_current_file - 1);
  286. #endif //
  287. } //
  288. } //
  289. // ------------------------------------------------------------------------------------------------------------------- //
  290. // ---- M P 3 N E X T F I L E ------------------------------------------------------------------------------------ //
  291. // ------------------------------------------------------------------------------------------------------------------- //
  292. // void WIKIMP3::MP3Next() uruchamiana jest tylko wtedy kiedy trwa odtwarzanie pliku mp3. Funkcja jest uruchamiana //
  293. // z funkcji PlayerUpdate, która otrzymuje kod pilota - jeśli jest to 3 i flaga TRUE //
  294. // Wykorzystano do obsługi kolejnego pliku funkcje MP3Start (stop/przestawienie/start) //
  295. // ------------------------------------------------------------------------------------------------------------------- //
  296. void WIKIMP3::MP3Next() //
  297. { //
  298. // zatrzymanie odtwarzacza ------------------------- //
  299. if(mp3_current_file<sizeBTS) mp3_current_file++; // ustaw znacznik na kolejny plik jeśli nie koniec - //
  300. else mp3_current_file=1; // ustaw znacznik na pierwszy plik jeśli koniec ---- //
  301. MP3Start(); // zatrzymaj odtwarzacz ---------------------------- //
  302. for(byte index = 0; index <= 16; index ++) progressBar[index] = 0; // posprzątaj progress BAR ------ //
  303. // --- komunikacja SERIAL ---------------------------------------------------------------------------------------- //
  304. #if DEBUG_WIKIMP3
  305. Serial.print(F("Inside: MP3Next(); Check -> mp3_current_file = "));
  306. Serial.println(mp3_current_file);
  307. #endif
  308. } //
  309. // ---- M P 3 P R E V F I L E ------------------------------------------------------------------------------------ //
  310. void WIKIMP3::MP3Prev() //
  311. { //
  312. if(mp3_current_file==1) mp3_current_file = sizeBTS - 1; //
  313. else mp3_current_file --; //
  314. MP3Start(); // zatrzymaj odtwarzacz ---------------------------- //
  315. for(byte index = 0; index <= 16; index ++) progressBar[index] = 0; // posprzątaj progress BAR ------ //
  316. // --- komunikacja SERIAL ---------------------------------------------------------------------------------------- //
  317. #if DEBUG_WIKIMP3
  318. Serial.print(F("Inside: MP3Prev(); Check -> mp3_current_file = "));
  319. Serial.println(mp3_current_file);
  320. #endif //
  321. } //
  322. // ------------------------------------------------------------------------------------------------------------------- //
  323. // ---- M P 3 V O L U M E U P ---------------------------------------------------------------------------------- //
  324. // ------------------------------------------------------------------------------------------------------------------- //
  325. // Funkcja zwiększająca dźwięk. Wykona się jeśli na pilocie zostanie wciśnięty przycisk "+" oraz flaga //
  326. // F_mp3_is_play ma wartość TRUE - czyli aktualnie odtwarzany jest plik. mp3, w innym przypadku nic nie jest robione //
  327. // maksymalna wartość to 60, każde wciśnięcie powiększa bieżącą wartość o 5 jednostek pod warunkiem, że nie osiągnięto //
  328. // wartości maksymalnej. Jeśli DEBUG_WIKIMP3 ma wartość TRUE pokazuj na SERIAL MONITOR komunikaty //
  329. // ------------------------------------------------------------------------------------------------------------------- //
  330. void WIKIMP3::MP3VolUp() //
  331. { //
  332. if(mp3_volume < 56) // jeśli nie osiągnięto maksimum --- //
  333. { //
  334. mp3_volume += 5; // zwiększ dźwięk o 5 jeśli < 56 --- //
  335. mp3.volume(mp3_volume); // ustaw nową wartość dźwięku ------ //
  336. } //
  337. // --- komunikacja SERIAL ---------------------------------------------------------------------------------------- //
  338. #if DEBUG_WIKIMP3
  339. Serial.print(F("Inside: MP3VolUp(); Check -> uint8_t mp3_volume = "));
  340. Serial.println(mp3_volume);
  341. #endif //
  342. //
  343. } //
  344. // ------------------------------------------------------------------------------------------------------------------- //
  345. // ---- M P 3 V O L U M E D O W N ------------------------------------------------------------------------------ //
  346. // ------------------------------------------------------------------------------------------------------------------- //
  347. // Funkcja zmniejszająca dźwięk. Wykona się jeśli na pilocie zostanie wciśnięty przycisk "-" oraz flaga //
  348. // F_mp3_is_play ma wartość TRUE - czyli aktualnie odtwarzany jest plik. mp3, w innym przypadku nic nie jest robione //
  349. // minimalna wartość to 0, każde wciśnięcie pomniejsza bieżącą wartość o 5 jednostek, pod warunkiem, że nie osiągnięto //
  350. // wartości minimalnej. Jeśli DEBUG_WIKIMP3 ma wartość TRUE pokazuj na SERIAL MONITOR komunikaty //
  351. // ------------------------------------------------------------------------------------------------------------------- //
  352. void WIKIMP3::MP3VolDown() //
  353. { //
  354. if(mp3_volume > 4) // jeśli nie osiągnieto minimum ---- //
  355. { //
  356. mp3_volume -=5; // zmniejsz dźwięk 0 5 jeśli > 4 --- //
  357. mp3.volume(mp3_volume); // ustaw nową wartość dźwięku ------ //
  358. } //
  359. // --- komunikacja SERIAL ---------------------------------------------------------------------------------------- //
  360. #if DEBUG_WIKIMP3
  361. Serial.print(F("Inside: MP3VolDown(); Check -> uint8_t mp3_volume = "));
  362. Serial.println(mp3_volume);
  363. #endif //
  364. } //
  365. // ------------------------------------------------------------------------------------------------------------------- //
  366. // ---- T I M E S P E A K E R b y C Z U B Ó W N A -------------------------------------------------------------- //
  367. // ------------------------------------------------------------------------------------------------------------------- //
  368. // Funkcja co godzinę mówi głosem Czubówny która godzina upłynęła. Uruchamiana jest tylko wtedy kiedy odtwarzacz //
  369. // nie odtwarza w danej chwili pliku mp3. Za pozwolenie na wykonanie odpowiada flaga : F_timer_auto, jest jest FALSE //
  370. // nigdy się nie wykona, możliwe tylko wtedy gdy program sterujący mp3 przestawi flagę na TRUE czyli zwolni mp3 //
  371. // ------------------------------------------------------------------------------------------------------------------- //
  372. void WIKIMP3::SpeakTime() //
  373. { //
  374. mp3.playSpecific(2, godzina); // powiedz która godzina ----------- //
  375. // --- komunikacja SERIAL ---------------------------------------------------------------------------------------- //
  376. #if DEBUG_WIKIMP3
  377. Serial.print(F("Inside: SpeakTime(); Say: Time "));
  378. Serial.println(godzina);
  379. #endif
  380.  
  381. } //
  382. // ------------------------------------------------------------------------------------------------------------------- //
  383. // --- A U T O P L A Y E R I O B S Ł U G A P I L O T A ------------------------------------------------------ //
  384. // //
  385. // code = 0 -> jeśli flaga F_music_auto jest TRUE kod wchodzi z obsługi wątku co 1 sekundę w celu wyświetlenia //
  386. // progressBAR na wyświetlaczu LCD, zwiększenia programowo czasu odwarzanego pliku : mp3_current_time ++ //
  387. // jeśli odtwarzanie dobiegło końcowi zaczynają się operację wyboru następnego utworu i sprzątanie //
  388. // progress BAR, przestawianie FLAG. Jeśli F_music_auto to FALSE funkcja klasy nie jest wywoływana //
  389. // //
  390. // case = 1 -> jeśli flaga F_mp3_is_play to TRUE wywołana funkcja MP3Start powoduje zatrzymanie odtwarzania //
  391. // jeśli flaga F_mp3_is_play to FALSE wywołana funkcja MP3Start powoduje rozpoczęcie odtwarzania //
  392. // kod 1 - pochodzi z przycisku PLAY pilota, możliwe że w późniejszym czasie będzie też wysyłany przez //
  393. // funkcje zarządzające czasem (autoplay / autostop) o danych godzinach w określonych dniach //
  394. // //
  395. // case = 2 -> jeśli flaga F_music_is_play jest TRUE czyli trwa odtwarzanie, wywołaj funkcję MP3Prev(); //
  396. // przestaw bieżący plik na poprzedni, ale jeśli obecnie odtwarzany plik jest pierwszym z playlisty //
  397. // to ustaw na ostatni. Zatrzymaj odtwarzanie funkcją MP3Start(); i ponowie ją wywołaj w celu PLAY //
  398. // //
  399. // case = 3 -> jeśli flaga F_music_is_play jest TRUE czyli trwa odtwarzanie, wywołaj funkcję MP3Next(); //
  400. // przestaw bieżący plik na następny, ale jeśli obecnie odtwarzany plik jest ostatnim z playlisty //
  401. // to ustaw na pierwszy. Zatrzymaj odtwarzanie funkcją MP3Start(); i ponowie ją wywołaj w celu PLAY //
  402. // //
  403. // case = 4 -> jeśli flaga F_music_is_play jest TRUE czyli trwa odtwarzanie, wywołaj funkcję MP3VolUp(); //
  404. // zwiększ głośność o 5 jednostek pod warunkiem że nie osiągnięto wartości maksymalnej 60 //
  405. // //
  406. // case = 5 -> jesli flaga F_music_is_play jest TRUE czyli trwa odtwarzanie, wywołaj funkcję MP3VolDown(); //
  407. // zmniejsz głośność o 5 jednostek pod warunkiem że nie osiągnieto wartości minimalnej 0 //
  408. // ------------------------------------------------------------------------------------------------------------------- //
  409. void WIKIMP3::PlayerUpdate(byte code) //
  410. { //
  411. switch (code) //
  412. { //
  413. case 0 : if ( F_mp3_is_play ) MP3Play(); // jesli trwa odtwarzanie wykonaj operacje obsługi --- //
  414. else //
  415. if (!F_mp3_is_play ) MP3Start(); // auto play -> obsługiwane flagą f_musi_auto -------- //
  416. break;
  417. case 1 : MP3Start(); // uruchom funkcję PLAY jest (F_mp3_is_play = FALSE) //
  418. break;
  419. case 2 : MP3Prev();
  420. MP3Start();
  421. break;
  422. case 3 : MP3Next();
  423. MP3Start(); // next mp3 file -> jeśli F_mp3_is_play jest TRUE ---- //
  424. break;
  425. case 4 : MP3VolUp();
  426. break;
  427. case 5 : MP3VolDown();
  428. break;
  429. default : break; //
  430. } //
  431. } //
  432. // ------------------------------------------------------------------------------------------------------------------- //
  433.  
  434. /*
  435. void Test(int nr)
  436. {
  437. unsigned int * ptr = (unsigned int*) pgm_read_word(&btsfile[nr]);
  438. cFile = pgm_read_word ( & ptr[0] );
  439. cTime = pgm_read_word ( & ptr[1] );
  440.  
  441. Serial.print("FILE : ");
  442. Serial.println(cFile);
  443. Serial.print("TIME : ");
  444. Serial.println(cTime);
  445. }
  446. */
Add Comment
Please, Sign In to add comment