c - 在 Cygwin 中使用 NCurses 扫描 USB 设备的输入

标签 c cygwin ncurses

在学校实验室工作,我们必须从 PS4 Controller 获取陀螺仪值,并使用 C 语言通过 Cygwin 在 NCurses 中在屏幕上移动头像。目前,我有一个 scanf() 语句扫描来自PS4 Controller 在正常的 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;
}

最佳答案

您可能想到的是scanw :

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

convert formatted input from a curses window

关于c - 在 Cygwin 中使用 NCurses 扫描 USB 设备的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58902781/

相关文章:

c++ - 创建 C/C++ 解析器/分析器的好工具

c - Opencv FindContours函数

javascript - 如何添加允许在 Umbraco 中添加新行的验证

windows - 使用 cygwin 时 vagrant up "Error: Could not create directory '/home/username/.ssh'"

c - 在 C 中,我应该如何在字符和另一个字符之间剪切文本文件?

c指针和数组,将内容复制到另一个数组

c - Windows 10 上的多线程性能比 Linux 差得多

linux - lib32-ncurses 没有安装到 rootfs

C程序垂直线不在窗口内打印(方形)

Python:诅咒和默认的黑色