Z-Pocket Game Pro(ZPG Pro)

read joystick


main.c

#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
 
int main(int argc, char **argv)
{
  SDL_Event e;
  SDL_Joystick *joy=NULL;
   
  SDL_Init(SDL_INIT_JOYSTICK);
  joy = SDL_JoystickOpen(0);
 
  int stop=0;
  while(stop == 0) {
    if(SDL_PollEvent(&e)){
      switch(e.type){
      case SDL_JOYBUTTONUP:
        printf("up %d\n", e.jbutton.button);
        break;
      case SDL_JOYBUTTONDOWN:
        printf("down %d\n", e.jbutton.button);
        if(e.jbutton.button == 14){
          stop = 1;
        }
        break;
      case SDL_JOYAXISMOTION:
        // up-left
        //   (SDL_JoystickGetAxis(joy, 1) < -16384) && (SDL_JoystickGetAxis(joy, 0) < -16384);
        // down-left
        //   (SDL_JoystickGetAxis(joy, 1) > 16384) && (SDL_JoystickGetAxis(joy, 0) < -16384);
        // down-right
        //   (SDL_JoystickGetAxis(joy, 1) > 16384) && (SDL_JoystickGetAxis(joy, 0) > 16384);
        // up-right
        //   (SDL_JoystickGetAxis(joy, 1) < -16384) && (SDL_JoystickGetAxis(joy, 0) > 16384);

        // up
        //   vax = SDL_JoystickGetAxis(joy, 0);
        //   (SDL_JoystickGetAxis(joy, 1) < -16384) && (ABS(vax) < 16384);
        // down
        //   vax = SDL_JoystickGetAxis(joy, 0);
        //   (SDL_JoystickGetAxis(joy, 1) > 16384) && (ABS(vax) < 16384);
        // left
        //   vax = SDL_JoystickGetAxis(joy, 1);
        //   (SDL_JoystickGetAxis(joy, 0) < -16384) && (ABS(vax) < 16384);
        // right
        //   vax = SDL_JoystickGetAxis(joy, 1);
        //   (SDL_JoystickGetAxis(joy, 0) > 16384) && (ABS(vax) < 16384);
        break;
      }
    }
  }
  SDL_JoystickClose(joy);
  SDL_Quit();
  return 0;
}

編譯

$ cd
$ wget https://github.com/steward-fu/zpg-pro/releases/download/v1.0/toolchain-x64.tar.gz
$ tar xvf toolchain-x64.tar.gz
$ sudo mv gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu /opt/zpg-sdk
$ export PATH=$PATH:/opt/zpg-sdk/bin

$ aarch64-none-linux-gnu-gcc main.c -o main -lSDL2 -lSDL2_image -I/opt/zpg-sdk/aarch64-none-linux-gnu/include/SDL2 -Wl,-rpath-link=/opt/zpg-sdk/aarch64-none-linux-gnu/lib/pulseaudio -Wl,-rpath-link=/opt/zpg-sdk/aarch64-none-linux-gnu/lib


返回上一頁