kopia lustrzana https://github.com/SP8EBC/ParaTNC
buttons with programable function
rodzic
2a75bb6eb5
commit
115db54bdd
|
@ -11,7 +11,7 @@
|
|||
#ifndef BUTTON_H_
|
||||
#define BUTTON_H_
|
||||
|
||||
#include "config_data.h"
|
||||
#include "configuration_handler.h"
|
||||
|
||||
/**
|
||||
* Should be called from main for loop or in quite short interval, like
|
||||
|
@ -19,7 +19,7 @@
|
|||
* connected push buttons and then, depending on configuration, takes
|
||||
* an appropriate action.
|
||||
*/
|
||||
void button_check_all(config_data_basic_t * config);
|
||||
void button_check_all(configuration_button_function_t left, configuration_button_function_t right);
|
||||
|
||||
/**
|
||||
* Resets debouncing inhibiter which enables button key presses back
|
||||
|
|
|
@ -35,16 +35,6 @@ typedef enum config_data_powersave_mode_t {
|
|||
|
||||
}config_data_powersave_mode_t;
|
||||
|
||||
typedef enum config_data_button_function_t {
|
||||
|
||||
BUTTON_SEND_WX = 1,
|
||||
BUTTON_SEND_WX_INTERNET = 2,
|
||||
BUTTON_SEND_BEACON = 3,
|
||||
BUTTON_FORCE_UART_KISS = 4,
|
||||
BUTTON_FORCE_UART_LOG = 5,
|
||||
BUTTON_RESET_GSM_GPRS = 6
|
||||
}config_data_button_function_t;
|
||||
|
||||
typedef struct __attribute__((aligned (4))) config_data_mode_t {
|
||||
|
||||
#define WX_ENABLED (1)
|
||||
|
@ -179,9 +169,25 @@ typedef struct __attribute__((aligned (4))) config_data_basic_t {
|
|||
|
||||
uint16_t battery_scalling_b;
|
||||
|
||||
config_data_button_function_t button_one;
|
||||
/**
|
||||
* BUTTON_SEND_WX = 1,
|
||||
BUTTON_SEND_WX_INTERNET = 2,
|
||||
BUTTON_SEND_BEACON = 3,
|
||||
BUTTON_FORCE_UART_KISS = 4,
|
||||
BUTTON_FORCE_UART_LOG = 5,
|
||||
BUTTON_RESET_GSM_GPRS = 6
|
||||
*/
|
||||
#define BUTTON_FUNCTION_SEND_WX 1U
|
||||
#define BUTTON_FUNCTION_SEND_WX_INET 2U
|
||||
#define BUTTON_FUNCTION_SEND_BEACON 3U
|
||||
#define BUTTON_FUNCTION_UART_KISS 4U
|
||||
#define BUTTON_FUNCTION_UART_LOG 5U
|
||||
#define BUTTON_FUNCION_RESET_GSM_GPRS 6U
|
||||
|
||||
config_data_button_function_t button_two;
|
||||
|
||||
uint8_t button_one_left;
|
||||
|
||||
uint8_t button_two_right;
|
||||
|
||||
} config_data_basic_t;
|
||||
|
||||
|
|
|
@ -23,6 +23,17 @@ typedef enum configuration_erase_startup_t {
|
|||
ERASE_STARTUP_ERROR = 0xAD
|
||||
}configuration_erase_startup_t;
|
||||
|
||||
typedef enum configuration_button_function_t {
|
||||
|
||||
BUTTON_DISABLED = 0,
|
||||
BUTTON_SEND_WX = 1,
|
||||
BUTTON_SEND_WX_INTERNET = 2,
|
||||
BUTTON_SEND_BEACON = 3,
|
||||
BUTTON_FORCE_UART_KISS = 4,
|
||||
BUTTON_FORCE_UART_LOG = 5,
|
||||
BUTTON_RESET_GSM_GPRS = 6
|
||||
}configuration_button_function_t;
|
||||
|
||||
uint32_t configuration_handler_check_crc(void);
|
||||
uint32_t configuration_handler_restore_default_first(void);
|
||||
uint32_t configuration_handler_restore_default_second(void);
|
||||
|
@ -47,5 +58,8 @@ int configuration_get_power_cycle_gsmradio_on_no_communications(void);
|
|||
uint16_t configuration_get_vbat_a_coeff(void);
|
||||
uint16_t configuration_get_vbat_b_coeff(void);
|
||||
|
||||
configuration_button_function_t configuration_get_left_button(void);
|
||||
configuration_button_function_t configuration_get_right_button(void);
|
||||
|
||||
|
||||
#endif /* CONFIGURATION_HANDLER_H_ */
|
||||
|
|
|
@ -20,7 +20,7 @@ uint8_t button_left_previous_state = 1;
|
|||
uint8_t button_right_previous_state = 1;
|
||||
|
||||
|
||||
void button_check_all(config_data_basic_t * config) {
|
||||
void button_check_all(configuration_button_function_t left, configuration_button_function_t right) {
|
||||
|
||||
/**
|
||||
* Naming convention: There are two buttons on the PCB. Lets call it
|
||||
|
@ -35,28 +35,38 @@ void button_check_all(config_data_basic_t * config) {
|
|||
* when a button is not pressed. the button shorts this to ground.
|
||||
*/
|
||||
|
||||
// check if a configuration has been passed
|
||||
if (config != 0) {
|
||||
// current state of right button
|
||||
const uint32_t state_right = LL_GPIO_IsInputPinSet(GPIOC, LL_GPIO_PIN_3);
|
||||
// current state of right button
|
||||
const uint32_t state_right = LL_GPIO_IsInputPinSet(GPIOC, LL_GPIO_PIN_3);
|
||||
|
||||
// current state of left button
|
||||
const uint32_t state_left = LL_GPIO_IsInputPinSet(GPIOA, LL_GPIO_PIN_0);
|
||||
// current state of left button
|
||||
const uint32_t state_left = LL_GPIO_IsInputPinSet(GPIOA, LL_GPIO_PIN_0);
|
||||
|
||||
// check falling edge on right button
|
||||
if (state_right == 0 && button_right_previous_state == 1) {
|
||||
button_right_previous_state = 0;
|
||||
// check falling edge on right button
|
||||
if (state_left == 0 && button_left_previous_state == 1) {
|
||||
button_left_previous_state = 0;
|
||||
|
||||
switch (config->button_two) {
|
||||
case BUTTON_RESET_GSM_GPRS:
|
||||
gsm_sim800_reset(&main_gsm_state);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (left) {
|
||||
case BUTTON_RESET_GSM_GPRS:
|
||||
gsm_sim800_reset(&main_gsm_state);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// check falling edge on right button
|
||||
if (state_right == 0 && button_right_previous_state == 1) {
|
||||
button_right_previous_state = 0;
|
||||
|
||||
switch (right) {
|
||||
case BUTTON_RESET_GSM_GPRS:
|
||||
gsm_sim800_reset(&main_gsm_state);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void button_debounce(void) {
|
||||
|
|
|
@ -221,7 +221,17 @@ const config_data_basic_t __attribute__((section(".config_section_default.basic"
|
|||
.battery_scalling_a = VBAT_MEAS_A_COEFF,
|
||||
.battery_scalling_b = VBAT_MEAS_B_COEFF,
|
||||
|
||||
.button_one
|
||||
#ifdef _BUTTON_ONE_LEFT
|
||||
.button_one_left = _BUTTON_ONE_RIGHT,
|
||||
#else
|
||||
.button_one_left = 0,
|
||||
#endif
|
||||
|
||||
#ifdef _BUTTON_TWO_RIGHT
|
||||
.button_two_right = _BUTTON_TWO_RIGHT
|
||||
#else
|
||||
.button_two_right = 0
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -910,3 +910,34 @@ uint16_t configuration_get_vbat_b_coeff(void) {
|
|||
|
||||
return out;
|
||||
}
|
||||
|
||||
configuration_button_function_t configuration_get_left_button(void) {
|
||||
configuration_button_function_t out = BUTTON_DISABLED;
|
||||
|
||||
switch (main_config_data_basic->button_one_left) {
|
||||
case 1: out = BUTTON_SEND_WX; break;
|
||||
case 2: out = BUTTON_SEND_WX_INTERNET; break;
|
||||
case 3: out = BUTTON_SEND_BEACON; break;
|
||||
case 4: out = BUTTON_FORCE_UART_KISS; break;
|
||||
case 5: out = BUTTON_FORCE_UART_LOG; break;
|
||||
case 6: out = BUTTON_RESET_GSM_GPRS; break;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
configuration_button_function_t configuration_get_right_button(void) {
|
||||
configuration_button_function_t out = BUTTON_DISABLED;
|
||||
|
||||
switch (main_config_data_basic->button_two_right) {
|
||||
case 1: out = BUTTON_SEND_WX; break;
|
||||
case 2: out = BUTTON_SEND_WX_INTERNET; break;
|
||||
case 3: out = BUTTON_SEND_BEACON; break;
|
||||
case 4: out = BUTTON_FORCE_UART_KISS; break;
|
||||
case 5: out = BUTTON_FORCE_UART_LOG; break;
|
||||
case 6: out = BUTTON_RESET_GSM_GPRS; break;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
|
14
src/main.c
14
src/main.c
|
@ -210,6 +210,12 @@ main_usart_mode_t main_usart1_kiss_mode = USART_MODE_UNDEF;
|
|||
//! operation mode of USART2 (RS485)
|
||||
main_usart_mode_t main_usart2_wx_mode = USART_MODE_UNDEF;
|
||||
|
||||
//!
|
||||
configuration_button_function_t main_button_one_left;
|
||||
|
||||
//!
|
||||
configuration_button_function_t main_button_two_right;
|
||||
|
||||
//! a pointer to KISS context
|
||||
srl_context_t* main_kiss_srl_ctx_ptr;
|
||||
|
||||
|
@ -588,6 +594,12 @@ int main(int argc, char* argv[]){
|
|||
// initializing UART gpio pins
|
||||
io_uart_init();
|
||||
|
||||
// set function for left button
|
||||
main_button_one_left = configuration_get_left_button();
|
||||
|
||||
// set function for right button
|
||||
main_button_two_right = configuration_get_right_button();
|
||||
|
||||
#if defined(STM32F10X_MD_VL)
|
||||
// enabling the clock for both USARTs
|
||||
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
|
||||
|
@ -1324,7 +1336,7 @@ int main(int argc, char* argv[]){
|
|||
rtu_serial_pool();
|
||||
}
|
||||
|
||||
button_check_all(main_config_data_basic);
|
||||
button_check_all(main_button_one_left, main_button_two_right);
|
||||
|
||||
main_set_monitor(2);
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue