Skip to content

Commit

Permalink
made chime stable
Browse files Browse the repository at this point in the history
  • Loading branch information
venus@trg.ru committed Feb 28, 2020
1 parent e810e5f commit 79886e4
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ volatile int16_t count_20000; //2s
volatile __bit blinker_slowest;
#endif
#ifndef WITHOUT_CHIME
volatile int16_t chime_ticks; //100ms inc
volatile int16_t chime_ticks; //10ms inc
#endif

volatile uint16_t count_timeout; // max 6.5536 sec
Expand Down Expand Up @@ -148,7 +148,7 @@ uint8_t chime_ss_bcd; // hour since
uint8_t chime_uu_bcd; // hour until
__bit chime_ss_pm;
__bit chime_uu_pm;
__bit chime_trigger = 0;
volatile uint8_t chime_trigger = 0;
#endif
__bit cfg_changed = 1;
uint8_t snooze_time; //snooze(min)
Expand Down Expand Up @@ -218,6 +218,10 @@ void timer0_isr() __interrupt 1 __using 1
count_100 = 0;
count_1000++; //increment every 10ms

#ifndef WITHOUT_CHIME
if (chime_trigger)
chime_ticks ++; //increment every 10ms
#endif

// 10/sec: 100 ms
if (count_1000 == 10) {
Expand All @@ -228,10 +232,6 @@ void timer0_isr() __interrupt 1 __using 1
count_5000++; //increment every 100ms
#ifndef WITHOUT_ALARM
count_20000++; //increment every 100ms
#endif
#ifndef WITHOUT_CHIME
if (chime_trigger)
chime_ticks ++; //increment every 100ms
#endif
// 2/sec: 500 ms
if (count_5000 == 5) {
Expand Down Expand Up @@ -538,11 +538,9 @@ int main()
else if (uu != 0x12 && chime_uu_pm)
uu += 0x12;
}
if((ss <= uu && hh >= ss && hh <= uu) || (ss > uu && (hh >= ss || hh <= uu))) {
chime_ticks = 0;
if((ss <= uu && hh >= ss && hh <= uu) || (ss > uu && (hh >= ss || hh <= uu)))
chime_trigger = 1;
}
}
#endif

#ifndef WITHOUT_ALARM
Expand Down Expand Up @@ -1045,23 +1043,24 @@ int main()
BUZZER_OFF;
}
} else {
#ifndef WITHOUT_CHIME
if (!chime_trigger)
#endif
BUZZER_OFF;
}
#endif

#ifndef WITHOUT_CHIME
if (chime_trigger)
//if(chime_ticks == 0 || chime_ticks == 2)
if (chime_ticks == 0)
switch (chime_trigger) {
case 1: // ~100ms chime
BUZZER_ON;
//else if(chime_ticks == 1 || chime_ticks == 3)
else if (chime_ticks == 1 || chime_ticks == 2) // 2 times off - just in case
for (chime_ticks = 0; chime_ticks < 10; );
BUZZER_OFF;
else if (chime_ticks > 100) // disable after >1sec.
chime_trigger = 0;
chime_trigger = 2;
case 2: // wait > 1sec until rtc sec changed
if (chime_ticks > 150)
chime_trigger = 0; // stop chime
break;
default:
break;
}
#endif

__critical {
Expand Down

0 comments on commit 79886e4

Please sign in to comment.