luna-sysmgr-common
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HostArm.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
30 #ifndef HOSTARM_H
31 #define HOSTARM_H
32 
33 #include <nyx/nyx_client.h>
34 
35 #include "Common.h"
36 
37 #include "HostBase.h"
38 #include "Event.h"
39 #include "CustomEvents.h"
40 #include "NyxSensorConnector.h"
41 #include "NyxInputControl.h"
42 #include "NyxLedControl.h"
43 
44 #if defined(HAS_HIDLIB)
45 #include "HidLib.h"
46 #endif
47 #include "lunaservice.h"
48 
49 #include <qsocketnotifier.h>
50 #include <QObject>
51 
52 #if defined(USE_KEY_FILTER) || defined(USE_MOUSE_FILTER)
53 #include <QApplication>
54 #include <QWidget>
55 #endif // USE_KEY_FILTER || USE_MOUSE_FILTER
56 
57 #if defined(USE_KEY_FILTER)
58 #include <SysMgrDeviceKeydefs.h>
59 
60 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
61  #define KEYS Qt
62 #else
63  #define KEYS
64 #endif // QT_VERSION
65 
66 #include <QKeyEvent>
67 #endif // USE_KEY_FILTER
68 
69 #if defined(USE_MOUSE_FILTER)
70 #include <QMouseEvent>
71 #endif // USE_MOUSE_FILTER
72 
73 #define KEYBOARD_TOKEN "com.palm.properties.KEYoBRD"
74 #define KEYBOARD_QWERTY "z"
75 #define KEYBOARD_AZERTY "w"
76 #define KEYBOARD_QWERTZ "y"
77 
78 #define HIDD_LS_KEYPAD_URI "palm://com.palm.hidd/HidKeypad/"
79 #define HIDD_RINGER_URI HIDD_LS_KEYPAD_URI"RingerState"
80 #define HIDD_SLIDER_URI HIDD_LS_KEYPAD_URI"SliderState"
81 #define HIDD_HEADSET_URI HIDD_LS_KEYPAD_URI"HeadsetState"
82 #define HIDD_HEADSET_MIC_URI HIDD_LS_KEYPAD_URI"HeadsetMicState"
83 #define HIDD_GET_STATE "{\"mode\":\"get\"}"
84 
85 #define HIDD_LS_ACCELEROMETER_URI "palm://com.palm.hidd/HidAccelerometer/"
86 #define HIDD_ACCELEROMETER_RANGE_URI HIDD_LS_ACCELEROMETER_URI"Range"
87 
88 #define HIDD_ACCELEROMETER_MODE HIDD_LS_ACCELEROMETER_URI"Mode"
89 #define HIDD_ACCELEROMETER_INTERRUPT_MODE HIDD_LS_ACCELEROMETER_URI"InterruptMode"
90 #define HIDD_ACCELEROMETER_POLL_INTERVAL HIDD_LS_ACCELEROMETER_URI"PollInterval"
91 #define HIDD_ACCELEROMETER_TILT_TIMER HIDD_LS_ACCELEROMETER_URI"TiltTimer"
92 #define HIDD_ACCELEROMETER_SET_DEFAULT_TILT_TIMER "{\"mode\":\"set\",\"value\":6}"
93 #define HIDD_ACCELEROMETER_SET_DEFAULT_INTERVAL "{\"mode\":\"set\",\"value\":2000}"
94 #define HIDD_ACCELEROMETER_SET_DEFAULT_MODE "{\"mode\":\"set\",\"value\":\"all\"}"
95 #define HIDD_ACCELEROMETER_SET_POLL "{\"mode\":\"set\",\"value\":\"poll\"}"
96 
97 // Same as default kernel values
98 #define REPEAT_DELAY 250
99 #define REPEAT_PERIOD 33
100 
101 #if 0
102 // TODO: These don't get included from <linux/input.h> because the OE build
103 // picks up the include files from the codesourcery toolchain, not our modified headers
104 #define SW_RINGER 0x5
105 #define SW_SLIDER 0x6
106 #define SW_OPTICAL 0x7
107 #define ABS_ORIENTATION 0x30
108 
109 // TODO: these should come from hidd headers
110 #define EV_GESTURE 0x06
111 #define EV_FINGERID 0x07
112 #endif
113 
114 #if defined(USE_MOUSE_FILTER)
115 class HostArmQtMouseFilter : public QObject
116 {
117  Q_OBJECT
118 
119 protected:
120  bool eventFilter(QObject *obj, QEvent *event)
121  {
122  bool handled = false;
123  if(event->type() == QEvent::MouseButtonRelease ||
124  event->type() == QEvent::MouseButtonPress ||
125  event->type() == QEvent::MouseMove)
126  {
127  QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
128  Qt::KeyboardModifiers modifiers = mouseEvent->modifiers();
129  if(modifiers & Qt::ControlModifier)
130  {
131  modifiers &= ~Qt::ControlModifier;
132  modifiers |= Qt::AltModifier;
133  mouseEvent->setModifiers(modifiers);
134  }
135  if(event->type() == QEvent::MouseButtonRelease && mouseEvent->button() == Qt::LeftButton)
136  {
137  QWidget *grabber = QWidget::mouseGrabber();
138  if(grabber)
139  {
140  grabber->releaseMouse();
141  }
142  }
143  }
144  return handled;
145  }
146 };
147 #endif // USE_MOUSE_FILTER
148 
149 #if defined(USE_KEY_FILTER)
150 class HostArmQtKeyFilter : public QObject
151 {
152  Q_OBJECT
153 
154 protected:
155  bool eventFilter(QObject *obj, QEvent* event)
156  {
157  bool handled = false;
158  if( (event->type() == QEvent::KeyPress) || (event->type() == QEvent::KeyRelease) )
159  {
160  int keyToRemapTo = 0;
161  QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
162 
163  switch(keyEvent->key())
164  {
165  case Qt::Key_Home:
166  keyToRemapTo = KEYS::Key_CoreNavi_Home;
167  break;
168  case Qt::Key_Escape:
169  keyToRemapTo = KEYS::Key_CoreNavi_Back;
170  break;
171  case Qt::Key_End:
172  keyToRemapTo = KEYS::Key_CoreNavi_Launcher;
173  break;
174  case Qt::Key_Pause:
175 // QT5_TODO: Are these two equivalent?
176 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
177  keyToRemapTo = KEYS::Key_Power;
178 #else
179  keyToRemapTo = KEYS::Key_HardPower;
180 #endif
181  break;
182  }
183  if(keyToRemapTo > 0) {
184  QWidget* window = NULL;
185  window = QApplication::focusWidget();
186  if(window)
187  {
188  QApplication::postEvent(window, new QKeyEvent(event->type(), keyToRemapTo, 0));
189  }
190  handled = true;
191  }
192  }
193  else if(event->type() == QEvent::MouseButtonRelease)
194  {
195 #if defined(USE_MOUSE_FILTER)
196  QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
197  if(mouseEvent->button() == Qt::LeftButton)
198  {
199  QWidget *grabber = QWidget::mouseGrabber();
200  if(grabber)
201  {
202  grabber->releaseMouse();
203  }
204  }
205 #endif // USE_MOUSE_FILTER
206  }
207  return handled;
208  }
209 };
210 #endif // USE_KEY_FILTER
211 
212 typedef enum
213 {
214  BACK = 0,
226 } GestureType_t;
227 
231 class HostArm : public HostBase, public NYXConnectorObserver
232 {
233  Q_OBJECT
234 public:
240  HostArm();
241 
245  virtual ~HostArm();
246 
247  //Documented in parent
248  virtual void init(int w, int h);
249 
250  //Documented in parent
251  virtual void show();
252 
253  //Documented in parent
254  virtual int getNumberOfSwitches() const;
255 
256 #if defined(HAS_HIDLIB)
257 
271  virtual void getInitialSwitchStates(void);
272 #endif
273 
288  int readHidEvents(int fd, struct input_event* eventBuf, int bufSize);
289 
299  virtual const char* hardwareName() const;
300 
301  //Documented in parent
302  virtual InputControl* getInputControlALS();
303 
304  //Documented in parent
306 
307  //Documented in parent
309 
310  //Documented in parent
312 
313  //Documented in parent
315 
316  //Documented in parent
318 
324  virtual void OrientationSensorOn(bool enable);
325 
326 
327  //Documented in parent
328  virtual void setBluetoothKeyboardActive(bool active);
329 
330  //Documented in parent
331  virtual bool bluetoothKeyboardActive() const;
332 
333 protected:
334 
335 #if defined(USE_KEY_FILTER)
336  HostArmQtKeyFilter* m_keyFilter;
337 #endif // USE_KEY_FILTER
338 #if defined(USE_MOUSE_FILTER)
339  HostArmQtMouseFilter* m_mouseFilter;
340 #endif
341 
350  QSocketNotifier* m_nyxLightNotifier;
351 
360  QSocketNotifier* m_nyxProxNotifier;
361 
369  virtual void wakeUpLcd();
370 
380  virtual int screenX(int rawX, Event::Type type) { return rawX; }
381 
391  virtual int screenY(int rawY, Event::Type type) { return rawY; }
392 
393  //Documented in parent
394  virtual void setCentralWidget(QWidget* view);
395 
396 #if defined(HAS_HIDLIB)
397 
407  HidHardwareRevision_t m_hwRev;
408 
419  HidHardwarePlatform_t m_hwPlatform;
420 #endif
421 
428  int m_fb0Fd;
429 
436  int m_fb1Fd;
437 
443  void* m_fb0Buffer;
444 
457 
464  void* m_fb1Buffer;
465 
478 
485  LSHandle* m_service;
486 
494 
504 
512 
522 
531 
539 
547 
548 protected:
563  void setupInput(void);
564 
580  void shutdownInput(void);
581 
587  void startService(void);
588 
594  void stopService(void);
595 
610  void disableScreenBlanking();
611 
612  //Documented in parent
613  virtual void flip();
614 
615  //Documented in parent
616  virtual QImage takeScreenShot() const;
617 
618  //Documented in parent
619  virtual QImage takeAppDirectRenderingScreenShot() const;
620 
621  //Documented in parent
622  virtual void setAppDirectRenderingLayerEnabled(bool enable);
623 
624  //Documented in parent
625  virtual void setRenderingLayerEnabled(bool enable);
626 
646  static bool getMsgValueInt(LSMessage* msg, int& value);
647 
648 #if defined(HAS_HIDLIB)
649 
666  static bool switchStateCallback(LSHandle* handle, LSMessage* msg, void* data);
667 #endif
668 
674  virtual void NYXDataAvailable (NYXConnectorBase::Sensor aSensorType);
675 
676 protected Q_SLOTS:
692  void readALSData();
693 
710  void readProxData();
711 };
712 
713 #endif /* HOSTARM_H */