From b55b5224c4db7a020532c56fb4e8480a91deee52 Mon Sep 17 00:00:00 2001 From: qba667 Date: Wed, 22 Nov 2017 21:48:22 +0100 Subject: [PATCH] Alarms improved. --- source/MKL16Z64xxx4_flash.ld | 3 +- source/source/alt.c | 95 +++++++++++++++++------------------- source/source/alt.h | 5 +- 3 files changed, 48 insertions(+), 55 deletions(-) diff --git a/source/MKL16Z64xxx4_flash.ld b/source/MKL16Z64xxx4_flash.ld index 7bf2481..5cf1a4f 100644 --- a/source/MKL16Z64xxx4_flash.ld +++ b/source/MKL16Z64xxx4_flash.ld @@ -251,7 +251,8 @@ SECTIONS .mod_MOD_ALARMS 0xE140 : { - *(.mod_customAlarms); + *(.mod_customAlarmsCheck); + *(.mod_customAlarmsPlay); } /*Free space until 0xE400*/ diff --git a/source/source/alt.c b/source/source/alt.c index 73e7e77..c41c403 100644 --- a/source/source/alt.c +++ b/source/source/alt.c @@ -411,63 +411,56 @@ void BatteryType() { saveModSettings(); } } +void play(int freq, int duration, int pause){ + if(someBeepCheck() >= 2){ + beep(freq,duration); + if(pause > 0) beep(0,pause); + } +} - void ChackCustomAlarms(){ - int32_t timer = ((*(int32_t *)(TIMER_SYS_TIM))); - int32_t lastAlarm = *((int32_t *)LAST_ALARM_TIMER); - int32_t lastTelemetryUpdate = *((int32_t *)TELEMETRY_UPDATE_TIMER); - uint8_t beepCount = 0; - uint8_t sensorID = 0; - - if(timer < 100 ) return; +#define BEEP_DEFAULT_FREQ (900) - if((uint32_t)modConfig.timerAlarm != 0 && timerValue > (uint32_t)modConfig.timerAlarm) { - beepCount = 1; - } - if(timer - lastTelemetryUpdate < 1000){ - for(int i = 0; i < 3; i++){ - sensorID = modConfig.alarm[i].sensorID; - if(sensorID == 0xff) continue; - int32_t sensorValue = getSensorValue(sensorID, 0, 0); - if(sensorID >= IBUS_MEAS_TYPE_GPS_LAT && sensorID <= IBUS_MEAS_TYPE_S8a && sensorValue < SENSORS_ARRAY_LENGTH){ - sensorValue = longSensors[sensorValue]; - } - if(modConfig.alarm[i].operator == OPERATOR_GT){ - if(sensorValue > modConfig.alarm[i].value){ - beepCount = i+2; - break; + void ChackCustomAlarms(){ + int32_t timer = ((*(int32_t *)(TIMER_SYS_TIM))); + int32_t lastAlarm = *((int32_t *)LAST_ALARM_TIMER); + int32_t lastTelemetryUpdate = *((int32_t *)TELEMETRY_UPDATE_TIMER); + uint8_t sensorID = 0; + uint8_t active = 0; + uint32_t defFreq = 100; + if(timer < 100 ) return; + if(timer - lastAlarm >= 500){ + if((uint32_t)modConfig.timerAlarm != 0 && timerValue > (uint32_t)modConfig.timerAlarm) { + *((int32_t *)LAST_ALARM_TIMER) = timer; + play(BEEP_DEFAULT_FREQ, 100, 50); + } + if(timer - lastTelemetryUpdate < 1000){ + for(int i = 0; i < 3; i++){ + active = 0; + sensorID = modConfig.alarm[i].sensorID; + if(sensorID == IBUS_MEAS_TYPE_UNKNOWN) continue; + int32_t sensorValue = getSensorValue(sensorID, 0, 0); + if(sensorID >= IBUS_MEAS_TYPE_GPS_LAT && sensorID <= IBUS_MEAS_TYPE_S8a && sensorValue < SENSORS_ARRAY_LENGTH){ + sensorValue = longSensors[sensorValue]; } - } - if(modConfig.alarm[i].operator == OPERATOR_LT){ - if(sensorValue < modConfig.alarm[i].value){ - beepCount = i+2; - break; + if(modConfig.alarm[i].operator == OPERATOR_GT){ + if(sensorValue > modConfig.alarm[i].value){ + active = 1; + } + } + if(modConfig.alarm[i].operator == OPERATOR_LT){ + if(sensorValue < modConfig.alarm[i].value){ + active = 1; + } + } + if(active){ + *((int32_t *)LAST_ALARM_TIMER) = timer; + play(BEEP_DEFAULT_FREQ + ((i+1)* defFreq), 100, 40); } } - - //modConfig.alarms[i].operator = modConfig.alarm[i].operator; - //modConfig.alarms[i].sensorID = modConfig.alarm[i].sensorID; - //modConfig.alarms[i].value = modConfig.alarm[i].value; - } - } - - if(beepCount > 0 && ((timer - lastAlarm) >= 2000)){ - *((int32_t *)LAST_ALARM_TIMER) = timer; - while(beepCount > 0){ - beepCount --; - if(someBeepCheck() >= 2){ - beep(700,100); - beep(0,100); - }} - //if(someBeepCheck >= 2){ - // beep(1000, 350); - // beep(500, 350); - //} - } - - - CheckAlarmsCall(); + } + } + CheckAlarmsCall(); } void SwBConfig() { diff --git a/source/source/alt.h b/source/source/alt.h index 33c302e..441df5a 100644 --- a/source/source/alt.h +++ b/source/source/alt.h @@ -106,9 +106,8 @@ __attribute__((section (".mod_parseAC"))) void acData(uint8_t* rxBuffer); __attribute__((section (".mod_createPacketCh1114"))) void createPacketCh1114(); __attribute__((section (".mod_SW_B_config"))) void SwBConfig(); __attribute__((section (".mod_alarmConfig"))) void AlarmConfig(); - __attribute__((section (".mod_customAlarms"))) void ChackCustomAlarms(); - - + __attribute__((section (".mod_customAlarmsCheck"))) void ChackCustomAlarms(); + __attribute__((section (".mod_customAlarmsPlay"))) void play(int freq, int duration, int pause); __attribute__((section (".mod_swEHandling"))) void swEHandling(); __attribute__((section (".mod_swBHandling"))) void swBasADC(); __attribute__((section (".mod_loadModEeprom"))) void loadModSettings();