00001
00012 #ifndef _GAINER_H_
00013 #define _GAINER_H_
00014
00015 #include <string>
00016 #include <vector>
00017 #include <process.h>
00018 #include <windows.h>
00019
00020 class Gainer;
00021
00022 namespace GainerInternal
00023 {
00024 class Exception
00025 {
00026
00027 };
00028 }
00029
00030
00031
00032 enum COM_PORT
00033 {
00034 COM1 = 1,
00035 COM2,
00036 COM3,
00037 COM4,
00038 COM5,
00039 COM6,
00040 COM7,
00041 COM8,
00042 COM9,
00043 COM10
00044 };
00045
00046
00047
00048 enum MODE
00049 {
00050 MODE1 = 1,
00051 MODE2,
00052 MODE3,
00053 MODE4,
00054 MODE5,
00055 MODE6,
00056 MODE7
00057 };
00058
00059
00060 #define SEND_TIME 50
00061
00067 class Gainer
00068 {
00069 public:
00073 typedef void (*callback_t)(void);
00074
00081 Gainer(int portNum=1, int mode=1, bool verbose=false);
00082
00086 ~Gainer();
00087
00092 void turnOnLED();
00093
00098 void turnOffLED();
00099
00100
00101 #if 0
00102 void set_matrix(ary);
00103 void set_analog_output(int n);
00104
00105 void continuous_digital_inputs();
00106 void continuous_analog_inputs();
00107 void exit_continuos();
00108 #endif
00109
00110
00115 void peekDigitalInput();
00116
00121 void peekAnalogInput();
00122
00128 void digitalOutput(int value);
00129
00135 void setHigh(int port);
00136
00137 #if 0
00138
00143 void setHigh(int *portArray);
00144 #endif
00145
00151 void setLow(int port);
00152
00153 #if 0
00154
00159 void setLow(int *portArray);
00160 #endif
00161
00167 void setOnPressedCallback(callback_t funcp){on_pressed = funcp;}
00168
00174 void setOnReleasedCallback(callback_t funcp){on_released = funcp;}
00175
00176 private:
00181 int setupCOMPort();
00182
00187 void reboot();
00188
00194 void setConfiguration(int mode);
00195
00202 void command(const std::string &cmd, int wait=0);
00203
00204 void command_send(const std::string &cmd);
00205 void processEvent(std::string &event);
00206
00207
00208 bool led_;
00209 std::vector<int> analogInputs;
00210 std::vector<bool> digitalInputs;
00211
00215 int config_;
00216
00220 int portNum_;
00221 bool endFlag;
00222
00226 callback_t on_pressed, on_released;
00227
00231 HANDLE handle;
00232
00233 enum pin_t {AIN = 0, DIN, AOUT, DOUT};
00234 static const int CONFIG[][4];
00235 static const int MATRIX_LED_CONFIGURATION = 7;
00236 static unsigned __stdcall receiver(void *arg);
00237 };
00238
00239 #endif // __GAINER_H_