format buzzer
-#include "project.h"
+#include "buzzer.h"
#include "defines.h"
#include "drv_time.h"
-#include "buzzer.h"
-
+#include "project.h"
#ifdef BUZZER_ENABLE
//#define PIN_OFF( port , pin ) GPIO_ResetBits( port , pin) //moved to defines.h
//#define PIN_ON( port , pin ) GPIO_SetBits( port , pin) //moved to defines.h
-
-int gpio_init_buzzer(void)
-{
-
+int gpio_init_buzzer(void) {
// set gpio pin as output
GPIO_InitTypeDef GPIO_InitStructure;
@@ -28,9 +24,7 @@ int gpio_init_buzzer(void)
return 1;
}
-
-void buzzer()
-{
+void buzzer() {
extern int failsafe;
extern int lowbatt;
extern int rxmode;
@@ -47,13 +41,11 @@ void buzzer()
// there is time to program the chip (if using SWDAT or SWCLK)
extern char aux[];
- if ( lowbatt || failsafe || aux[BUZZER_ENABLE] )
- {
+ if (lowbatt || failsafe || aux[BUZZER_ENABLE]) {
unsigned long time = gettime();
if (buzzertime == 0)
buzzertime = time;
- else
- {
+ else {
// rank lowbatt > failsafe > throttle
if (lowbatt)
@@ -64,52 +56,37 @@ void buzzer()
pulse_rate = 600000; // 3/5ths second
// start the buzzer if timeout has elapsed
- if ( time - buzzertime > BUZZER_DELAY || lowbatt || aux[BUZZER_ENABLE])
- {
+ if (time - buzzertime > BUZZER_DELAY || lowbatt || aux[BUZZER_ENABLE]) {
// initialize pin only after minimum 10 seconds from powerup
- if ( !buzzer_init && time > 10e6)
- {
+ if (!buzzer_init && time > 10e6) {
buzzer_init = gpio_init_buzzer();
}
// don't continue if buzzer not initialized
- if ( !buzzer_init ) return;
-
+ if (!buzzer_init)
+ return;
// enable buzzer
- if (time%pulse_rate>pulse_rate/2)
- {
+ if (time % pulse_rate > pulse_rate / 2) {
if (toggle) // cycle the buzzer
{
PIN_ON(BUZZER_PIN_PORT, BUZZER_PIN); // on
- }
- else
- {
+ } else {
PIN_OFF(BUZZER_PIN_PORT, BUZZER_PIN); // off
}
toggle = !toggle;
- }
- else
- {
+ } else {
PIN_OFF(BUZZER_PIN_PORT, BUZZER_PIN);
}
}
-
}
- }
- else
- {
+ } else {
buzzertime = 0;
// set buzzer to off if beeping condition stopped
- if (buzzer_init) PIN_OFF(BUZZER_PIN_PORT, BUZZER_PIN );
-
+ if (buzzer_init)
+ PIN_OFF(BUZZER_PIN_PORT, BUZZER_PIN);
}
-
}
#endif
-
-
-
-
