Changeset 20
- Timestamp:
- 10/17/08 14:34:26 (4 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
-
avango-daemon/include/avango/daemon/HIDInput.h (modified) (2 diffs)
-
avango-daemon/include/avango/daemon/WacomTablet.h (modified) (3 diffs)
-
avango-daemon/python/__init__.py (modified) (1 diff)
-
avango-daemon/python/_daemon.cpp (modified) (2 diffs)
-
avango-daemon/src/avango/daemon/HIDInput.cpp (modified) (3 diffs)
-
avango-daemon/src/avango/daemon/WacomTablet.cpp (modified) (7 diffs)
-
avango-menu/python/avango/menu/layout/_PushButtonLayouter.py (modified) (1 diff)
-
examples/daemon/wacom-app.py (modified) (7 diffs)
-
examples/daemon/wacom-daemon.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/avango-daemon/include/avango/daemon/HIDInput.h
r1 r20 221 221 virtual float normalizeAbsValue(const struct input_event& event) const; 222 222 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 223 232 private: 224 233 225 bool stationLooksForEvent(int station_index, const struct input_event& event) const;234 // bool stationLooksForEvent(int station_index, const struct input_event& event) const; 226 235 const HIDMapping& getStationHIDMapping(int station_index) const; 227 236 const HIDLEDMapping& getStationHIDLEDMapping(int station_index) const; … … 231 240 232 241 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(); 237 245 238 246 }; -
trunk/avango-daemon/include/avango/daemon/WacomTablet.h
r1 r20 33 33 34 34 #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> 35 39 36 40 namespace av … … 52 56 WacomTablet(); 53 57 58 54 59 protected: 55 60 … … 65 70 66 71 /** 72 * overrides readloop() from av::daemon::HIDInput, used to create a transformation Matrix 73 * from pen input 74 */ 75 void readLoop(); 76 77 /** 67 78 * overrides normalizeAbsValue from HIDInput, used to perform custom normalization 68 79 * of some values 69 80 */ 70 81 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; 71 94 }; 72 95 } -
trunk/avango-daemon/python/__init__.py
r1 r20 159 159 mydev.value[0] = \'EV_REL::REL_X\'. All appearing value und button events of a tablet 160 160 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.""" 162 162 def __init__(self): 163 163 super(WacomTablet, self).__init__() -
trunk/avango-daemon/python/_daemon.cpp
r1 r20 74 74 std::string getTimeoutFeature(av::daemon::Device* self) { return self->queryFeature("timeout"); } 75 75 std::string getPortFeature(av::daemon::Device* self) { return self->queryFeature("port"); } 76 std::string getToggleResetFeature(av::daemon::Device* self) { return self->queryFeature("toggle-reset"); } 76 77 77 78 // 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 } 78 85 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)); } 81 89 void setResetRelCycleFeature(av::daemon::Device* self, std::string value) { self->configureFeature("reset-rel-values-cycle", value); } 82 90 void setTimeoutFeature(av::daemon::Device* self, std::string value) { self->configureFeature("timeout", value); } 83 91 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)); } 84 93 85 94 // set LED states … … 175 184 class_<av::daemon::WacomTablet, av::Link<av::daemon::WacomTablet>, bases<av::daemon::HIDInput>, boost::noncopyable >("_WacomTabletHelper", 176 185 "A helper class that provides some basic properties and functions inherited from HIDInput.") 186 .add_property("toggle_reset", &::getToggleResetFeature, &::setToggleResetFeature) 177 187 ; 178 188 -
trunk/avango-daemon/src/avango/daemon/HIDInput.cpp
r18 r20 27 27 #include <cstring> 28 28 #include <fcntl.h> 29 #include <iostream> 29 30 #include <sstream> 30 31 #include <iomanip> … … 269 270 } 270 271 271 int272 /*virtual*/ int 272 273 av::daemon::HIDInput::parse_features() 273 274 { … … 285 286 mResetRelCycle = scanForOptionalFeature<int>("reset-rel-values-cycle", 0); 286 287 mTimeout = scanForOptionalFeature<unsigned int>("timeout", 200); 287 288 std::cout << "Parse Features, mNormAbs = " << mNormAbs << std::endl; 288 289 return 1; 289 290 } -
trunk/avango-daemon/src/avango/daemon/WacomTablet.cpp
r1 r20 37 37 38 38 av::daemon::WacomTablet::WacomTablet() 39 {} 39 { 40 } 40 41 41 42 av::daemon::WacomTablet::~WacomTablet() … … 69 70 configureFeature(station + "10", "EV_ABS::ABS_TILT_Y"); // Pen tilt y axis 70 71 configureFeature(station + "11", "EV_REL::REL_WHEEL"); // Relative Wheel on mouse 72 configureFeature(station + "12", "AspectRatio"); // Ratio of Width/Height of Tablet 71 73 72 74 //auto-configure buttons … … 96 98 configureFeature(station + "22", "EV_KEY::BTN_STYLUS"); // 1st side button on pen/airbrush 97 99 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 104 void 105 av::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 122 av::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 98 219 } 99 220 … … 103 224 float normalized_value = 0.0f; 104 225 HIDInput::AbsInfoMap::const_iterator iter (mAbsInfoMap.find(event.code)); 226 const input_absinfo& info = (*iter).second; 227 NumStationMap::const_iterator ns = mStations.begin(); 105 228 106 229 switch (event.code) { … … 113 236 if (iter != mAbsInfoMap.end()) 114 237 { 115 const input_absinfo&info = (*iter).second;238 //info = (*iter).second; 116 239 normalized_value = (float)event.value / (float)(info.maximum - info.minimum); 117 240 } … … 121 244 else normalized_value = 0.0f; 122 245 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; 123 263 default: 124 264 normalized_value = HIDInput::normalizeAbsValue(event); … … 127 267 return normalized_value; 128 268 } 269 270 /*virtual*/ int 271 av::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 98 98 self._last_select = self.Select.value 99 99 100 101 100 def push_button_enable_changed(self): 102 101 self.super().layout_base_enable_changed() -
trunk/examples/daemon/wacom-app.py
r1 r20 77 77 PenTiltY = avango.SFFloat() 78 78 UnknownRelWheel = avango.SFFloat() 79 Ratio = avango.SFFloat() 79 80 Button0 = avango.SFBool() 80 81 Button1 = avango.SFBool() … … 101 102 ButtonStylus = avango.SFBool() 102 103 ButtonStylus2 = avango.SFBool() 104 Proximity = avango.SFBool() 105 Matrix = avango.osg.SFMatrix() 103 106 104 107 def evaluate(self): … … 119 122 print "PenTiltY: " + str(self.PenTiltY.value) 120 123 print "UnknownRelWheel: " + str(self.UnknownRelWheel.value) 124 print "Ratio: " + str(self.Ratio.value) 121 125 print "---Buttons-------------------------------------" 122 126 print "Button0: " + str(self.Button0.value) … … 144 148 print "ButtonStylus: " + str(self.ButtonStylus.value) 145 149 print "ButtonStylus2: " + str(self.ButtonStylus2.value) 150 print "Proximity: " + str(self.Proximity.value) 151 print "Matrix: " + str(self.Matrix.value) 146 152 147 153 if (self.ButtonAirbrush.value): … … 152 158 transform.Matrix.value = transform.Matrix.value*\ 153 159 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) 156 162 sphereTrans2.Matrix.value = avango.osg.make_trans_mat(0,0,0.25 - (0.175*self.PenPressure.value)) 157 163 sphereTrans3.Matrix.value = avango.osg.make_trans_mat(0,0,0.4 - (0.25*self.PenPressure.value)) … … 184 190 tablet.PenTiltY.connect_from(sensor.Value10) 185 191 tablet.UnknownRelWheel.connect_from(sensor.Value11) 192 tablet.Ratio.connect_from(sensor.Value12) 186 193 tablet.Button0.connect_from(sensor.Button0) 187 194 tablet.Button1.connect_from(sensor.Button1) … … 208 215 tablet.ButtonStylus.connect_from(sensor.Button22) 209 216 tablet.ButtonStylus2.connect_from(sensor.Button23) 217 tablet.Proximity.connect_from(sensor.Button24) 218 tablet.Matrix.connect_from(sensor.Matrix) 210 219 211 220 # set up viewing -
trunk/examples/daemon/wacom-daemon.py
r1 r20 39 39 40 40 # configure a tablet device 41 wacom = avango.daemon.Wacom Intuos3()41 wacom = avango.daemon.WacomTablet() 42 42 wacom.station = station 43 43 wacom.device = '/dev/input/wacom' 44 #wacom.norm_abs = 'False' 44 wacom.norm_abs = 'True' 45 wacom.toggle_reset = 'False' 45 46 46 47 #input events are configures automatically in WacomIntuos3 … … 59 60 #wacom.values[10] = "EV_ABS::ABS_TILT_Y" #abs pen tilt Y axis 60 61 #wacom.values[11] = "EV_REL::REL_WHEEL" 62 #wacom.values[12] = "AspectRatio" #Width/Height of tablet CUSTOM 61 63 62 64 # map incoming key events to station buttons … … 85 87 #wacom.buttons[22] = "EV_KEY::BTN_STYLUS" 86 88 #wacom.buttons[23] = "EV_KEY::BTN_STYLUS2" 89 #wacom.buttons[24] = "Proximity, True if anything active on tablet, CUSTOM 87 90 88 91
Note: See TracChangeset
for help on using the changeset viewer.
