【问题标题】:Scanning input from USB device with NCurses in Cygwin在 Cygwin 中使用 NCurses 扫描 USB 设备的输入
【发布时间】:2023-04-08 22:55:01
【问题描述】:

在学校实验室工作,我们必须从 PS4 控制器获取陀螺仪值,并在 NCurses 中使用 Cygwin 在屏幕上移动头像。目前我有一个 scanf() 语句扫描来自PS4 控制器在普通 Cygwin 窗口/程序中工作正常,但我知道 NCurses 不使用 STDIN,因此 scanf() 数据不会在 NCurses 窗口中更新。有谁知道我必须在我的程序中使用什么功能或如何在命令行中使用它?谢谢!

我正在使用的当前命令:

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

主代码:

// 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;
}

【问题讨论】:

    标签: c cygwin ncurses


    【解决方案1】:

    你可能想到了scanw

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

    转换格式 从诅咒窗口输入

    【讨论】:

    • 我用相同的参数将我的 scanf 更改为 scanw,但在初始输入后它似乎仍然没有收到任何输入。您能否阐明如何使用您发布的“int”和“const char *fmt”部分?感谢您的回复!
    • 检查PS4 controller,您的设备似乎不会通过使用 Linux 的标准输入来输入,您应该寻找解释如何使用它的教程。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-03
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    相关资源
    最近更新 更多