button press and character input reset sleep timeout
This commit is contained in:
parent
755b0a37b3
commit
a05fa023e5
29
main.c
29
main.c
|
@ -15,7 +15,7 @@
|
||||||
/** CuVoodoo clapperboard firmware (for STM32F103Cx micro-controller)
|
/** CuVoodoo clapperboard firmware (for STM32F103Cx micro-controller)
|
||||||
* @file main.c
|
* @file main.c
|
||||||
* @author King Kévin <kingkevin@cuvoodoo.info>
|
* @author King Kévin <kingkevin@cuvoodoo.info>
|
||||||
* @date 2016-2017
|
* @date 2016-2018
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* standard libraries */
|
/* standard libraries */
|
||||||
|
@ -593,7 +593,12 @@ void main(void)
|
||||||
timer_enable_oc_output(TIM(BUZZER_TIMER), TIM_OC1); // enable output to generate PWM
|
timer_enable_oc_output(TIM(BUZZER_TIMER), TIM_OC1); // enable output to generate PWM
|
||||||
timer_enable_oc_output(TIM(BUZZER_TIMER), TIM_OC1N); // enable output to generate PWM (complementary to be louder)
|
timer_enable_oc_output(TIM(BUZZER_TIMER), TIM_OC1N); // enable output to generate PWM (complementary to be louder)
|
||||||
timer_enable_break_main_output(TIM(BUZZER_TIMER)); // enable master output
|
timer_enable_break_main_output(TIM(BUZZER_TIMER)); // enable master output
|
||||||
timer_generate_event(TIM(BUZZER_TIMER), TIM_EGR_UG); // generate update event to reload registers and reset counter
|
timer_generate_event(TIM(BUZZER_TIMER), TIM_EGR_UG); // generate update event to reload registers and reset counter
|
||||||
|
// switch buzzer off by removing the output from the PWM
|
||||||
|
gpio_clear(GPIO(BUZZER_1_PORT), GPIO(BUZZER_1_PIN));
|
||||||
|
gpio_set_mode(GPIO(BUZZER_1_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUZZER_1_PIN));
|
||||||
|
gpio_clear(GPIO(BUZZER_2_PORT), GPIO(BUZZER_2_PIN));
|
||||||
|
gpio_set_mode(GPIO(BUZZER_2_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUZZER_2_PIN));
|
||||||
printf("OK\n");
|
printf("OK\n");
|
||||||
|
|
||||||
// setup GPIO for reading buttons
|
// setup GPIO for reading buttons
|
||||||
|
@ -628,12 +633,14 @@ void main(void)
|
||||||
action = true; // action has been performed
|
action = true; // action has been performed
|
||||||
led_toggle(); // toggle LED to show activity
|
led_toggle(); // toggle LED to show activity
|
||||||
c = usart_getchar(); // store receive character
|
c = usart_getchar(); // store receive character
|
||||||
|
standby_timer = 0; // restart standby timer
|
||||||
char_flag = true; // notify character has been received
|
char_flag = true; // notify character has been received
|
||||||
}
|
}
|
||||||
while (cdcacm_received) { // data received over USB
|
while (cdcacm_received) { // data received over USB
|
||||||
action = true; // action has been performed
|
action = true; // action has been performed
|
||||||
led_toggle(); // toggle LED to show activity
|
led_toggle(); // toggle LED to show activity
|
||||||
c = cdcacm_getchar(); // store receive character
|
c = cdcacm_getchar(); // store receive character
|
||||||
|
standby_timer = 0; // restart standby timer
|
||||||
char_flag = true; // notify character has been received
|
char_flag = true; // notify character has been received
|
||||||
}
|
}
|
||||||
while (char_flag) { // user data received
|
while (char_flag) { // user data received
|
||||||
|
@ -684,7 +691,15 @@ void main(void)
|
||||||
if (morse[morse_i]) { // skip empty codes
|
if (morse[morse_i]) { // skip empty codes
|
||||||
if (morse_i%2) { // switch buzzer on for odd code
|
if (morse_i%2) { // switch buzzer on for odd code
|
||||||
timer_disable_counter(TIM(BUZZER_TIMER)); // stop buzzing
|
timer_disable_counter(TIM(BUZZER_TIMER)); // stop buzzing
|
||||||
|
// switch buzzer off by removing the output from the PWM
|
||||||
|
gpio_clear(GPIO(BUZZER_1_PORT), GPIO(BUZZER_1_PIN));
|
||||||
|
gpio_set_mode(GPIO(BUZZER_1_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUZZER_1_PIN));
|
||||||
|
gpio_clear(GPIO(BUZZER_2_PORT), GPIO(BUZZER_2_PIN));
|
||||||
|
gpio_set_mode(GPIO(BUZZER_2_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUZZER_2_PIN));
|
||||||
} else {
|
} else {
|
||||||
|
// allow PWM to control the output
|
||||||
|
gpio_set_mode(GPIO(BUZZER_1_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO(BUZZER_1_PIN));
|
||||||
|
gpio_set_mode(GPIO(BUZZER_2_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO(BUZZER_2_PIN));
|
||||||
timer_enable_counter(TIM(BUZZER_TIMER)); // start buzzing
|
timer_enable_counter(TIM(BUZZER_TIMER)); // start buzzing
|
||||||
}
|
}
|
||||||
morse[morse_i]--; // decrement remaining buzzing time
|
morse[morse_i]--; // decrement remaining buzzing time
|
||||||
|
@ -695,8 +710,11 @@ void main(void)
|
||||||
}
|
}
|
||||||
if (morse_i>=LENGTH(morse)) { // all codes done
|
if (morse_i>=LENGTH(morse)) { // all codes done
|
||||||
morse_delay = -2; // Morse completed
|
morse_delay = -2; // Morse completed
|
||||||
gpio_clear(GPIO(BUZZER_1_PORT), GPIO(BUZZER_1_PIN)); // ensure it's not beeping
|
// switch buzzer off by removing the output from the PWM
|
||||||
gpio_clear(GPIO(BUZZER_2_PORT), GPIO(BUZZER_2_PIN)); // ensure it's not beeping
|
gpio_clear(GPIO(BUZZER_1_PORT), GPIO(BUZZER_1_PIN));
|
||||||
|
gpio_set_mode(GPIO(BUZZER_1_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUZZER_1_PIN));
|
||||||
|
gpio_clear(GPIO(BUZZER_2_PORT), GPIO(BUZZER_2_PIN));
|
||||||
|
gpio_set_mode(GPIO(BUZZER_2_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUZZER_2_PIN));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -741,7 +759,7 @@ void main(void)
|
||||||
uint16_t buttons_diff = buttons^buttons_new; // get difference
|
uint16_t buttons_diff = buttons^buttons_new; // get difference
|
||||||
buttons = buttons_new; // save new state
|
buttons = buttons_new; // save new state
|
||||||
if (buttons_diff) { // only do something if there is a change
|
if (buttons_diff) { // only do something if there is a change
|
||||||
//printf("button pressed: %016b\n", buttons);
|
printf("button pressed: %016b\n", buttons);
|
||||||
for (uint8_t number=0; number<LENGTH(numbers); number++) { // check buttons for every number
|
for (uint8_t number=0; number<LENGTH(numbers); number++) { // check buttons for every number
|
||||||
if (buttons_diff&(1<<numbers[number].up) || buttons_diff&(1<<numbers[number].down)) { // a button for the number has been pressed
|
if (buttons_diff&(1<<numbers[number].up) || buttons_diff&(1<<numbers[number].down)) { // a button for the number has been pressed
|
||||||
if (buttons&(1<<numbers[number].up) && buttons&(1<<numbers[number].down)) { // both buttons are pressed
|
if (buttons&(1<<numbers[number].up) && buttons&(1<<numbers[number].down)) { // both buttons are pressed
|
||||||
|
@ -823,6 +841,7 @@ void main(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
standby_timer = 0; // restart standby timer
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue