sound.cpp 4.5 KB

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