00001 #ifndef _discrete_contact_H_
00002 #define _discrete_contact_H_
00003
00004 #include "event/event.H"
00005 #include "dev/dev.H"
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 MAKE_PTR_SUBC(EVENTdiscrete_contact, EVENT);
00031 class EVENTdiscrete_contact : public EVENT {
00032 public:
00033 typedef unsigned long bits;
00034
00035 protected:
00036 ARRAY<bits> _oldstate;
00037 ARRAY<bits> _newstate;
00038
00039 bool testmask(const ARRAY<bits> &s, const bits &m, const bits &r) const {
00040 int i; for(i = 0; i < s.num(); i++) if((s[i]&m) == r) return true;
00041 return false; }
00042
00043
00044
00045 virtual bool compare(cEVENTptr &e) const
00046 { cerr << "EVENTdiscrete_contact::compare - Need to implement\n";
00047 return false; }
00048
00049 virtual void debug_data(ostream &o)const { o << " contacts=";
00050 for (int i=8*sizeof(bits)-1;i>=0&&_newstate.num();i--)
00051 o << ((_newstate[0] & (1 << i)) ? "1":"0"); }
00052
00053 public:
00054 EVENTdiscrete_contact(EVENTsource *s,
00055 const ARRAY<bits> &o,
00056 const ARRAY<bits> &n) : EVENT(s),
00057 _oldstate(o), _newstate(n)
00058 { }
00059
00060 const ARRAY<bits> &oldstate() const { return _oldstate; }
00061 const ARRAY<bits> &newstate() const { return _newstate; }
00062
00063 bool testmaskold(const bits &mask, const bits &result) const {
00064 return testmask(_oldstate, mask, result); }
00065 bool testmasknew(const bits &mask, const bits &result) const {
00066 return testmask(_newstate, mask, result); }
00067
00068
00069 DEFINE_DERIVED_TYPE(EVENTdiscrete_contact, EVENT, cEVENTptr);
00070 };
00071
00072
00073 class DEVdiscrete_btns;
00074
00075
00076
00077
00078
00079
00080
00081
00082 class DllImpExp DEVdiscrete_contact : public DEVice {
00083 public:
00084 typedef EVENTdiscrete_contact::bits bits;
00085
00086 protected:
00087 ARRAY<bits> _state;
00088 DEVdiscrete_btns *_btnmap;
00089
00090 public:
00091 DEVdiscrete_contact(Cstr_ptr &n);
00092 virtual ~DEVdiscrete_contact() { }
00093
00094 virtual void event(const ARRAY<bits> &newstate) {
00095 distrib(new EVENTdiscrete_contact(this, _state, newstate));
00096 _state = newstate;
00097 }
00098
00099
00100 DEFINE_DERIVED_TYPE(DEVdiscrete_contact, DEVice, const DEVice *);
00101 };
00102
00103
00104 #endif