int main(void) { // Create IP connection IPConnection ipcon; ipcon_create(&ipcon); // Create device object DualButton db; dual_button_create(&db, UID, &ipcon); // Connect to brickd if(ipcon_connect(&ipcon, HOST, PORT) < 0) { fprintf(stderr, "Could not connect\n"); return 1; } // Don't use device before ipcon is connected // Register state changed callback to function cb_state_changed dual_button_register_callback(&db, DUAL_BUTTON_CALLBACK_STATE_CHANGED, (void *)cb_state_changed, NULL); printf("Press key to exit\n"); getchar(); dual_button_destroy(&db); ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally return 0; }
void LaserTransform::callbackEnumerate(const char *uid, const char *connected_uid, char position, uint8_t hardware_version[3], uint8_t firmware_version[3], uint16_t device_identifier, uint8_t enumeration_type, void *user_data) { LaserTransform *lt = (LaserTransform*) user_data; if(enumeration_type == IPCON_ENUMERATION_TYPE_DISCONNECTED) { return; } // check if device is an imu if(device_identifier == IMU_DEVICE_IDENTIFIER) { if (lt->is_imu_v2_connected) return; ROS_INFO_STREAM("found IMU with UID:" << uid); // Create IMU device object imu_create(&(lt->imu), uid, &(lt->ipcon)); imu_set_convergence_speed(&(lt->imu),lt->imu_convergence_speed); imu_leds_on(&(lt->imu)); lt->imu_init_time = ros::Time::now(); lt->is_imu_connected = true; } else if (device_identifier == IMU_V2_DEVICE_IDENTIFIER) { if (lt->is_imu_connected) return; ROS_INFO_STREAM("found IMU_v2 with UID:" << uid); // Create IMU_v2 device object imu_v2_create(&(lt->imu_v2), uid, &(lt->ipcon)); imu_leds_on(&(lt->imu_v2)); lt->is_imu_v2_connected = true; } else if (device_identifier == GPS_DEVICE_IDENTIFIER) { ROS_INFO_STREAM("found GPS with UID:" << uid); // Create GPS device object gps_create(&(lt->gps), uid, &(lt->ipcon)); lt->is_gps_connected = true; } else if (device_identifier == INDUSTRIAL_DIGITAL_IN_4_DEVICE_IDENTIFIER) { ROS_INFO_STREAM("found IDI4 with UID:" << uid); // Create IndustrialDigitalIn4 device object industrial_digital_in_4_create(&(lt->idi4), uid, &(lt->ipcon)); // Register callback for interrupts industrial_digital_in_4_register_callback(&(lt->idi4), INDUSTRIAL_DIGITAL_IN_4_CALLBACK_INTERRUPT, (void*)callbackIdi4, lt); // set debounce period industrial_digital_in_4_set_debounce_period(&(lt->idi4),10); // Enable interrupt on pin 0 industrial_digital_in_4_set_interrupt(&(lt->idi4), 1 << 0); lt->is_idi4_connected = true; } else if (device_identifier == DUAL_BUTTON_DEVICE_IDENTIFIER) { ROS_INFO_STREAM("found DualButton with UID:" << uid); dual_button_create(&(lt->db), uid, &(lt->ipcon)); // Register state changed callback to function cb_state_changed dual_button_register_callback(&(lt->db), DUAL_BUTTON_CALLBACK_STATE_CHANGED, (void *)callbackDb, lt); } }