Added C++ examples to the build process
[libftdi] / examples / find_all_pp.cpp
1 /* final_all_pp.cpp
2
3    Simple libftdi-cpp usage
4
5    This program is distributed under the GPL, version 2
6 */
7
8 #include "ftdi.hpp"
9 #include <iostream>
10 #include <iomanip>
11 #include <cstdlib>
12 #include <cstring>
13 using namespace Ftdi;
14
15 int main(int argc, char **argv)
16 {
17    // Show help
18    if(argc > 1)
19    {
20       if(strcmp(argv[1],"-h") == 0 || strcmp(argv[1],"--help") == 0)
21       {
22          std::cout << "Usage: " << argv[0] << " [-v VENDOR_ID] [-p PRODUCT_ID]" << std::endl;
23          return EXIT_SUCCESS;
24       }
25    }
26
27    // Parse args
28    int vid = 0x0403, pid = 0x6010, tmp = 0;
29    for(int i = 0; i < (argc - 1); i++)
30    {
31       if(strcmp(argv[i], "-v") == 0)
32          if((tmp = strtol(argv[++i], 0, 16)) >= 0)
33             vid = tmp;
34
35       if(strcmp(argv[i], "-p") == 0)
36          if((tmp = strtol(argv[++i], 0, 16)) >= 0)
37             pid = tmp;
38    }
39
40    // Print header
41    std::cout << std::hex << std::showbase
42              << "Found devices ( VID: " << vid << ", PID: " << pid << " )"
43              << std::endl
44              << "------------------------------------------------"
45              << std::endl << std::dec;
46
47    // Print whole list
48    List* list = List::find_all(vid, pid);
49    for(List::iterator it = list->begin(); it != list->end(); it++)
50    {
51       std::cout << "FTDI (" << &*it << "): "
52                 << it->vendor() << ", "
53                 << it->description() << ", "
54                 << it->serial()
55                 << std::endl;
56
57    }
58
59    delete list;
60
61    return EXIT_SUCCESS;
62 }