00001 #ifndef _discrete_btns_H_ 00002 #define _discrete_btns_H_ 00003 00004 #include "dev/buttons.H" 00005 #include "dev/discrete_contact.H" 00006 00007 // 00008 // This device maps from the discrete_contact device into a pseudo-button 00009 // device that reports button events corresponding to given pseudo-button 00010 // specifications. Each pseudo-button specification is a pair of an interest 00011 // mask and a resulting value; the button is considered to be on if any set in 00012 // the state of the device, anded with the mask equals the resulting value. 00013 // 00014 00015 class DEVdiscrete_btns : public EVENThandler { 00016 public: 00017 typedef EVENTdiscrete_contact::bits bits; 00018 protected: 00019 ARRAY<bits> _masks; 00020 ARRAY<bits> _results; 00021 ARRAY<DEVice_btn *> _buttons; 00022 DEVdiscrete_contact &_dcsource; 00023 public: 00024 DEVdiscrete_btns(DEVdiscrete_contact &dc) : _dcsource(dc) 00025 { dc.add_handler(this); } 00026 virtual ~DEVdiscrete_btns() { _dcsource.rem_handler(this);} 00027 00028 // 00029 // If you add two buttons with the same id, they'll both be added and 00030 // operate separately, but deleting it will only delete the first one 00031 // left. 00032 // 00033 void add(DEVice_btn *btn, const bits &mask, const bits &result) { 00034 _buttons += btn; 00035 _masks += mask; 00036 _results += result; } 00037 void del(DEVice_btn *btn) { int i = _buttons.get_index(btn); 00038 _masks. remove(i); 00039 _results.remove(i); 00040 _buttons -= btn; } 00041 00042 /* -------------- EVENThandler methods --------------- */ 00043 00044 virtual void handle_event(cEVENTptr &e); 00045 }; 00046 00047 #endif