00001 #ifndef _buttons_serial_H_
00002 #define _buttons_serial_H_
00003
00004 #include "dev/buttons.H"
00005 #ifdef NO_POLL
00006 #include "tty/tty.H"
00007 #else
00008 #include "dev/polled.H"
00009 #endif
00010
00011
00012
00013
00014
00015 MAKE_PTR_SUBC(EVENTbtn_serial, EVENT);
00016 class DllImpExp EVENTbtn_serial : public EVENT {
00017
00018 protected:
00019 bool _trans;
00020
00021
00022 virtual bool compare(cEVENTptr &e) const { EVENTbtn_serial *b =
00023 (EVENTbtn_serial *)&*e;
00024 return b->_trans == _trans; }
00025 virtual void debug_data(ostream &o) const { o << " " <<
00026 (_trans ? "down":"up"); }
00027
00028 public:
00029
00030 EVENTbtn_serial(Cstr_ptr &n, bool t=true) : EVENT(new EVENTsource(n)),
00031 _trans(t) { }
00032 EVENTbtn_serial(EVENTsource *s, bool t=true): EVENT(s), _trans(t) { }
00033
00034 bool transition() const { return _trans; }
00035
00036
00037
00038 DEFINE_DERIVED_TYPE(EVENTbtn_serial, EVENT, cEVENTptr);
00039 static EVENTbtn_serialptr cast(cEVENTptr &e) { return EVENTbtn_serial::isa(e)
00040 ? (EVENTbtn_serial *)&*e : 0; }
00041 };
00042
00043
00044
00045
00046 class DEVbutton_serial : public DEVice,
00047 #ifdef NO_POLL
00048 public TTYfd {
00049 #else
00050 public DEVpolled {
00051 #endif
00052
00053 protected:
00054 int _fd;
00055 bool _state;
00056
00057
00058 public:
00059 DEVbutton_serial(Cstr_ptr &name);
00060 virtual ~DEVbutton_serial();
00061 #ifdef NO_POLL
00062
00063 void sample();
00064 bool activate();
00065 bool deactivate();
00066 #else
00067
00068 void do_poll();
00069 #endif
00070
00071
00072 DEFINE_DERIVED_TYPE(DEVbutton_serial, DEVice, const DEVice *);
00073 };
00074
00075 #endif