root/lang/cplusplus/gainer++/gainer.h

Revision 8185, 1.6 kB (checked in by mootoh, 10 months ago)

lang/cplusplus/gainer++: use thread to receive events from I/O module.

Line 
1/*
2 * Gainer C++ wrapper
3 */
4#include <string>
5#include <vector>
6#include <pthread.h>
7// #include "protocol.h"
8
9class Gainer;
10
11namespace GainerInternal {
12  class Exception {
13  }; // Exception
14} // GainerInternal
15
16/**
17 * Gainer Serial I/O.
18 */
19class Gainer {
20public:
21  //! event handler calback
22  typedef void (*callback_t)(void);
23
24  /**
25   * @brief setup Gainer
26   * @param path  device path (/dev/cu.usbserial*)
27   * @param config configutation mode (1-7)
28   */
29  Gainer(const std::string &path, int config=1);
30  ~Gainer();
31
32  void set_led(bool flag); //! set led state (true: on/ false:off)
33
34  // void set_matrix(ary);
35
36  void peek_digital_inputs(); //! capture all digital inputs
37  void peek_analog_inputs();  //! capture all analog inputs
38
39  void continuous_digital_inputs();
40  void continuous_analog_inputs();
41
42  void exit_continuos();
43
44  void set_digital_output(int n);
45  void set_analog_output(int n);
46
47  void set_on_pressed(callback_t funcp) { on_pressed = funcp; }
48  void set_on_released(callback_t funcp) { on_released = funcp; }
49
50  // properties
51  bool led_;
52  std::vector<int> analog_inputs;
53  std::vector<bool> digital_inputs;
54
55private:
56  void setup_port();
57  void reboot();
58  void set_configuration(int number);
59  void command(const std::string &cmd, int wait=0);
60  void command_send(const std::string &cmd);
61  void process_event(std::string &event);
62
63  int config_;
64  int io_;
65  bool end_;
66  callback_t on_pressed, on_released;
67  pthread_t thread_;
68
69  enum pin_t {AIN=0, DIN, AOUT, DOUT};
70  static const int CONFIG[][4];
71  static const int MATRIX_LED_CONFIGURATION = 7;
72
73  static void *receiver(void *arg);
74}; // Gainer
75
Note: See TracBrowser for help on using the browser.