This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | flink_lib:high_level_example [2020/05/26 16:11] – ursgraf | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Example using high-level API ====== | ||
+ | The following example demonstrates how a flink device can be opened and a subdevice selected. The subdevice is of type '' | ||
+ | <code c> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | |||
+ | int main(void) { | ||
+ | char* | ||
+ | flink_dev* | ||
+ | flink_subdev* subdev; | ||
+ | char* | ||
+ | uint32_t | ||
+ | uint32_t | ||
+ | int error = 0; | ||
+ | |||
+ | // Open flink device | ||
+ | dev = flink_open(DEFAULT_DEV); | ||
+ | if(dev == NULL) { | ||
+ | fprintf(stderr, | ||
+ | return -1; | ||
+ | } | ||
+ | |||
+ | // Get a pointer to the choosen subdevice | ||
+ | subdev = flink_get_subdevice_by_unique_id(dev, | ||
+ | if(subdev == NULL) { | ||
+ | fprintf(stderr, | ||
+ | return -1; | ||
+ | } | ||
+ | |||
+ | // Set I/O direction to output | ||
+ | error = flink_dio_set_direction(subdev, | ||
+ | if(error != 0) { | ||
+ | printf(" | ||
+ | return -1; | ||
+ | } | ||
+ | |||
+ | // toggle an output for 20s | ||
+ | uint8_t out = 1; | ||
+ | for (int count = 0; count < 200; count++) { | ||
+ | error = flink_dio_set_value(subdev, | ||
+ | if(error != 0) { | ||
+ | printf(" | ||
+ | return -1; | ||
+ | } | ||
+ | usleep(100000); | ||
+ | out = !out; | ||
+ | } | ||
+ | |||
+ | // Close flink device | ||
+ | flink_close(dev); | ||
+ | |||
+ | return EXIT_SUCCESS; | ||
+ | } | ||
+ | </ |