sound.cpp 2.3 KB

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