// Create a ptz device ptz_t *ptz_create(mainwnd_t *mainwnd, opt_t *opt, playerc_client_t *client, int index, const char *drivername, int subscribe) { char section[64]; char label[64]; ptz_t *ptz; ptz = malloc(sizeof(ptz_t)); ptz->datatime = 0; ptz->drivername = strdup(drivername); ptz->proxy = playerc_ptz_create(client, index); // Set initial device state snprintf(section, sizeof(section), "ptz:%d", index); if (subscribe) { if (playerc_ptz_subscribe(ptz->proxy, PLAYER_OPEN_MODE) != 0) PRINT_ERR1("libplayerc error: %s", playerc_error_str()); } // Construct the menu snprintf(label, sizeof(label), "ptz:%d (%s)", index, ptz->drivername); ptz->menu = rtk_menu_create_sub(mainwnd->device_menu, label); ptz->subscribe_item = rtk_menuitem_create(ptz->menu, "Subscribe", 1); ptz->command_item = rtk_menuitem_create(ptz->menu, "Command", 1); // Set the initial menu state rtk_menuitem_check(ptz->subscribe_item, ptz->proxy->info.subscribed); // Construct figures ptz->data_fig = rtk_fig_create(mainwnd->canvas, mainwnd->robot_fig, 10); ptz->cmd_fig = rtk_fig_create(mainwnd->canvas, mainwnd->robot_fig, 11); ptz->data_fig_tilt = rtk_fig_create(mainwnd->canvas, mainwnd->robot_fig, 12); ptz->cmd_fig_tilt = rtk_fig_create(mainwnd->canvas, mainwnd->robot_fig, 13); rtk_fig_movemask(ptz->cmd_fig, RTK_MOVE_TRANS); rtk_fig_origin(ptz->cmd_fig, 1, 0, 0); rtk_fig_color_rgb32(ptz->cmd_fig, COLOR_PTZ_CMD); rtk_fig_ellipse(ptz->cmd_fig, 0, 0, 0, 0.2, 0.2, 0); rtk_fig_movemask(ptz->cmd_fig_tilt, RTK_MOVE_TRANS); rtk_fig_origin(ptz->cmd_fig_tilt, 0.8, 0, 0); rtk_fig_color_rgb32(ptz->cmd_fig_tilt, COLOR_PTZ_CMD_TILT); rtk_fig_ellipse(ptz->cmd_fig_tilt, 0, 0, 0, 0.2, 0.2, 0); return ptz; }
// Basic ptz test int test_ptz(playerc_client_t *client, int index) { int t; void *rdevice; playerc_ptz_t *device; double period; printf("device [ptz] index [%d]\n", index); device = playerc_ptz_create(client, index); TEST("subscribing (read)"); if (0 == playerc_ptz_subscribe(device, PLAYER_OPEN_MODE)) PASS(); else FAIL(); period = 10 / M_PI * 2; for (t = 0; t < 20; t++) { TEST1("reading data (attempt %d)", t); do rdevice = playerc_client_read(client); while (rdevice == client); if (rdevice == device) { PASS(); printf("ptz: [%d %d %d]\n", (int) (device->pan * 180 / M_PI), (int) (device->tilt * 180 / M_PI), (int) (device->zoom * 180 / M_PI)); } else { FAIL(); break; } TEST1("writing data (attempt %d)", t); if (playerc_ptz_set(device, sin(t / period) * M_PI / 2, sin(t / period) * M_PI / 3, (1 - t / 20.0) * M_PI) != 0) { FAIL(); break; } PASS(); } TEST1("writing data (attempt %d)", t); if (playerc_ptz_set(device, 0, 0, M_PI) != 0) FAIL(); else PASS(); TEST("unsubscribing"); if (playerc_ptz_unsubscribe(device) == 0) PASS(); else FAIL(); playerc_ptz_destroy(device); return 0; }