Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

discrete_contact.H

Go to the documentation of this file.
00001 #ifndef _discrete_contact_H_
00002 #define _discrete_contact_H_
00003 
00004 #include "event/event.H"
00005 #include "dev/dev.H"
00006 
00007 /* This device has some finite number of contact points and reports multiple
00008    disjoint sets of these buttons; each set represents one set of contacts
00009    among the contact points. For instance, you might have a pinch glove and
00010    each set reported is a pinch involving some number of fingers (possibly
00011    more than two). A device doesn't have to support more than one concurrent
00012    touching set, but it can.
00013 
00014    An event is the entire state change from the previous state (list of sets
00015    of contacts) to the new state. We don't try to break this up into separate
00016    events for the contacting and uncontacting parameters because we might get
00017    a split (1&2&3&4 -> 1&2, 3&4) and don't want to get two events that might
00018    trigger two update functions later (especially if they just look at the
00019    state on the device anyway). If you want up/down events, you probably want
00020    to reinterpret this device as a DEVice_btns; use the DEVice_discrete_btns
00021    class (as a handler on the DEVice_discrete_contact class) which handles the
00022    mapping for you. However, we do support testing against an interest mask
00023    and resulting value here; if any set when anded with the mask matches the
00024    result then it returns true, else false. (This is used by
00025    DEVice_discrete_btns.)  */
00026 
00027 /* These should really be templated instead of using unsigned long, but it's
00028    not necessary yet and I don't want to have to go through all that work. */
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    /* ----------- EVENT methods --------------- */
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    /* ----------- TYPEDOBJ methods --------------- */
00069    DEFINE_DERIVED_TYPE(EVENTdiscrete_contact, EVENT, cEVENTptr);
00070 }; 
00071 
00072 
00073 class DEVdiscrete_btns;
00074 
00075 //
00076 //  DEVdiscrete_contact - device generating contact events
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     /* ----------- TYPEDOBJ methods --------------- */
00100     DEFINE_DERIVED_TYPE(DEVdiscrete_contact, DEVice, const DEVice *);
00101 };
00102 
00103 
00104 #endif

Generated on Mon Sep 15 16:25:56 2003 for gluebase by doxygen1.2.18