passing variable and bit place to 3 Struct arrays and return the corresponding bit
Budget: $30 – $250 NZD
In MPLAB IDE for Microchip PIC there are 3 Structs with an named array of uint32 numbers that represent various single bit configuration item that are configured by another piece of code. The varible passed to the function needs to be the uint32_t number in the struct that the bit is returned from
#include <stdio.h>
typedef struct{
uint32_t SMALL_BUTTON;
uint32_t REMOTE_SET;
uint32_t BIG_BUTTON;
uint32_t REMOTE_RESET;
uint32_t SMOKE;
uint32_t SOCKET;
uint32_t RX_MINI_1;
uint32_t RX_MINI_2;
uint32_t MAIN_FAIL;
}settings_single;
typedef struct{
uint32_t SMALL_BUTTON;
uint32_t REMOTE_SET;
uint32_t BIG_BUTTON;
uint32_t REMOTE_RESET;
uint32_t SMOKE;
uint32_t SOCKET;
uint32_t RX_MINI_1;
uint32_t RX_MINI_2;
}settings_hold;
typedef struct{
uint32_t SMALL_BUTTON;
uint32_t REMOTE_SET;
uint32_t BIG_BUTTON;
uint32_t REMOTE_RESET;
uint32_t SMOKE;
uint32_t SOCKET;
uint32_t RX_MINI_1;
uint32_t RX_MINI_2;
}settings_x3;
extern volatile settings_single theSettingsSingle;
extern volatile settings_hold theSettingsHold;
extern volatile settings_x3 theSettingsX3;
typedef enum {
SMALL_BUTTON,REMOTE_SET,BIG_BUTTON,REMOTE_RESET,SMOKE,SOCKET,RX_MINI_1,RX_MINI_2
}inputs_t;
void ButtonDo(uint8_t button,uint8_t type,uint8_t function) {
uint8_t result;
switch(type){
case 1:
result =theSettingsSingle.button & ((1U) << function));
break;
case 2:
result =theSettingshold.button & ((1U) << function));
break;
case 3:
result =theSettingsx3.button & ((1U) << function));
break;
printf("result %x\r\n", result);
}
void main(void) {
ButtonDo(REMOTE_SET ,3,14);
}
#include <stdio.h>
typedef struct{
uint32_t SMALL_BUTTON;
uint32_t REMOTE_SET;
uint32_t BIG_BUTTON;
uint32_t REMOTE_RESET;
uint32_t SMOKE;
uint32_t SOCKET;
uint32_t RX_MINI_1;
uint32_t RX_MINI_2;
uint32_t MAIN_FAIL;
}settings_single;
typedef struct{
uint32_t SMALL_BUTTON;
uint32_t REMOTE_SET;
uint32_t BIG_BUTTON;
uint32_t REMOTE_RESET;
uint32_t SMOKE;
uint32_t SOCKET;
uint32_t RX_MINI_1;
uint32_t RX_MINI_2;
}settings_hold;
typedef struct{
uint32_t SMALL_BUTTON;
uint32_t REMOTE_SET;
uint32_t BIG_BUTTON;
uint32_t REMOTE_RESET;
uint32_t SMOKE;
uint32_t SOCKET;
uint32_t RX_MINI_1;
uint32_t RX_MINI_2;
}settings_x3;
extern volatile settings_single theSettingsSingle;
extern volatile settings_hold theSettingsHold;
extern volatile settings_x3 theSettingsX3;
typedef enum {
SMALL_BUTTON,REMOTE_SET,BIG_BUTTON,REMOTE_RESET,SMOKE,SOCKET,RX_MINI_1,RX_MINI_2
}inputs_t;
void ButtonDo(uint8_t button,uint8_t type,uint8_t function) {
uint8_t result;
switch(type){
case 1:
result =theSettingsSingle.button & ((1U) << function));
break;
case 2:
result =theSettingshold.button & ((1U) << function));
break;
case 3:
result =theSettingsx3.button & ((1U) << function));
break;
printf("result %x\r\n", result);
}
void main(void) {
ButtonDo(REMOTE_SET ,3,14);
}