sound.cpp 2.3 KB

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