sound.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #include "sound.h"
  2. #include "Marlin.h"
  3. //#include <inttypes.h>
  4. //#include <avr/eeprom.h>
  5. //#include "eeprom.h"
  6. #include "backlight.h"
  7. //eSOUND_MODE eSoundMode=e_SOUND_MODE_LOUD;
  8. // nema vyznam, pokud se bude volat Sound_Init (tzn. poc. hodnota je v EEPROM)
  9. // !?! eSOUND_MODE eSoundMode; v ultraldc.cpp :: cd_settings_menu() se takto jevi jako lokalni promenna
  10. eSOUND_MODE eSoundMode; //=e_SOUND_MODE_DEFAULT;
  11. static void Sound_SaveMode(void);
  12. static void Sound_DoSound_Echo(void);
  13. static void Sound_DoSound_Prompt(void);
  14. static void Sound_DoSound_Alert(bool bOnce);
  15. static void Sound_DoSound_Encoder_Move(void);
  16. static void Sound_DoSound_Blind_Alert(void);
  17. void Sound_Init(void)
  18. {
  19. SET_OUTPUT(BEEPER);
  20. eSoundMode=(eSOUND_MODE)eeprom_read_byte((uint8_t*)EEPROM_SOUND_MODE);
  21. if(eSoundMode==e_SOUND_MODE_NULL)
  22. Sound_Default(); // je potreba provest i ulozeni do EEPROM
  23. }
  24. void Sound_Default(void)
  25. {
  26. eSoundMode=e_SOUND_MODE_DEFAULT;
  27. Sound_SaveMode();
  28. }
  29. void Sound_SaveMode(void)
  30. {
  31. eeprom_update_byte((uint8_t*)EEPROM_SOUND_MODE,(uint8_t)eSoundMode);
  32. }
  33. void Sound_CycleState(void)
  34. {
  35. switch(eSoundMode)
  36. {
  37. case e_SOUND_MODE_LOUD:
  38. eSoundMode=e_SOUND_MODE_ONCE;
  39. break;
  40. case e_SOUND_MODE_ONCE:
  41. eSoundMode=e_SOUND_MODE_SILENT;
  42. break;
  43. case e_SOUND_MODE_SILENT:
  44. eSoundMode=e_SOUND_MODE_BLIND;
  45. break;
  46. case e_SOUND_MODE_BLIND:
  47. eSoundMode=e_SOUND_MODE_LOUD;
  48. break;
  49. default:
  50. eSoundMode=e_SOUND_MODE_LOUD;
  51. }
  52. Sound_SaveMode();
  53. }
  54. //if critical is true then silend and once mode is ignored
  55. void Sound_MakeCustom(uint16_t ms,uint16_t tone_,bool critical){
  56. backlight_wake();
  57. if (!critical){
  58. if (eSoundMode != e_SOUND_MODE_SILENT){
  59. if(!tone_){
  60. WRITE(BEEPER, HIGH);
  61. _delay(ms);
  62. WRITE(BEEPER, LOW);
  63. }
  64. else{
  65. _tone(BEEPER, tone_);
  66. _delay(ms);
  67. _noTone(BEEPER);
  68. }
  69. }
  70. }
  71. else{
  72. if(!tone_){
  73. WRITE(BEEPER, HIGH);
  74. _delay(ms);
  75. WRITE(BEEPER, LOW);
  76. }
  77. else{
  78. _tone(BEEPER, tone_);
  79. _delay(ms);
  80. _noTone(BEEPER);
  81. }
  82. }
  83. }
  84. void Sound_MakeSound(eSOUND_TYPE eSoundType)
  85. {
  86. switch(eSoundMode)
  87. {
  88. case e_SOUND_MODE_LOUD:
  89. if(eSoundType==e_SOUND_TYPE_ButtonEcho)
  90. Sound_DoSound_Echo();
  91. if(eSoundType==e_SOUND_TYPE_StandardPrompt)
  92. Sound_DoSound_Prompt();
  93. if(eSoundType==e_SOUND_TYPE_StandardAlert)
  94. Sound_DoSound_Alert(false);
  95. break;
  96. case e_SOUND_MODE_ONCE:
  97. if(eSoundType==e_SOUND_TYPE_ButtonEcho)
  98. Sound_DoSound_Echo();
  99. if(eSoundType==e_SOUND_TYPE_StandardPrompt)
  100. Sound_DoSound_Prompt();
  101. if(eSoundType==e_SOUND_TYPE_StandardAlert)
  102. Sound_DoSound_Alert(true);
  103. break;
  104. case e_SOUND_MODE_SILENT:
  105. if(eSoundType==e_SOUND_TYPE_StandardAlert)
  106. Sound_DoSound_Alert(true);
  107. break;
  108. case e_SOUND_MODE_BLIND:
  109. if(eSoundType==e_SOUND_TYPE_ButtonEcho)
  110. Sound_DoSound_Echo();
  111. if(eSoundType==e_SOUND_TYPE_StandardPrompt)
  112. Sound_DoSound_Prompt();
  113. if(eSoundType==e_SOUND_TYPE_StandardAlert)
  114. Sound_DoSound_Alert(false);
  115. if(eSoundType==e_SOUND_TYPE_EncoderMove)
  116. Sound_DoSound_Encoder_Move();
  117. if(eSoundType==e_SOUND_TYPE_BlindAlert)
  118. Sound_DoSound_Blind_Alert();
  119. break;
  120. default:
  121. break;
  122. }
  123. }
  124. static void Sound_DoSound_Blind_Alert(void)
  125. {
  126. backlight_wake(1);
  127. uint8_t nI;
  128. for(nI=0; nI<20; nI++)
  129. {
  130. WRITE(BEEPER,HIGH);
  131. delayMicroseconds(94);
  132. WRITE(BEEPER,LOW);
  133. delayMicroseconds(94);
  134. }
  135. }
  136. static void Sound_DoSound_Encoder_Move(void)
  137. {
  138. backlight_wake();
  139. uint8_t nI;
  140. for(nI=0;nI<5;nI++)
  141. {
  142. WRITE(BEEPER,HIGH);
  143. delayMicroseconds(75);
  144. WRITE(BEEPER,LOW);
  145. delayMicroseconds(75);
  146. }
  147. }
  148. static void Sound_DoSound_Echo(void)
  149. {
  150. backlight_wake();
  151. uint8_t nI;
  152. for(nI=0;nI<10;nI++)
  153. {
  154. WRITE(BEEPER,HIGH);
  155. delayMicroseconds(100);
  156. WRITE(BEEPER,LOW);
  157. delayMicroseconds(100);
  158. }
  159. }
  160. static void Sound_DoSound_Prompt(void)
  161. {
  162. backlight_wake(2);
  163. WRITE(BEEPER,HIGH);
  164. _delay_ms(500);
  165. WRITE(BEEPER,LOW);
  166. }
  167. static void Sound_DoSound_Alert(bool bOnce)
  168. {
  169. backlight_wake();
  170. uint8_t nI,nMax;
  171. nMax=bOnce?1:3;
  172. for(nI=0;nI<nMax;nI++)
  173. {
  174. WRITE(BEEPER,HIGH);
  175. delayMicroseconds(200);
  176. WRITE(BEEPER,LOW);
  177. delayMicroseconds(500);
  178. }
  179. }