blob: 6a6c83841c8a055d5eb33f641ed7ed5d63bfb5d8 [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#ifndef __CRIO_MOTOR_SERVER_SOLENOID_OUTPUT_H_
2#define __CRIO_MOTOR_SERVER_SOLENOID_OUTPUT_H_
3
4#include "aos/crio/motor_server/OutputDevice.h"
5
6namespace aos {
7
8class SolenoidOutput : public OutputDevice {
9 private:
10 Solenoid solenoid;
11 bool value;
12 public:
13 SolenoidOutput(uint32_t port) : OutputDevice(), solenoid(port), value(false) {
14 }
15 protected:
16 virtual bool ReadValue(ByteBuffer &buff) {
17 const int on = buff.read_char();
18 if (on != 0 && on != 1) {
19 if (on != -1) {
20 LOG(ERROR, "illegal solenoid value %d\n", on);
21 }
22 return false;
23 }
24 value = on;
25 return true;
26 }
27 virtual void SetValue() {
28 solenoid.Set(value);
29 }
30 virtual void NoValue() {
31 // leave the solenoid in its previous state
32 }
33};
34
35} // namespace aos
36
37#endif
38