sound.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. void Sound_Init(void)
  15. {
  16. SET_OUTPUT(BEEPER);
  17. eSoundMode=(eSOUND_MODE)eeprom_read_byte((uint8_t*)EEPROM_SOUND_MODE);
  18. if(eSoundMode==e_SOUND_MODE_NULL)
  19. Sound_Default(); // je potreba provest i ulozeni do EEPROM
  20. }
  21. void Sound_Default(void)
  22. {
  23. eSoundMode=e_SOUND_MODE_DEFAULT;
  24. Sound_SaveMode();
  25. }
  26. void Sound_SaveMode(void)
  27. {
  28. eeprom_update_byte((uint8_t*)EEPROM_SOUND_MODE,(uint8_t)eSoundMode);
  29. }
  30. void Sound_CycleState(void)
  31. {
  32. switch(eSoundMode)
  33. {
  34. case e_SOUND_MODE_LOUD:
  35. eSoundMode=e_SOUND_MODE_ONCE;
  36. break;
  37. case e_SOUND_MODE_ONCE:
  38. eSoundMode=e_SOUND_MODE_SILENT;
  39. break;
  40. case e_SOUND_MODE_SILENT:
  41. eSoundMode=e_SOUND_MODE_MUTE;
  42. break;
  43. case e_SOUND_MODE_MUTE:
  44. eSoundMode=e_SOUND_MODE_LOUD;
  45. break;
  46. default:
  47. eSoundMode=e_SOUND_MODE_LOUD;
  48. }
  49. Sound_SaveMode();
  50. }
  51. void Sound_MakeSound(eSOUND_TYPE eSoundType)
  52. {
  53. switch(eSoundMode)
  54. {
  55. case e_SOUND_MODE_LOUD:
  56. if(eSoundType==e_SOUND_TYPE_ButtonEcho)
  57. Sound_DoSound_Echo();
  58. if(eSoundType==e_SOUND_TYPE_StandardPrompt)
  59. Sound_DoSound_Prompt();
  60. if(eSoundType==e_SOUND_TYPE_StandardAlert)
  61. Sound_DoSound_Alert(false);
  62. break;
  63. case e_SOUND_MODE_ONCE:
  64. if(eSoundType==e_SOUND_TYPE_ButtonEcho)
  65. Sound_DoSound_Echo();
  66. if(eSoundType==e_SOUND_TYPE_StandardPrompt)
  67. Sound_DoSound_Prompt();
  68. if(eSoundType==e_SOUND_TYPE_StandardAlert)
  69. Sound_DoSound_Alert(true);
  70. break;
  71. case e_SOUND_MODE_SILENT:
  72. if(eSoundType==e_SOUND_TYPE_StandardAlert)
  73. Sound_DoSound_Alert(true);
  74. break;
  75. case e_SOUND_MODE_MUTE:
  76. break;
  77. default:
  78. ;
  79. }
  80. }
  81. static void Sound_DoSound_Echo(void)
  82. {
  83. uint8_t nI;
  84. for(nI=0;nI<10;nI++)
  85. {
  86. WRITE(BEEPER,HIGH);
  87. delayMicroseconds(100);
  88. WRITE(BEEPER,LOW);
  89. delayMicroseconds(100);
  90. }
  91. }
  92. static void Sound_DoSound_Prompt(void)
  93. {
  94. WRITE(BEEPER,HIGH);
  95. delay_keep_alive(500);
  96. WRITE(BEEPER,LOW);
  97. }
  98. static void Sound_DoSound_Alert(bool bOnce)
  99. {
  100. uint8_t nI,nMax;
  101. nMax=bOnce?1:3;
  102. for(nI=0;nI<nMax;nI++)
  103. {
  104. WRITE(BEEPER,HIGH);
  105. delay_keep_alive(200);
  106. WRITE(BEEPER,LOW);
  107. delay_keep_alive(500);
  108. }
  109. }