From 1360c0e3f74d82d722d9c3c780096d1238e5f4a6 Mon Sep 17 00:00:00 2001 From: Chris Veigl Date: Sun, 9 May 2021 16:47:42 +0200 Subject: [PATCH] fixed array copy bug when copying input button map --- FabiWare/buttons.cpp | 14 +++++++++----- FabiWare/buttons.h | 4 ++++ FabiWare/fabi.h | 4 +--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/FabiWare/buttons.cpp b/FabiWare/buttons.cpp index 19a6566..d5066d8 100644 --- a/FabiWare/buttons.cpp +++ b/FabiWare/buttons.cpp @@ -16,13 +16,14 @@ #include "keys.h" #include "buttons.h" -int8_t input_map[NUMBER_OF_PHYSICAL_BUTTONS] = {2, 3, 4, 5, 6, 7, 8, 9, 10}; -int8_t input_map_PCB[NUMBER_OF_PHYSICAL_BUTTONS] = {10, 16, 19, 5, 6, 7, 8, 9}; +int8_t input_map[NUMBER_OF_PHYSICAL_BUTTONS_NOPCB] = {2, 3, 4, 5, 6, 7, 8, 9, 10}; +int8_t input_map_PCB[NUMBER_OF_PHYSICAL_BUTTONS_PCB] = {10, 16, 19, 5, 6, 7, 8, 9}; struct buttonType buttons [NUMBER_OF_BUTTONS]; // array for all buttons - type definition see fabi.h struct buttonDebouncerType buttonDebouncers [NUMBER_OF_BUTTONS]; // array for all buttonsDebouncers - type definition see fabi.h char keystringBuffer[KEYSTRING_BUFFER_LEN]; // buffer for all string parameters for the buttons of a slot +uint8_t NUMBER_OF_PHYSICAL_BUTTONS; uint16_t buttonStates = 0; uint16_t pressure = 0; uint8_t reportRawValues = 0; @@ -37,10 +38,13 @@ uint8_t valueReportCount = 0; initialise button pins and default modes */ void initButtons() { - + // update pin mapping for PCB version - if (PCBversion) - memcpy(input_map, input_map_PCB, NUMBER_OF_PHYSICAL_BUTTONS - 1); + if (PCBversion) { + NUMBER_OF_PHYSICAL_BUTTONS = NUMBER_OF_PHYSICAL_BUTTONS_PCB; + memcpy(input_map, input_map_PCB, NUMBER_OF_PHYSICAL_BUTTONS); + } + else NUMBER_OF_PHYSICAL_BUTTONS = NUMBER_OF_PHYSICAL_BUTTONS_NOPCB; for (int i = 0; i < NUMBER_OF_PHYSICAL_BUTTONS; i++) // initialize physical buttons and bouncers pinMode (input_map[i], INPUT_PULLUP); // configure the pins for input mode with pullup resistors diff --git a/FabiWare/buttons.h b/FabiWare/buttons.h index 7e08e44..9eab3da 100644 --- a/FabiWare/buttons.h +++ b/FabiWare/buttons.h @@ -16,6 +16,10 @@ #ifndef _BUTTONS_H_ #define _BUTTONS_H_ +#define NUMBER_OF_PHYSICAL_BUTTONS_NOPCB 9 // number of connectable switches for no-PCB version +#define NUMBER_OF_PHYSICAL_BUTTONS_PCB 8 // number of connectable switches for PCB version +#define NUMBER_OF_LEDS 3 // number of connectable leds (no-PCB verion) + #define SIP_BUTTON 9 #define PUFF_BUTTON 10 #define PRESSURE_SENSOR_PIN A0 diff --git a/FabiWare/fabi.h b/FabiWare/fabi.h index 75e3fae..3be3404 100644 --- a/FabiWare/fabi.h +++ b/FabiWare/fabi.h @@ -36,9 +36,7 @@ #include #include -#define NUMBER_OF_BUTTONS 11 // number of connected or virtual switches, note: if more than 16, change buttonState type to uint32_t! -#define NUMBER_OF_PHYSICAL_BUTTONS 9 // number of connected switches -#define NUMBER_OF_LEDS 3 // number of connected leds +#define NUMBER_OF_BUTTONS 11 // number of pyhsical plus virtual switches, note: if more than 16, change buttonState type to uint32_t! #define MAX_SLOTNAME_LEN 10 // maximum lenght for a slotname #define KEYSTRING_BUFFER_LEN 400 // maximum lenght for all string parameters of a slot