good day to you all.
I am trying to make my own joystick, so I have been looking for references and then I found usbjoy project from v-usb wiki page (http://vusb.wikidot.com/project:usbjoy).
Then, I found data structure for buttons, taken from common.h in zip file from the website.
typedef struct
{
uchar x; //Byte-0, οΎ (0...255)
uchar y; //Byte-1, Y (0...255)
uchar z; //Byte-2, Handle-1 (0...255)
uchar p; //Byte-3, Handle-2 (0...255)
union {
uchar buttons; //Byte-4, buttons 8
struct
{
uchar btn1: 1; //0, 1
uchar btn2: 1; //0, 1
uchar btn3: 1; //0, 1
uchar btn4: 1; //0, 1
uchar btn5: 1; //0, 1
uchar btn6: 1; //0, 1
uchar btn7: 1; //0, 1
uchar btn8: 1; //0, 1
} b;
} u;
union {
uchar but; //Byte-5, buttons 4
struct
{
uchar btn9: 1; //0, 1
uchar btn10: 1; //0, 1
uchar btn11: 1; //0, 1
uchar btn12: 1; //0, 1
uchar padding: 4; //Not use
} b;
} w;
} t_PsxController;
I understand that x and y are for left analog pad, z and p are for right analog pad, and u and w are for buttons. My questions are:
- Why are u and w declared as unions?
- Will the struct inside the unions ever be used?
- What is the size of t_PsxController?
- And finally, what do colons in
uchar btn1: 1;
and codes below it mean?