ListDevices.c

/**
 * ListDevices.c - for LibTiePie 0.5+
 *
 * This example prints all the available devices to the screen.
 *
 * Find more information on http://www.tiepie.com/LibTiePie .
 */

#include 
#include 
#include 
#include 
#include "CheckStatus.h"
#include "PrintInfo.h"
#include "Utils.h"

int main(int argc, char* argv[])
{
  int status = EXIT_SUCCESS;

  // Initialize library:
  LibInit();

  // Print library information:
  printLibraryInfo();

  // Update device list:
  LstUpdate();
  CHECK_LAST_STATUS();

  // Get the number of connected devices:
  const uint32_t connectedDevices = LstGetCount();
  CHECK_LAST_STATUS();

  if(connectedDevices != 0)
  {
    printf("Available devices: %" PRIu16 NEWLINE, connectedDevices);

    for(uint32_t index = 0; index < connectedDevices; index++)
    {
      // Print device info:
      uint32_t length = LstDevGetName(IDKIND_INDEX, index, NULL, 0) + 1;
      CHECK_LAST_STATUS();
      char* name = malloc(sizeof(char) * length);
      length = LstDevGetName(IDKIND_INDEX, index, name, length);
      CHECK_LAST_STATUS();
      printf("  Name: %s" NEWLINE, name);
      free(name);

      printf("    Serial Number  : %" PRIu32 NEWLINE, LstDevGetSerialNumber(IDKIND_INDEX, index));
      CHECK_LAST_STATUS();

      printf("    Available types: ");
      printDeviceType(LstDevGetTypes(IDKIND_INDEX, index));
      CHECK_LAST_STATUS();
      printf(NEWLINE);
    }
  }
  else
  {
    fprintf(stderr, "No devices found!" NEWLINE);
    status = EXIT_FAILURE;
  }

  // Exit library:
  LibExit();

  return status;
}