I have these structs
typedef struct DeviceState_s {
uint32_t Function_Type;
uint8_t Left_Trigger;//byte [1]#9 left analog trigger
uint8_t Right_Trigger;//byte [2]#10 right analog trigger
uint8_t Buttons_1;//byte [3]#11 1----XY(1/Z) ..X and Y are the bits representing the buttons state (1 for unpress 0 for press) the last bit is z if the controller supports it.
uint8_t Buttons_2;//byte [4]#12 PR PL PD PU start A B (1/C) PR=pad right same for the rest and the bit marked as one is c if the controller supports it.
uint8_t Analog_a1;//byte [5]#13 useless in original controller
uint8_t Analog_a2;//byte [6]#14 useless in original controller
uint8_t Analog_Y;//byte [7]#15 joystick Y axis movement
uint8_t Analog_X;//byte [8]#16 joystick X axis movement
} DeviceState;
typedef struct DeviceStatus_s {
uint32_t Function;
uint32_t DeviceID[3];
uint8_t AreaCode; //1
uint8_t ConnectorDirection; //1
char ProductName[30];
char ProductLicense[60];
uint16_t StandbyPower; //2
uint16_t MaxPower; //2
} DeviceStatus;
typedef struct Status_FPacket_s {
PacketHeader Header; //4
DeviceStatus Status //112
} Status_FPacket;
static Status_FPacket Status_Packet;
then I pulsate them later on. But There is no need to populate the Status each time, it's always the same. I thought maybe one was like so.
typedef struct Status_FPacket_s {
PacketHeader Header; //4
DeviceStatus Status //112
= {
.Function = FUNC_CONTROLLER,
.DeviceID[0] = 0xffff06fe,
.DeviceID[1] = 0x0000ffff,
.DeviceID[2] = 0x00000000,
.AreaCode = 0xff,
.ConnectorDirection = 0,
.ProductName =0,
.ProductLicense =0,
.StandbyPower = (430>>8) | (430<<8),
.MaxPower = (500>>8) | (500<<8),
};
} Status_FPacket;
but that didn't work. Maybe I need to use my own type?
///////////adding AbeMonk's suggestion////////
typedef struct DeviceStatus_s {
uint32_t Function;
uint32_t DeviceID[3];
uint8_t AreaCode; //1
uint8_t ConnectorDirection; //1
char ProductName[30];
char ProductLicense[60];
uint16_t StandbyPower; //2
uint16_t MaxPower; //2
} DeviceStatus;
static DeviceStatus controllerStatus =
{
.Function=FUNC_CONTROLLER,
.DeviceID[0]= 0xffff06fe,
.DeviceID[1]= 0x0000ffff,
.DeviceID[2] = 0x00000000,
.AreaCode = 0xff,
.ConnectorDirection = 0,
.ProductName = "....";
.ProductLicense "....";
.StandbyPower = (430>>8) | (430<<8),
.MaxPower = (500>>8) | (500<<8),
};
then just do this later
Status_Packet.Status = controllerStatus;
the things I use to set my strings are
strncpy(Status_Packet.Status.ProductName, "text here", sizeof(Status_Packet.Status.ProductName));
not sure how to do this without strncpy.