Changeset 20


Ignore:
Timestamp:
10/17/08 14:34:26 (4 years ago)
Author:
jschild
Message:

-updated WacomTablet?
--Matrix outputs a transform matrix of pen position
--Value12 now gives the AspectRation? Width/Height? of the tablet to recalculate normalized values
--Button24 now is true if any tool is within proximity (pen, airbrush, mouse,...)
--some bug fixes
--addition bool property toggle-reset, as the intuos3 resets to the wrong values which get messed up during normalization

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/avango-daemon/include/avango/daemon/HIDInput.h

    r1 r20  
    221221      virtual float normalizeAbsValue(const struct input_event& event) const; 
    222222 
     223      bool stationLooksForEvent(int station_index, const struct input_event& event) const; 
     224 
     225      void applyEventToStation(int station_index, const struct input_event& event); 
     226 
     227      void clearRelativeStationValues(); 
     228 
     229      template <class ValueType> ValueType scanForOptionalFeature(const std::string& feature, ValueType default_value); 
     230 
     231 
    223232    private: 
    224233 
    225       bool stationLooksForEvent(int station_index, const struct input_event& event) const; 
     234//      bool stationLooksForEvent(int station_index, const struct input_event& event) const; 
    226235      const HIDMapping&  getStationHIDMapping(int station_index) const; 
    227236      const HIDLEDMapping&  getStationHIDLEDMapping(int station_index) const; 
     
    231240 
    232241      template <class ValueType> ValueType scanForRequiredFeature(const std::string& feature); 
    233       template <class ValueType> ValueType scanForOptionalFeature(const std::string& feature, ValueType default_value); 
    234  
    235       void applyEventToStation(int station_index, const struct input_event& event); 
    236       void clearRelativeStationValues(); 
     242 
     243//      void applyEventToStation(int station_index, const struct input_event& event); 
     244//      void clearRelativeStationValues(); 
    237245 
    238246    }; 
  • trunk/avango-daemon/include/avango/daemon/WacomTablet.h

    r1 r20  
    3333 
    3434#include <avango/daemon/HIDInput.h> 
     35#include <osg/Matrixf> 
     36#include <avango/osg/Object.h> 
     37#include <avango/osg/Fields.h> 
     38#include <avango/osg/MatrixTransform.h> 
    3539 
    3640namespace av 
     
    5256      WacomTablet(); 
    5357 
     58 
    5459    protected: 
    5560 
     
    6570 
    6671      /** 
     72       * overrides readloop() from av::daemon::HIDInput, used to create a transformation Matrix 
     73       * from pen input 
     74       */ 
     75      void readLoop(); 
     76 
     77      /** 
    6778       * overrides normalizeAbsValue from HIDInput, used to perform custom normalization 
    6879       * of some values 
    6980       */ 
    7081      float normalizeAbsValue(const input_event& event) const; 
     82 
     83      /** 
     84       * Retrieves aspect ratio of tablet from maximum absolute values, Ratio is written in Value12 
     85       */ 
     86      void retrieveAspectRatio(); 
     87 
     88      /** 
     89       * overrides HIDInput::parse_features() to add toggle_reset property 
     90       */ 
     91      int parse_features(); 
     92 
     93      bool mToggleReset; 
    7194    }; 
    7295  } 
  • trunk/avango-daemon/python/__init__.py

    r1 r20  
    159159    mydev.value[0] = \'EV_REL::REL_X\'. All appearing value und button events of a tablet 
    160160    are already set up in the constructor of this class. Optional properties: value, button, 
    161     led, norm_abs, accum_rel_events, reset_rel_values_cycle, timeout.""" 
     161    led, norm_abs, accum_rel_events, reset_rel_values_cycle, timeout, toggle_reset.""" 
    162162    def __init__(self): 
    163163        super(WacomTablet, self).__init__() 
  • trunk/avango-daemon/python/_daemon.cpp

    r1 r20  
    7474  std::string getTimeoutFeature(av::daemon::Device* self) { return self->queryFeature("timeout"); } 
    7575  std::string getPortFeature(av::daemon::Device* self) { return self->queryFeature("port"); } 
     76  std::string getToggleResetFeature(av::daemon::Device* self) { return self->queryFeature("toggle-reset"); } 
    7677 
    7778  // wrapper for specialized configureFeature calls, required by .add_property 
     79  std::string parseBoolString(std::string value) 
     80  { 
     81    if ((value == "true")||(value=="TRUE")||(value=="True")) return "1"; 
     82    if ((value == "false")||(value=="FALSE")||(value=="False")) return "0"; 
     83    return value; 
     84  } 
    7885  void setTTYFeature(av::daemon::Device* self, std::string value) { self->configureFeature("tty", value); } 
    79   void setNormAbsFeature(av::daemon::Device* self, std::string value) { self->configureFeature("norm-abs", value); } 
    80   void setAccumRelFeature(av::daemon::Device* self, std::string value) { self->configureFeature("accum-rel-events", value); } 
     86  void setNormAbsFeature(av::daemon::Device* self, std::string value) { self->configureFeature("norm-abs",parseBoolString(value)); } 
     87  //void setNormAbsFeature(av::daemon::Device* self, bool value) { (value)?self->configureFeature("norm-abs", "1"):self->configureFeature("norm-abs", "0"); } 
     88  void setAccumRelFeature(av::daemon::Device* self, std::string value) { self->configureFeature("accum-rel-events", parseBoolString(value)); } 
    8189  void setResetRelCycleFeature(av::daemon::Device* self, std::string value) { self->configureFeature("reset-rel-values-cycle", value); } 
    8290  void setTimeoutFeature(av::daemon::Device* self, std::string value) { self->configureFeature("timeout", value); } 
    8391  void setPortFeature(av::daemon::Device* self, std::string value) { self->configureFeature("port", value); } 
     92  void setToggleResetFeature(av::daemon::Device* self, std::string value) { self->configureFeature("toggle-reset", parseBoolString(value)); } 
    8493 
    8594  // set LED states 
     
    175184  class_<av::daemon::WacomTablet, av::Link<av::daemon::WacomTablet>, bases<av::daemon::HIDInput>, boost::noncopyable >("_WacomTabletHelper", 
    176185    "A helper class that provides some basic properties and functions inherited from HIDInput.") 
     186    .add_property("toggle_reset", &::getToggleResetFeature, &::setToggleResetFeature) 
    177187    ; 
    178188 
  • trunk/avango-daemon/src/avango/daemon/HIDInput.cpp

    r18 r20  
    2727#include <cstring> 
    2828#include <fcntl.h> 
     29#include <iostream> 
    2930#include <sstream> 
    3031#include <iomanip> 
     
    269270} 
    270271 
    271 int 
     272/*virtual*/ int 
    272273av::daemon::HIDInput::parse_features() 
    273274{ 
     
    285286  mResetRelCycle = scanForOptionalFeature<int>("reset-rel-values-cycle", 0); 
    286287  mTimeout = scanForOptionalFeature<unsigned int>("timeout", 200); 
    287  
     288  std::cout << "Parse Features, mNormAbs = " << mNormAbs << std::endl; 
    288289  return 1; 
    289290} 
  • trunk/avango-daemon/src/avango/daemon/WacomTablet.cpp

    r1 r20  
    3737 
    3838av::daemon::WacomTablet::WacomTablet() 
    39 {} 
     39{ 
     40} 
    4041 
    4142av::daemon::WacomTablet::~WacomTablet() 
     
    6970  configureFeature(station + "10", "EV_ABS::ABS_TILT_Y");  // Pen tilt y axis 
    7071  configureFeature(station + "11", "EV_REL::REL_WHEEL");   // Relative Wheel on mouse 
     72  configureFeature(station + "12", "AspectRatio");         // Ratio of Width/Height of Tablet 
    7173 
    7274  //auto-configure buttons 
     
    9698  configureFeature(station + "22", "EV_KEY::BTN_STYLUS");        // 1st side button on pen/airbrush 
    9799  configureFeature(station + "23", "EV_KEY::BTN_STYLUS2");       // 2nd side button on pen 
     100  configureFeature(station + "24", "Proximity");                 // true if anything in proximity 
     101  configureFeature(station + "25", "ToggleReset");               // should be true for Intuos3 
     102} 
     103 
     104void 
     105av::daemon::WacomTablet::retrieveAspectRatio() 
     106{ 
     107  HIDInput::AbsInfoMap::iterator it (mAbsInfoMap.find(0)); 
     108  const float x_max = (*it).second.maximum; 
     109 
     110  it = (mAbsInfoMap.find(1)); 
     111  const float y_max = (*it).second.maximum; 
     112 
     113  NumStationMap::iterator ns = mStations.begin(); 
     114 
     115  if ((0 < x_max)&&(0 < y_max)) 
     116    (*ns).second->setValue(12,x_max/y_max); 
     117  else 
     118    (*ns).second->setValue(12,1); 
     119} 
     120 
     121/* virtual */ void 
     122av::daemon::WacomTablet::readLoop() 
     123{ 
     124  float x,y; 
     125  ::osg::Matrixf matrix; 
     126 
     127  if (!parse_features()) 
     128  { 
     129    logger.warn() << "startDevice: required features missing, not started."; 
     130    return; 
     131  } 
     132 
     133  NumStationMap::iterator ns; 
     134  struct input_event      event; 
     135  int                     reset_wait_counter(0); 
     136 
     137  for (;;) 
     138  { 
     139 
     140    while (!isOpen()) 
     141    { 
     142      if (open()) 
     143      { 
     144        retrieve_abs_info(); 
     145        retrieveAspectRatio(); 
     146        stopLEDs(); 
     147        startLEDs(); 
     148      } 
     149      else 
     150      { 
     151        logger.warn() << "readLoop: HID device is not open."; 
     152        // sleep 5 seconds 
     153        struct timeval timeout = { 5, 0 }; 
     154        while (0 != ::select(0, 0, 0, 0, &timeout)) {} 
     155      } 
     156    } 
     157 
     158    updateLEDs(); 
     159    if (readEvent(&event)) { 
     160      reset_wait_counter = 0; 
     161      logger.trace() << "readLoop: time " << event.time.tv_sec << "." << event.time.tv_usec 
     162                     << ", type " << event.type << ", code " << event.code << ", value " <<  event.value; 
     163 
     164      for (ns = mStations.begin(); ns != mStations.end(); ++ns) 
     165      { 
     166        int station_index = ns->first; 
     167        if (!stationLooksForEvent(station_index, event)) { 
     168          continue; 
     169        } 
     170        applyEventToStation(station_index, event); 
     171      } 
     172 
     173      //set Transform Matrix 
     174      ns = mStations.begin(); 
     175      x = (*ns).second->getValue(0); 
     176      y = (*ns).second->getValue(1); 
     177      matrix.makeTranslate(::osg::Vec3f(x,y,0.0f)); 
     178      (*ns).second->setMatrix(matrix); 
     179 
     180      //set Proximity Value and reset some buttons which else get wrong values with normalization 
     181      for (int code=13; code<21; ++code) 
     182      { 
     183        if (0 == (*ns).second->getButton(code)) 
     184        { 
     185          if (code == 20) 
     186          { 
     187            (*ns).second->setButton(24,0); 
     188            if (mToggleReset) 
     189            { 
     190              (*ns).second->setValue(0,0); 
     191              (*ns).second->setValue(1,0); 
     192              (*ns).second->setValue(6,0); 
     193              (*ns).second->setValue(8,0); 
     194              (*ns).second->setValue(9,0); 
     195              (*ns).second->setValue(10,0); 
     196            } 
     197          } 
     198        } 
     199        else 
     200        { 
     201          (*ns).second->setButton(24,1); 
     202          code = 21; 
     203        } 
     204      } 
     205    } 
     206    else 
     207    { // timeout 
     208      ++reset_wait_counter; 
     209      // reset all EV_REL mappings to 0.0 if not accumulating relative values 
     210      if (!mAccumRel && (mResetRelCycle >= 0) && (reset_wait_counter >= mResetRelCycle)) 
     211      { 
     212        reset_wait_counter = 0; 
     213        clearRelativeStationValues(); 
     214        logger.trace() << "readLoop: resetting all EV_REL mappings."; 
     215      } 
     216    } 
     217  } 
     218 
    98219} 
    99220 
     
    103224  float normalized_value = 0.0f; 
    104225  HIDInput::AbsInfoMap::const_iterator iter (mAbsInfoMap.find(event.code)); 
     226  const input_absinfo& info = (*iter).second; 
     227  NumStationMap::const_iterator ns = mStations.begin(); 
    105228 
    106229  switch (event.code) { 
     
    113236    if (iter != mAbsInfoMap.end()) 
    114237    { 
    115       const input_absinfo& info = (*iter).second; 
     238      //info = (*iter).second; 
    116239      normalized_value = (float)event.value / (float)(info.maximum - info.minimum); 
    117240    } 
     
    121244    else normalized_value = 0.0f; 
    122245    break; 
     246  case ABS_X: 
     247  case ABS_WHEEL: 
     248  case ABS_TILT_X: 
     249    normalized_value = 2.0f* ((float)event.value -(float)info.minimum) / (float)(info.maximum + info.minimum ) - 1.0f; 
     250    break; 
     251  case ABS_Y: 
     252  case ABS_TILT_Y: 
     253    normalized_value = -2.0f* ((float)event.value -(float)info.minimum) / (float)(info.maximum + info.minimum ) + 1.0f; 
     254    break; 
     255  case ABS_MISC: 
     256    std::cout << event.value << std::endl; 
     257    if (iter != mAbsInfoMap.end()) 
     258    { 
     259       //info = (*iter).second; 
     260       std::cout << info.maximum << " <-max min-> " << info.minimum << std::endl; 
     261    } 
     262    break; 
    123263  default: 
    124264    normalized_value = HIDInput::normalizeAbsValue(event); 
     
    127267  return normalized_value; 
    128268} 
     269 
     270/*virtual*/ int 
     271av::daemon::WacomTablet::parse_features() 
     272{ 
     273  if (HIDInput::parse_features()) 
     274    mToggleReset = HIDInput::scanForOptionalFeature<bool>("toggle-reset", false); 
     275  std::cout << "Parse Features, mToggleReset = " << mToggleReset << std::endl; 
     276  return 1; 
     277} 
  • trunk/avango-menu/python/avango/menu/layout/_PushButtonLayouter.py

    r1 r20  
    9898        self._last_select = self.Select.value 
    9999 
    100  
    101100    def push_button_enable_changed(self): 
    102101        self.super().layout_base_enable_changed() 
  • trunk/examples/daemon/wacom-app.py

    r1 r20  
    7777    PenTiltY = avango.SFFloat() 
    7878    UnknownRelWheel = avango.SFFloat() 
     79    Ratio = avango.SFFloat() 
    7980    Button0 = avango.SFBool() 
    8081    Button1 = avango.SFBool() 
     
    101102    ButtonStylus = avango.SFBool() 
    102103    ButtonStylus2 = avango.SFBool() 
     104    Proximity = avango.SFBool() 
     105    Matrix = avango.osg.SFMatrix() 
    103106 
    104107    def evaluate(self): 
     
    119122        print "PenTiltY: " + str(self.PenTiltY.value) 
    120123        print "UnknownRelWheel: " + str(self.UnknownRelWheel.value) 
     124        print "Ratio: " + str(self.Ratio.value) 
    121125        print "---Buttons-------------------------------------" 
    122126        print "Button0: " + str(self.Button0.value) 
     
    144148        print "ButtonStylus: " + str(self.ButtonStylus.value) 
    145149        print "ButtonStylus2: " + str(self.ButtonStylus2.value) 
     150        print "Proximity: " + str(self.Proximity.value) 
     151        print "Matrix: " + str(self.Matrix.value) 
    146152 
    147153        if (self.ButtonAirbrush.value): 
     
    152158        transform.Matrix.value = transform.Matrix.value*\ 
    153159            avango.osg.make_rot_mat(1.047*self.PenTiltX.value, avango.osg.Vec3(0,1,0))*\ 
    154             avango.osg.make_rot_mat(1.047*self.PenTiltY.value,avango.osg.Vec3(1,0,0))*\ 
    155             avango.osg.make_trans_mat(1*self.PenX.value,-1*self.PenY.value,-10) 
     160            avango.osg.make_rot_mat(-1.047*self.PenTiltY.value,avango.osg.Vec3(1,0,0))*\ 
     161            avango.osg.make_trans_mat(1*self.PenX.value,self.PenY.value,-10) 
    156162        sphereTrans2.Matrix.value = avango.osg.make_trans_mat(0,0,0.25 - (0.175*self.PenPressure.value)) 
    157163        sphereTrans3.Matrix.value = avango.osg.make_trans_mat(0,0,0.4 - (0.25*self.PenPressure.value)) 
     
    184190tablet.PenTiltY.connect_from(sensor.Value10) 
    185191tablet.UnknownRelWheel.connect_from(sensor.Value11) 
     192tablet.Ratio.connect_from(sensor.Value12) 
    186193tablet.Button0.connect_from(sensor.Button0) 
    187194tablet.Button1.connect_from(sensor.Button1) 
     
    208215tablet.ButtonStylus.connect_from(sensor.Button22) 
    209216tablet.ButtonStylus2.connect_from(sensor.Button23) 
     217tablet.Proximity.connect_from(sensor.Button24) 
     218tablet.Matrix.connect_from(sensor.Matrix) 
    210219 
    211220# set up viewing 
  • trunk/examples/daemon/wacom-daemon.py

    r1 r20  
    3939 
    4040# configure a tablet device 
    41 wacom = avango.daemon.WacomIntuos3() 
     41wacom = avango.daemon.WacomTablet() 
    4242wacom.station = station 
    4343wacom.device = '/dev/input/wacom' 
    44 #wacom.norm_abs = 'False' 
     44wacom.norm_abs = 'True' 
     45wacom.toggle_reset = 'False' 
    4546 
    4647#input events are configures automatically in WacomIntuos3 
     
    5960#wacom.values[10] = "EV_ABS::ABS_TILT_Y" #abs pen tilt Y axis 
    6061#wacom.values[11] = "EV_REL::REL_WHEEL" 
     62#wacom.values[12] = "AspectRatio" #Width/Height of tablet CUSTOM 
    6163 
    6264# map incoming key events to station buttons 
     
    8587#wacom.buttons[22] = "EV_KEY::BTN_STYLUS" 
    8688#wacom.buttons[23] = "EV_KEY::BTN_STYLUS2" 
     89#wacom.buttons[24] = "Proximity, True if anything active on tablet, CUSTOM 
    8790 
    8891 
Note: See TracChangeset for help on using the changeset viewer.