2018-07-23 18:04:47 +00:00
|
|
|
#include "sound.h"
|
|
|
|
|
|
|
|
#include "Marlin.h"
|
|
|
|
|
|
|
|
//#include <inttypes.h>
|
|
|
|
//#include <avr/eeprom.h>
|
|
|
|
//#include "eeprom.h"
|
2019-10-30 19:11:19 +00:00
|
|
|
#include "backlight.h"
|
2018-07-23 18:04:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
//eSOUND_MODE eSoundMode=e_SOUND_MODE_LOUD;
|
|
|
|
// nema vyznam, pokud se bude volat Sound_Init (tzn. poc. hodnota je v EEPROM)
|
|
|
|
// !?! eSOUND_MODE eSoundMode; v ultraldc.cpp :: cd_settings_menu() se takto jevi jako lokalni promenna
|
|
|
|
eSOUND_MODE eSoundMode; //=e_SOUND_MODE_DEFAULT;
|
|
|
|
|
|
|
|
|
|
|
|
static void Sound_SaveMode(void);
|
|
|
|
static void Sound_DoSound_Echo(void);
|
|
|
|
static void Sound_DoSound_Prompt(void);
|
2018-11-02 22:03:14 +00:00
|
|
|
static void Sound_DoSound_Alert(bool bOnce);
|
2019-06-10 13:03:52 +00:00
|
|
|
static void Sound_DoSound_Encoder_Move(void);
|
|
|
|
static void Sound_DoSound_Blind_Alert(void);
|
2018-07-23 18:04:47 +00:00
|
|
|
|
|
|
|
void Sound_Init(void)
|
|
|
|
{
|
2018-07-25 17:24:41 +00:00
|
|
|
SET_OUTPUT(BEEPER);
|
2018-07-23 18:04:47 +00:00
|
|
|
eSoundMode=(eSOUND_MODE)eeprom_read_byte((uint8_t*)EEPROM_SOUND_MODE);
|
|
|
|
if(eSoundMode==e_SOUND_MODE_NULL)
|
|
|
|
Sound_Default(); // je potreba provest i ulozeni do EEPROM
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sound_Default(void)
|
|
|
|
{
|
|
|
|
eSoundMode=e_SOUND_MODE_DEFAULT;
|
|
|
|
Sound_SaveMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sound_SaveMode(void)
|
|
|
|
{
|
|
|
|
eeprom_update_byte((uint8_t*)EEPROM_SOUND_MODE,(uint8_t)eSoundMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sound_CycleState(void)
|
|
|
|
{
|
|
|
|
switch(eSoundMode)
|
|
|
|
{
|
|
|
|
case e_SOUND_MODE_LOUD:
|
|
|
|
eSoundMode=e_SOUND_MODE_ONCE;
|
|
|
|
break;
|
|
|
|
case e_SOUND_MODE_ONCE:
|
|
|
|
eSoundMode=e_SOUND_MODE_SILENT;
|
|
|
|
break;
|
|
|
|
case e_SOUND_MODE_SILENT:
|
2019-06-10 13:03:52 +00:00
|
|
|
eSoundMode=e_SOUND_MODE_BLIND;
|
2018-07-23 18:04:47 +00:00
|
|
|
break;
|
2019-06-10 13:03:52 +00:00
|
|
|
case e_SOUND_MODE_BLIND:
|
2018-07-23 18:04:47 +00:00
|
|
|
eSoundMode=e_SOUND_MODE_LOUD;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
eSoundMode=e_SOUND_MODE_LOUD;
|
|
|
|
}
|
|
|
|
Sound_SaveMode();
|
|
|
|
}
|
|
|
|
|
2019-07-17 10:32:27 +00:00
|
|
|
//if critical is true then silend and once mode is ignored
|
2019-06-10 13:03:52 +00:00
|
|
|
void Sound_MakeCustom(uint16_t ms,uint16_t tone_,bool critical){
|
2019-10-31 17:07:20 +00:00
|
|
|
backlight_wake();
|
2019-06-10 13:03:52 +00:00
|
|
|
if (!critical){
|
|
|
|
if (eSoundMode != e_SOUND_MODE_SILENT){
|
|
|
|
if(!tone_){
|
|
|
|
WRITE(BEEPER, HIGH);
|
2019-07-17 10:32:27 +00:00
|
|
|
_delay(ms);
|
2019-06-10 13:03:52 +00:00
|
|
|
WRITE(BEEPER, LOW);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
_tone(BEEPER, tone_);
|
2019-07-17 10:32:27 +00:00
|
|
|
_delay(ms);
|
2019-06-10 13:03:52 +00:00
|
|
|
_noTone(BEEPER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if(!tone_){
|
|
|
|
WRITE(BEEPER, HIGH);
|
2019-07-17 10:32:27 +00:00
|
|
|
_delay(ms);
|
2019-06-10 13:03:52 +00:00
|
|
|
WRITE(BEEPER, LOW);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
_tone(BEEPER, tone_);
|
2019-07-17 10:32:27 +00:00
|
|
|
_delay(ms);
|
2019-06-10 13:03:52 +00:00
|
|
|
_noTone(BEEPER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 13:05:18 +00:00
|
|
|
void Sound_MakeSound(eSOUND_TYPE eSoundType)
|
2018-07-23 18:04:47 +00:00
|
|
|
{
|
|
|
|
switch(eSoundMode)
|
|
|
|
{
|
|
|
|
case e_SOUND_MODE_LOUD:
|
|
|
|
if(eSoundType==e_SOUND_TYPE_ButtonEcho)
|
2019-07-04 16:43:59 +00:00
|
|
|
Sound_DoSound_Echo();
|
2018-07-23 18:04:47 +00:00
|
|
|
if(eSoundType==e_SOUND_TYPE_StandardPrompt)
|
|
|
|
Sound_DoSound_Prompt();
|
2018-11-02 22:03:14 +00:00
|
|
|
if(eSoundType==e_SOUND_TYPE_StandardAlert)
|
|
|
|
Sound_DoSound_Alert(false);
|
2018-07-23 18:04:47 +00:00
|
|
|
break;
|
|
|
|
case e_SOUND_MODE_ONCE:
|
|
|
|
if(eSoundType==e_SOUND_TYPE_ButtonEcho)
|
|
|
|
Sound_DoSound_Echo();
|
|
|
|
if(eSoundType==e_SOUND_TYPE_StandardPrompt)
|
|
|
|
Sound_DoSound_Prompt();
|
2018-11-02 22:03:14 +00:00
|
|
|
if(eSoundType==e_SOUND_TYPE_StandardAlert)
|
|
|
|
Sound_DoSound_Alert(true);
|
2018-07-23 18:04:47 +00:00
|
|
|
break;
|
|
|
|
case e_SOUND_MODE_SILENT:
|
2018-11-02 22:03:14 +00:00
|
|
|
if(eSoundType==e_SOUND_TYPE_StandardAlert)
|
|
|
|
Sound_DoSound_Alert(true);
|
2018-07-23 18:04:47 +00:00
|
|
|
break;
|
2019-06-10 13:03:52 +00:00
|
|
|
case e_SOUND_MODE_BLIND:
|
|
|
|
if(eSoundType==e_SOUND_TYPE_ButtonEcho)
|
|
|
|
Sound_DoSound_Echo();
|
|
|
|
if(eSoundType==e_SOUND_TYPE_StandardPrompt)
|
|
|
|
Sound_DoSound_Prompt();
|
|
|
|
if(eSoundType==e_SOUND_TYPE_StandardAlert)
|
|
|
|
Sound_DoSound_Alert(false);
|
|
|
|
if(eSoundType==e_SOUND_TYPE_EncoderMove)
|
|
|
|
Sound_DoSound_Encoder_Move();
|
|
|
|
if(eSoundType==e_SOUND_TYPE_BlindAlert)
|
|
|
|
Sound_DoSound_Blind_Alert();
|
2021-02-03 18:18:54 +00:00
|
|
|
break;
|
2018-07-23 18:04:47 +00:00
|
|
|
default:
|
2019-06-10 13:03:52 +00:00
|
|
|
break;
|
2018-07-23 18:04:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-10 13:03:52 +00:00
|
|
|
static void Sound_DoSound_Blind_Alert(void)
|
|
|
|
{
|
2019-10-30 19:11:19 +00:00
|
|
|
backlight_wake(1);
|
2019-08-03 13:37:11 +00:00
|
|
|
uint8_t nI;
|
|
|
|
|
2019-08-05 10:41:27 +00:00
|
|
|
for(nI=0; nI<20; nI++)
|
2019-08-03 13:37:11 +00:00
|
|
|
{
|
|
|
|
WRITE(BEEPER,HIGH);
|
|
|
|
delayMicroseconds(94);
|
|
|
|
WRITE(BEEPER,LOW);
|
|
|
|
delayMicroseconds(94);
|
|
|
|
}
|
2019-06-10 13:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void Sound_DoSound_Encoder_Move(void)
|
|
|
|
{
|
2019-10-30 19:11:19 +00:00
|
|
|
backlight_wake();
|
2019-06-10 13:03:52 +00:00
|
|
|
uint8_t nI;
|
|
|
|
|
|
|
|
for(nI=0;nI<5;nI++)
|
|
|
|
{
|
|
|
|
WRITE(BEEPER,HIGH);
|
2019-07-04 16:43:59 +00:00
|
|
|
delayMicroseconds(75);
|
2019-06-10 13:03:52 +00:00
|
|
|
WRITE(BEEPER,LOW);
|
2019-07-04 16:43:59 +00:00
|
|
|
delayMicroseconds(75);
|
2019-06-10 13:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-23 18:04:47 +00:00
|
|
|
|
|
|
|
static void Sound_DoSound_Echo(void)
|
|
|
|
{
|
2019-10-30 19:11:19 +00:00
|
|
|
backlight_wake();
|
2018-07-23 18:04:47 +00:00
|
|
|
uint8_t nI;
|
|
|
|
|
|
|
|
for(nI=0;nI<10;nI++)
|
|
|
|
{
|
|
|
|
WRITE(BEEPER,HIGH);
|
2019-07-04 16:43:59 +00:00
|
|
|
delayMicroseconds(100);
|
2018-07-23 18:04:47 +00:00
|
|
|
WRITE(BEEPER,LOW);
|
2019-07-04 16:43:59 +00:00
|
|
|
delayMicroseconds(100);
|
2018-07-23 18:04:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Sound_DoSound_Prompt(void)
|
|
|
|
{
|
2019-10-30 19:11:19 +00:00
|
|
|
backlight_wake(2);
|
2018-07-23 18:04:47 +00:00
|
|
|
WRITE(BEEPER,HIGH);
|
2019-07-17 10:32:27 +00:00
|
|
|
_delay_ms(500);
|
2018-07-23 18:04:47 +00:00
|
|
|
WRITE(BEEPER,LOW);
|
|
|
|
}
|
2018-11-02 22:03:14 +00:00
|
|
|
|
|
|
|
static void Sound_DoSound_Alert(bool bOnce)
|
|
|
|
{
|
2019-10-30 19:11:19 +00:00
|
|
|
backlight_wake();
|
2018-11-02 22:03:14 +00:00
|
|
|
uint8_t nI,nMax;
|
|
|
|
|
|
|
|
nMax=bOnce?1:3;
|
|
|
|
for(nI=0;nI<nMax;nI++)
|
|
|
|
{
|
|
|
|
WRITE(BEEPER,HIGH);
|
2019-07-04 16:43:59 +00:00
|
|
|
delayMicroseconds(200);
|
2018-11-02 22:03:14 +00:00
|
|
|
WRITE(BEEPER,LOW);
|
2019-07-04 16:43:59 +00:00
|
|
|
delayMicroseconds(500);
|
2018-11-02 22:03:14 +00:00
|
|
|
}
|
|
|
|
}
|