Revision: 49266
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49266
Author:   alexk
Date:     2012-07-26 21:49:58 +0000 (Thu, 26 Jul 2012)
Log Message:
-----------
Adding Initial sensor API in GHOST

Test sensor availibility:
getSensorsAvailability()

Enable or disable sensors:
setSensorsState()

Sensors are disabled by default

You need to supply type of sensor:
1 - Accelerometer
2 - Gyroscope
3 - Magnetic Sensor
(Please don't switch order, just append new sensors. It is hardcoded in Android)

Data is stored as a vectror in GHOST_TEventSensorData
with dimension of 3 for Accelerometer, Gyroscope and Magnetic Sensor
Other sensors can have differnt dimensions

Modified Paths:
--------------
    branches/soc-2012-swiss_cheese/intern/ghost/CMakeLists.txt
    branches/soc-2012-swiss_cheese/intern/ghost/GHOST_C-api.h
    branches/soc-2012-swiss_cheese/intern/ghost/GHOST_ISystem.h
    branches/soc-2012-swiss_cheese/intern/ghost/GHOST_Types.h
    branches/soc-2012-swiss_cheese/intern/ghost/intern/GHOST_C-api.cpp
    branches/soc-2012-swiss_cheese/intern/ghost/intern/GHOST_System.cpp

Added Paths:
-----------
    branches/soc-2012-swiss_cheese/intern/ghost/intern/GHOST_EventSensor.h

Modified: branches/soc-2012-swiss_cheese/intern/ghost/CMakeLists.txt
===================================================================
--- branches/soc-2012-swiss_cheese/intern/ghost/CMakeLists.txt  2012-07-26 
21:22:42 UTC (rev 49265)
+++ branches/soc-2012-swiss_cheese/intern/ghost/CMakeLists.txt  2012-07-26 
21:49:58 UTC (rev 49266)
@@ -75,6 +75,7 @@
        intern/GHOST_EventString.h
        intern/GHOST_EventTrackpad.h
        intern/GHOST_EventWheel.h
+       intern/GHOST_EventSensor.h
        intern/GHOST_ModifierKeys.h
        intern/GHOST_System.h
        intern/GHOST_SystemPaths.h

Modified: branches/soc-2012-swiss_cheese/intern/ghost/GHOST_C-api.h
===================================================================
--- branches/soc-2012-swiss_cheese/intern/ghost/GHOST_C-api.h   2012-07-26 
21:22:42 UTC (rev 49265)
+++ branches/soc-2012-swiss_cheese/intern/ghost/GHOST_C-api.h   2012-07-26 
21:49:58 UTC (rev 49266)
@@ -420,7 +420,31 @@
                                            GHOST_TButtonMask mask,
                                            int *isDown);
 
+/***************************************************************************************
+ * Hardware Sensor operations
+ 
***************************************************************************************/
 
+/**
+ * Returns the availability of sensor.
+ * @param systemhandle The handle to the system
+ * @param type         The type of sensor.
+ * @return                     Indication of availability.
+ */
+extern GHOST_TSuccess GHOST_getSensorsAvailability(GHOST_SystemHandle 
systemhandle,
+                                                                               
                   GHOST_TSensorTypes type);
+
+/**
+ * Enables or disables specific sensor.
+ * @param systemhandle The handle to the system
+ * @param type         The type of sensor.
+ * @param enable       1 = enable, 0 = disable
+ * @return                     Indication of success.
+ */
+extern GHOST_TSuccess GHOST_setSensorsState(GHOST_SystemHandle systemhandle,
+                                                                               
        GHOST_TSensorTypes type,
+                                                                               
        int enable);
+
+
 
/***************************************************************************************
  * Drag'n'drop operations
  
***************************************************************************************/

Modified: branches/soc-2012-swiss_cheese/intern/ghost/GHOST_ISystem.h
===================================================================
--- branches/soc-2012-swiss_cheese/intern/ghost/GHOST_ISystem.h 2012-07-26 
21:22:42 UTC (rev 49265)
+++ branches/soc-2012-swiss_cheese/intern/ghost/GHOST_ISystem.h 2012-07-26 
21:49:58 UTC (rev 49266)
@@ -367,7 +367,27 @@
         */
        virtual GHOST_TSuccess getButtonState(GHOST_TButtonMask mask, bool& 
isDown) const = 0;
 
+
+       
/***************************************************************************************
+        * Hardware Sensor operations
+        
***************************************************************************************/
+
        /**
+        * Returns the availability of sensor.
+        * @param type          The type of sensor.
+        * @return                      Indication of availability.
+        */
+       virtual GHOST_TSuccess getSensorsAvailability(GHOST_TSensorTypes type) 
= 0;
+
+       /**
+        * Enables or disables specific sensor.
+        * @param type          The type of sensor.
+        * @param enable        1 = enable, 0 = disable
+        * @return                      Indication of success.
+        */
+       virtual GHOST_TSuccess setSensorsState(GHOST_TSensorTypes type, int 
enable) = 0;
+
+       /**
         * Toggles console
         * @action      0 - Hides
         *                      1 - Shows

Modified: branches/soc-2012-swiss_cheese/intern/ghost/GHOST_Types.h
===================================================================
--- branches/soc-2012-swiss_cheese/intern/ghost/GHOST_Types.h   2012-07-26 
21:22:42 UTC (rev 49265)
+++ branches/soc-2012-swiss_cheese/intern/ghost/GHOST_Types.h   2012-07-26 
21:49:58 UTC (rev 49266)
@@ -170,6 +170,8 @@
        GHOST_kEventKeyUp,
 //     GHOST_kEventKeyAuto,
 
+       GHOST_kEventSensor,
+
        GHOST_kEventQuit,
 
        GHOST_kEventWindowClose,
@@ -496,7 +498,20 @@
        char utf8_buf[6];
 } GHOST_TEventKeyData;
 
+typedef enum {
+       GHOST_kSensorAccelerometer = 1,
+       GHOST_kSensorGyroscope,
+       GHOST_kSensorMagnetic
+
+} GHOST_TSensorTypes;
+
 typedef struct {
+       GHOST_TSensorTypes type;
+       float dv[3];
+
+} GHOST_TEventSensorData;
+
+typedef struct {
        /** Number of pixels on a line. */
        GHOST_TUns32 xPixels;
        /** Number of lines. */
@@ -508,6 +523,7 @@
 } GHOST_DisplaySetting;
 
 
+
 #ifdef _WIN32
 typedef long GHOST_TEmbedderWindowID;
 #endif // _WIN32

Modified: branches/soc-2012-swiss_cheese/intern/ghost/intern/GHOST_C-api.cpp
===================================================================
--- branches/soc-2012-swiss_cheese/intern/ghost/intern/GHOST_C-api.cpp  
2012-07-26 21:22:42 UTC (rev 49265)
+++ branches/soc-2012-swiss_cheese/intern/ghost/intern/GHOST_C-api.cpp  
2012-07-26 21:49:58 UTC (rev 49266)
@@ -403,6 +403,23 @@
 }
 
 
+extern GHOST_TSuccess GHOST_getSensorsAvailability(GHOST_SystemHandle 
systemhandle,
+                                                                               
                   GHOST_TSensorTypes type)
+{
+       GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
+
+       return system->getSensorsAvailability(type);
+}
+
+extern GHOST_TSuccess GHOST_setSensorsState(GHOST_SystemHandle systemhandle,
+                                                                               
        GHOST_TSensorTypes type,
+                                                                               
        int enable)
+{
+       GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
+
+       return system->setSensorsState(type, enable && 1);
+}
+
 void GHOST_setAcceptDragOperation(GHOST_WindowHandle windowhandle, GHOST_TInt8 
canAccept)
 {
        GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;

Added: branches/soc-2012-swiss_cheese/intern/ghost/intern/GHOST_EventSensor.h
===================================================================
--- branches/soc-2012-swiss_cheese/intern/ghost/intern/GHOST_EventSensor.h      
                        (rev 0)
+++ branches/soc-2012-swiss_cheese/intern/ghost/intern/GHOST_EventSensor.h      
2012-07-26 21:49:58 UTC (rev 49266)
@@ -0,0 +1,91 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2012 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *                 Alexandr Kuznetsov
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file ghost/intern/GHOST_EventSensor.h
+ *  \ingroup GHOST
+ * Declaration of GHOST_EventSensor class.
+ */
+
+#ifndef __GHOST_EVENTSENSOR_H__
+#define __GHOST_EVENTSENSOR_H__
+
+#include "GHOST_Event.h"
+#include "GHOST_Types.h"
+
+/**
+ * Hardware sensor event.
+ * Like Acclerometer and gyroscope.
+ * Acceleromoter and gyroscope have 3D vector
+ * While others have  1D vectors (and data for other fields is not specified)
+ */
+class GHOST_EventSensor : public GHOST_Event
+{
+public:
+       GHOST_EventSensor(GHOST_TUns64 msec, GHOST_IWindow *window, 
GHOST_TSensorTypes subtype, float *v)
+               : GHOST_Event(msec, GHOST_kEventSensor, window)
+       {
+               m_SensorEventData.type = subtype;
+
+               m_SensorEventData.dv[0] = v[0];
+               m_SensorEventData.dv[1] = v[1];
+               m_SensorEventData.dv[2] = v[2];
+
+               m_data = &m_SensorEventData;
+       }
+
+
+       GHOST_EventSensor(GHOST_TUns64 msec, GHOST_IWindow *window, 
GHOST_TSensorTypes subtype, float v)
+               : GHOST_Event(msec, GHOST_kEventSensor, window)
+       {
+               m_SensorEventData.type = subtype;
+
+               m_SensorEventData.dv[0] = v;
+
+               m_data = &m_SensorEventData;
+       }
+
+
+       GHOST_EventSensor(GHOST_TUns64 msec, GHOST_IWindow *window, 
GHOST_TSensorTypes subtype, float v1, float v2, float v3)
+               : GHOST_Event(msec, GHOST_kEventSensor, window)
+       {
+               m_SensorEventData.type = subtype;
+
+               m_SensorEventData.dv[0] = v1;
+               m_SensorEventData.dv[1] = v2;
+               m_SensorEventData.dv[2] = v3;
+
+               m_data = &m_SensorEventData;
+       }
+
+
+protected:
+
+       GHOST_TEventSensorData m_SensorEventData;
+};
+
+
+#endif // __GHOST_EVENTSENSOR_H__
+

Modified: branches/soc-2012-swiss_cheese/intern/ghost/intern/GHOST_System.cpp
===================================================================
--- branches/soc-2012-swiss_cheese/intern/ghost/intern/GHOST_System.cpp 
2012-07-26 21:22:42 UTC (rev 49265)
+++ branches/soc-2012-swiss_cheese/intern/ghost/intern/GHOST_System.cpp 
2012-07-26 21:49:58 UTC (rev 49266)
@@ -298,6 +298,16 @@
        return success;
 }
 
+GHOST_TSuccess GHOST_System::getSensorsAvailability(GHOST_TSensorTypes type)
+{
+       return GHOST_kFailure;
+}
+
+GHOST_TSuccess GHOST_System::setSensorsState(GHOST_TSensorTypes type, int 
enable)
+{
+       return GHOST_kFailure;
+}
+
 GHOST_TSuccess GHOST_System::init()
 {
        m_timerManager = new GHOST_TimerManager();

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to