sound.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_LOUD;
  41. break;
  42. default:
  43. eSoundMode=e_SOUND_MODE_LOUD;
  44. }
  45. Sound_SaveMode();
  46. }
  47. void Sound_MakeSound(eSOUND_CLASS eSoundClass,eSOUND_TYPE eSoundType)
  48. {
  49. switch(eSoundMode)
  50. {
  51. case e_SOUND_MODE_LOUD:
  52. if(eSoundType==e_SOUND_TYPE_ButtonEcho)
  53. Sound_DoSound_Echo();
  54. if(eSoundType==e_SOUND_TYPE_StandardPrompt)
  55. Sound_DoSound_Prompt();
  56. break;
  57. case e_SOUND_MODE_ONCE:
  58. if(eSoundType==e_SOUND_TYPE_ButtonEcho)
  59. Sound_DoSound_Echo();
  60. if(eSoundType==e_SOUND_TYPE_StandardPrompt)
  61. Sound_DoSound_Prompt();
  62. break;
  63. case e_SOUND_MODE_SILENT:
  64. break;
  65. default:
  66. ;
  67. }
  68. }
  69. static void Sound_DoSound_Echo(void)
  70. {
  71. uint8_t nI;
  72. for(nI=0;nI<10;nI++)
  73. {
  74. WRITE(BEEPER,HIGH);
  75. delayMicroseconds(100);
  76. WRITE(BEEPER,LOW);
  77. delayMicroseconds(100);
  78. }
  79. }
  80. static void Sound_DoSound_Prompt(void)
  81. {
  82. WRITE(BEEPER,HIGH);
  83. delay_keep_alive(500);
  84. WRITE(BEEPER,LOW);
  85. }