0

Working on a lab for school, where we have to take the gyroscope values from a PS4 controller and move an avatar around the screen in NCurses with Cygwin using C. Currently I have a scanf() statement scanning in the data from the PS4 controller that works fine in a normal Cygwin window/program, but I know NCurses doesn't use the STDIN so the scanf() data is not updating in the NCurses window. Does anyone know what function I have to use in my program or how to pipe it in the command line? Thanks!

Current command I'm using:

 ./ds4rd.exe -d 054c:09cc -D DS4_USB -t -g -b | ./lab8.exe 80

Main Code:

// Main - Run with './ds4rd.exe -t -g -b' piped into STDIN
int main(int argc, char* argv[])
{
    int t,b_Triangle, b_X, b_Square, b_Circle;
    double g_x, g_y, g_z;
    if (argc <2) { printf("You forgot the difficulty\n"); return 1;}
    int difficulty = atoi(argv[1]); // get difficulty from first command line arg
    // setup screen    
    initscr();
    refresh();

    // Generate and draw the maze, with initial avatar
    srand(time(0));
    int colAvatar, rowAvatar;

    rowAvatar = 0;
    colAvatar = rand() % NUMCOLS;

    generate_maze(difficulty);
    draw_maze();
    draw_character(colAvatar,rowAvatar,AVATAR);

    // Read gyroscope data to get ready for using moving averages.    



    // Event loop
    do
    {

        // Read data, update average
        noecho();
        scanf("%d, %lf, %lf, %lf, %d, %d, %d, %d", &t, &g_x, &g_y, &g_z, &b_Triangle, &b_Circle, &b_X, &b_Square);

        // Is it time to move?  if so, then move avatar
        sleep(1);

        rowAvatar += 1;

        if(g_x > 0){
            colAvatar -= 1;
        }
        if(g_x < 0){
            colAvatar += 1;
        }

        MAZE[rowAvatar][colAvatar] = EMPTY_SPACE;
        MAZE[rowAvatar][colAvatar] = AVATAR;
        mvaddch(rowAvatar,colAvatar,EMPTY_SPACE);
        mvaddch(rowAvatar,colAvatar,AVATAR);

        refresh();
        fflush(stdout);



    } while(b_Square != 1); // Change this to end game at right time 

    // Print the win message
    endwin();

    printf("YOU WIN!\n");
    return 0;
}
Z-M
  • 1
  • 1

1 Answers1

0

You probably have in mind scanw:

int scanw(const char *fmt, ...);

convert formatted input from a curses window

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • I changed my scanf to scanw with the same parameters, but it still does not seem to receive any input after the initial input. Could you clarify how to use the "int" and the "const char *fmt" parts that you posted? Thank you for the reply! – Z-M Nov 17 '19 at 18:04
  • Checking on [PS4 controller](https://www.google.com/search?client=firefox-b-1-d&ei=DJDRXdjTJ9Kk_Qbs_oa4BA&q=%22ps4+controller%22+linux&oq=%22ps4+controller%22+linux&gs_l=psy-ab.3..0l3j0i22i30l7.12872.14390..14842...0.2..0.113.472.5j1......0....1..gws-wiz.......0i71j0i131i273j0i67j0i131.NawdQSw759w&ved=0ahUKEwjYiZTi7vHlAhVSUt8KHWy_AUcQ4dUDCAo&uact=5) it seems your device wouldn't be coming via the standard input using Linux, and that you should look for a tutorial explaining how to work with that. – Thomas Dickey Nov 17 '19 at 18:26