Dies ist eine alte Version des Dokuments!


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 GPIO. One of it's channels is configured as output and set to true.

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <flinklib.h>
 
#define DEFAULT_DEV "/dev/flink0"
 
int main(void) {
  flink_dev*    dev;
  flink_subdev* subdev;
  char*         dev_name = DEFAULT_DEV;
  uint8_t       subdevice_id = 0;
  uint32_t      channel = 0;
  int           error = 0;
 
  // Open flink device
  dev = flink_open(DEFAULT_DEV );
  if(dev == NULL) {
    fprintf(stderr, "Failed to open device %s!\n", dev_name);
    return -1;
  }
 
  // Get a pointer to the choosen subdevice
  subdev = flink_get_subdevice_by_id(dev, subdevice_id );
  if(subdev == NULL) {
    fprintf(stderr, "Illegal subdevice id %d!\n", subdevice_id);
    return -1;
  }
 
  // Set I/O direction to output
  error = flink_dio_set_direction(subdev, channel, true);
  if(error != 0) {
    printf("Configuring GPIO direction failed!\n");
    return -1;
  }
 
  // Write 'true' on output
  error = flink_dio_set_value(subdev, channel, true);
  if(error != 0) {
    printf("Writing value failed!\n");
    return -1;
  }
 
  // Close flink device
  flink_close(dev);
 
  return EXIT_SUCCESS;
}