raspberry pi zeroにてBluetoothで接続したゲームパッドからボタン情報を取得するプログラムをCで作成しようとしたところ,以下のようなエラーが出ました.
error:"struct joystick_struct" has no member named 'nr_buttons';
nt_btn=js->nr_buttons;
サイトからべた打ちしたものであり,なにが原因でエラーが発生しているかがわかりません.どうしたらよいのでしょうか.以下に前後のソースコードも載せます.
struct joystick_struct {
int fd;
unsigned char nr_buttons;
unsigned char nr_sticks;
short button; / button[nr_buttons] */
short stick; / stick[nr_sticks] */
char input; / input[nr_btn * 2 + nr_stk * 7 + 1] */
};
static int joystick_output(struct joystick_struct *js, const char *out_file);
static int joystick_get_input(struct joystick_struct *js);
static int joystick_get_info(struct joystick_struct *js);
static int joystick_init(struct joystick_struct *js, const char *dev_file);
static void joystick_exit(struct joystick_struct *js);
static void joystick_main(const char *dev_file, const char *out_file);
static int joystick_output(struct joystick_struct *js, const char *out_file)
{
FILE *fp = stdout;
unsigned char i, nr_btn, nr_stk;
if (out_file != NULL) { fp = fopen(out_file, "w"); if (fp == NULL) { return ERROR("fopen(%s)\n", out_file); } } nr_btn = js->nr_buttons; nr_stk = js->nr_sticks; for (i = 0; i < nr_btn; i++) { sprintf(&js->input[i * 2], "%2d", js->button[i] ? 1 : 0); } for (i = 0; i < nr_stk; i++) { sprintf(&js->input[nr_btn * 2 + i * 7], "%7d", js->stick[i]); } js->input[nr_btn * 2 + nr_stk * 7] = '\0'; fprintf(fp, "%s\n", js->input); if (out_file != NULL) { fclose(fp); } return 0;
}
回答1件
あなたの回答
tips
プレビュー