Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Nächste Überarbeitung
Vorhergehende Überarbeitung
software:flink:flink_lib:high_level_example [2014-12-02 12:29] – angelegt grafsoftware:flink:flink_lib:high_level_example [Unbekanntes Datum] (aktuell) – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1
Zeile 1: Zeile 1:
-====== Example using high-level API ====== 
-The following example  
  
-<code c> 
-#include <stdio.h> 
-#include <stdlib.h> 
-#include <unistd.h> 
-#include <getopt.h> 
-#include <ctype.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; 
- bool          output; 
- bool          val; 
-  
-  // Open flink device 
-  dev = flink_open(dev_name); 
-  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, output); 
- if(error != 0) { 
- printf("Configuring GPIO direction failed!\n"); 
- return -1; 
- } 
-  
- // Read or write I/O 
- if(output) { // write 
- printf("Writing %u to channel %u of subdevice %u\n", val, channel, subdevice_id); 
- error = flink_dio_set_value(subdev, channel, val); 
- if(error != 0) { 
- printf("Writing value failed!\n"); 
- return -1; 
- } 
- } 
- else { // read 
- uint8_t res; 
- error = flink_dio_get_value(subdev, channel, &res); 
- if(error != 0) { 
- printf("Reading value failed!\n"); 
- return -1; 
- } 
- else { 
- printf("Read: %u!\n", res); 
- } 
- } 
-  
- // Close flink device 
- flink_close(dev); 
-  
-    return EXIT_SUCCESS; 
-} 
-</code>