123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /*
- * buzzer.c
- *
- * Created on: Jan 12, 2021
- * Author: David Original work by Jose (PTDreamer), 2017
- */
- #include "buzzer.h"
- #include "iron.h"
- #include "settings.h"
- #include "main.h"
- typedef enum {STATE_SB, STATE_LB, STATE_FB, STATE_AL_H,STATE_AL_L, STATE_IDLE} buzzer_state_type;
- static buzzer_state_type buzzer_state = STATE_IDLE;
- static uint32_t last_time;
- static void tempReachedCall(uint16_t temp) {
- buzzer_short_beep();
- }
- static setTemperatureReachedCallback ironTempReachedCallback = &tempReachedCall;
- void buzzer_init() {
- addSetTemperatureReachedCallback(ironTempReachedCallback);
- }
- void buzzer_short_beep() {
- buzzer_state = STATE_SB;
- if(systemSettings.settings.buzzerMode){
- BUZZER_ON;
- }
- last_time = HAL_GetTick();
- }
- void buzzer_long_beep() {
- buzzer_state = STATE_LB;
- if(systemSettings.settings.buzzerMode){
- BUZZER_ON;
- }
- last_time = HAL_GetTick();
- }
- void buzzer_fatal_beep() {
- buzzer_state = STATE_FB;
- if(systemSettings.settings.buzzerMode){
- BUZZER_ON;
- }
- last_time = HAL_GetTick();
- }
- void buzzer_alarm_start(){
- if(!systemSettings.settings.buzzerMode){ return; }
- buzzer_state = STATE_AL_H;
- if(systemSettings.settings.buzzerMode){
- BUZZER_ON;
- }
- last_time = HAL_GetTick();
- }
- void buzzer_alarm_stop() {
- buzzer_state = STATE_IDLE;
- BUZZER_OFF;
- }
- void handle_buzzer() {
- uint32_t delta = HAL_GetTick() - last_time;
- switch (buzzer_state) {
- case STATE_SB:
- if (delta > SHORT_BEEP) {
- BUZZER_OFF;
- buzzer_state = STATE_IDLE;
- }
- break;
- case STATE_LB:
- if (delta > LONG_BEEP) {
- BUZZER_OFF;
- buzzer_state = STATE_IDLE;
- }
- break;
- case STATE_FB:
- if (delta > FATAL_BEEP) {
- BUZZER_OFF;
- buzzer_state = STATE_IDLE;
- }
- break;
- case STATE_AL_H:
- if(delta > ALARM_HIGH){
- buzzer_state=STATE_AL_L;
- BUZZER_OFF;
- last_time = HAL_GetTick();
- }
- break;
- case STATE_AL_L:
- if(delta > ALARM_LOW){
- buzzer_state=STATE_AL_H;
- if(systemSettings.settings.buzzerMode){
- BUZZER_ON;
- }
- last_time = HAL_GetTick();
- }
- break;
- case STATE_IDLE:
- break;
- default:
- BUZZER_OFF;
- buzzer_state = STATE_IDLE;
- break;
- }
- }
|