зеркало из https://github.com/mozilla/pjs.git
Bug 735330 - move device motion from dom/system to hal. r=jdm
* * * Bug 735330 - move device motion from dom/system to hal. cocoa bits. r=jdm * * * Bug 735330 - move device motion from dom/system to hal. window/qt/linux bits. r=jdm * * * Bug 735330 - move device motion from dom/system to hal. move accuracy into sensor data. support compassneedscalibration. r=jdm --HG-- rename : dom/system/cocoa/smslib.h => hal/cocoa/smslib.h rename : dom/system/cocoa/smslib.mm => hal/cocoa/smslib.mm
This commit is contained in:
Родитель
af735f8833
Коммит
357608e890
|
@ -96,8 +96,6 @@
|
|||
#include "nsPermissionManager.h"
|
||||
#endif
|
||||
|
||||
#include "nsDeviceMotion.h"
|
||||
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
#include "APKOpen.h"
|
||||
#endif
|
||||
|
@ -741,28 +739,6 @@ ContentChild::RecvAddPermission(const IPC::Permission& permission)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentChild::RecvDeviceMotionChanged(const long int& type,
|
||||
const double& x, const double& y,
|
||||
const double& z)
|
||||
{
|
||||
nsCOMPtr<nsIDeviceMotionUpdate> dmu =
|
||||
do_GetService(NS_DEVICE_MOTION_CONTRACTID);
|
||||
if (dmu)
|
||||
dmu->DeviceMotionChanged(type, x, y, z);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentChild::RecvNeedsCalibration()
|
||||
{
|
||||
nsCOMPtr<nsIDeviceMotionUpdate> dmu =
|
||||
do_GetService(NS_DEVICE_MOTION_CONTRACTID);
|
||||
if (dmu)
|
||||
dmu->NeedsCalibration();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentChild::RecvScreenSizeChanged(const gfxIntSize& size)
|
||||
{
|
||||
|
|
|
@ -158,12 +158,6 @@ public:
|
|||
|
||||
virtual bool RecvAddPermission(const IPC::Permission& permission);
|
||||
|
||||
virtual bool RecvDeviceMotionChanged(const long int& type,
|
||||
const double& x, const double& y,
|
||||
const double& z);
|
||||
|
||||
virtual bool RecvNeedsCalibration();
|
||||
|
||||
virtual bool RecvScreenSizeChanged(const gfxIntSize &size);
|
||||
|
||||
virtual bool RecvFlushMemory(const nsString& reason);
|
||||
|
|
|
@ -96,7 +96,6 @@
|
|||
#include "mozilla/hal_sandbox/PHalParent.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/unused.h"
|
||||
#include "nsDeviceMotion.h"
|
||||
#include "mozilla/Util.h"
|
||||
|
||||
#include "nsIMemoryReporter.h"
|
||||
|
@ -337,7 +336,6 @@ ContentParent::ActorDestroy(ActorDestroyReason why)
|
|||
}
|
||||
|
||||
RecvRemoveGeolocationListener();
|
||||
RecvRemoveDeviceMotionListener();
|
||||
|
||||
nsCOMPtr<nsIThreadInternal>
|
||||
threadInt(do_QueryInterface(NS_GetCurrentThread()));
|
||||
|
@ -685,11 +683,10 @@ ContentParent::RecvGetShowPasswordSetting(bool* showPassword)
|
|||
return true;
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS4(ContentParent,
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS3(ContentParent,
|
||||
nsIObserver,
|
||||
nsIThreadObserver,
|
||||
nsIDOMGeoPositionCallback,
|
||||
nsIDeviceMotionListener)
|
||||
nsIDOMGeoPositionCallback)
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContentParent::Observe(nsISupports* aSubject,
|
||||
|
@ -1216,26 +1213,6 @@ ContentParent::RecvRemoveGeolocationListener()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentParent::RecvAddDeviceMotionListener()
|
||||
{
|
||||
nsCOMPtr<nsIDeviceMotion> dm =
|
||||
do_GetService(NS_DEVICE_MOTION_CONTRACTID);
|
||||
if (dm)
|
||||
dm->AddListener(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentParent::RecvRemoveDeviceMotionListener()
|
||||
{
|
||||
nsCOMPtr<nsIDeviceMotion> dm =
|
||||
do_GetService(NS_DEVICE_MOTION_CONTRACTID);
|
||||
if (dm)
|
||||
dm->RemoveListener(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContentParent::HandleEvent(nsIDOMGeoPosition* postion)
|
||||
{
|
||||
|
@ -1278,25 +1255,5 @@ ContentParent::RecvScriptError(const nsString& aMessage,
|
|||
return true;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContentParent::OnMotionChange(nsIDeviceMotionData *aDeviceData) {
|
||||
PRUint32 type;
|
||||
double x, y, z;
|
||||
aDeviceData->GetType(&type);
|
||||
aDeviceData->GetX(&x);
|
||||
aDeviceData->GetY(&y);
|
||||
aDeviceData->GetZ(&z);
|
||||
|
||||
unused << SendDeviceMotionChanged(type, x, y, z);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContentParent::NeedsCalibration() {
|
||||
unused << SendNeedsCalibration();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
#include "nsIPrefService.h"
|
||||
#include "nsIPermissionManager.h"
|
||||
#include "nsIDOMGeoPositionCallback.h"
|
||||
#include "nsIDeviceMotion.h"
|
||||
#include "nsIMemoryReporter.h"
|
||||
#include "nsCOMArray.h"
|
||||
|
||||
|
@ -71,7 +70,6 @@ class ContentParent : public PContentParent
|
|||
, public nsIObserver
|
||||
, public nsIThreadObserver
|
||||
, public nsIDOMGeoPositionCallback
|
||||
, public nsIDeviceMotionListener
|
||||
{
|
||||
private:
|
||||
typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost;
|
||||
|
@ -85,7 +83,6 @@ public:
|
|||
NS_DECL_NSIOBSERVER
|
||||
NS_DECL_NSITHREADOBSERVER
|
||||
NS_DECL_NSIDOMGEOPOSITIONCALLBACK
|
||||
NS_DECL_NSIDEVICEMOTIONLISTENER
|
||||
|
||||
TabParent* CreateTab(PRUint32 aChromeFlags);
|
||||
|
||||
|
@ -218,8 +215,6 @@ private:
|
|||
|
||||
virtual bool RecvAddGeolocationListener();
|
||||
virtual bool RecvRemoveGeolocationListener();
|
||||
virtual bool RecvAddDeviceMotionListener();
|
||||
virtual bool RecvRemoveDeviceMotionListener();
|
||||
|
||||
virtual bool RecvConsoleMessage(const nsString& aMessage);
|
||||
virtual bool RecvScriptError(const nsString& aMessage,
|
||||
|
|
|
@ -133,9 +133,6 @@ child:
|
|||
// nsIPermissionManager messages
|
||||
AddPermission(Permission permission);
|
||||
|
||||
DeviceMotionChanged(long type, double x, double y, double z);
|
||||
NeedsCalibration();
|
||||
|
||||
ScreenSizeChanged(gfxIntSize size);
|
||||
|
||||
FlushMemory(nsString reason);
|
||||
|
@ -200,8 +197,6 @@ parent:
|
|||
|
||||
AddGeolocationListener();
|
||||
RemoveGeolocationListener();
|
||||
AddDeviceMotionListener();
|
||||
RemoveDeviceMotionListener();
|
||||
|
||||
ConsoleMessage(nsString message);
|
||||
ScriptError(nsString message, nsString sourceName, nsString sourceLine,
|
||||
|
|
|
@ -53,10 +53,6 @@ ifneq (,$(filter windows,$(MOZ_WIDGET_TOOLKIT)))
|
|||
DIRS = windows
|
||||
endif
|
||||
|
||||
ifneq (,$(filter cocoa,$(MOZ_WIDGET_TOOLKIT)))
|
||||
DIRS = cocoa
|
||||
endif
|
||||
|
||||
ifneq (,$(filter android,$(MOZ_WIDGET_TOOLKIT)))
|
||||
DIRS = android
|
||||
endif
|
||||
|
@ -96,6 +92,6 @@ include $(topsrcdir)/config/config.mk
|
|||
LIBXUL_LIBRARY = 1
|
||||
FORCE_STATIC_LIB = 1
|
||||
EXPORT_LIBRARY = 1
|
||||
|
||||
include $(topsrcdir)/ipc/chromium/chromium-config.mk
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
|
|
@ -53,7 +53,6 @@ include $(topsrcdir)/config/config.mk
|
|||
include $(topsrcdir)/ipc/chromium/chromium-config.mk
|
||||
|
||||
CPPSRCS = \
|
||||
nsDeviceMotionSystem.cpp \
|
||||
AndroidLocationProvider.cpp \
|
||||
nsHapticFeedback.cpp \
|
||||
$(NULL)
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Michael Wu <mwu@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "nsDeviceMotionSystem.h"
|
||||
|
||||
#include "AndroidBridge.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
extern nsDeviceMotionSystem *gDeviceMotionSystem;
|
||||
|
||||
nsDeviceMotionSystem::nsDeviceMotionSystem()
|
||||
{
|
||||
gDeviceMotionSystem = this;
|
||||
}
|
||||
|
||||
nsDeviceMotionSystem::~nsDeviceMotionSystem()
|
||||
{
|
||||
}
|
||||
|
||||
void nsDeviceMotionSystem::Startup()
|
||||
{
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Default)
|
||||
AndroidBridge::Bridge()->EnableDeviceMotion(true);
|
||||
else
|
||||
mozilla::dom::ContentChild::GetSingleton()->
|
||||
SendAddDeviceMotionListener();
|
||||
}
|
||||
|
||||
void nsDeviceMotionSystem::Shutdown()
|
||||
{
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Default)
|
||||
AndroidBridge::Bridge()->EnableDeviceMotion(false);
|
||||
else
|
||||
mozilla::dom::ContentChild::GetSingleton()->
|
||||
SendRemoveDeviceMotionListener();
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Michael Wu <mwu@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsDeviceMotionSystem_h
|
||||
#define nsDeviceMotionSystem_h
|
||||
|
||||
#include "nsDeviceMotion.h"
|
||||
|
||||
class nsDeviceMotionSystem : public nsDeviceMotion
|
||||
{
|
||||
public:
|
||||
nsDeviceMotionSystem();
|
||||
virtual ~nsDeviceMotionSystem();
|
||||
|
||||
private:
|
||||
virtual void Startup();
|
||||
virtual void Shutdown();
|
||||
};
|
||||
|
||||
#endif /* nsDeviceMotionSystem_h */
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is mozilla.org build system.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Mozilla Foundation
|
||||
# Portions created by the Initial Developer are Copyright (C) 2010
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Mike Kristoffersen <mikek@mikek.dk>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = dom
|
||||
LIBRARY_NAME = domsystemcocoa_s
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a static lib.
|
||||
LIBXUL_LIBRARY = 1
|
||||
FORCE_STATIC_LIB = 1
|
||||
EXPORT_LIBRARY = 1
|
||||
|
||||
# We fire the nsDOMDeviceAcceleration
|
||||
LOCAL_INCLUDES += -I$(topsrcdir)/content/events/src
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
CMMSRCS = \
|
||||
smslib.mm \
|
||||
nsDeviceMotionSystem.mm \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -1,59 +0,0 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Doug Turner <dougt@dougt.org>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsDeviceMotionSystem_h
|
||||
#define nsDeviceMotionSystem_h
|
||||
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#include <mach/mach_port.h>
|
||||
|
||||
#include "nsDeviceMotion.h"
|
||||
|
||||
class nsDeviceMotionSystem : public nsDeviceMotion
|
||||
{
|
||||
public:
|
||||
nsDeviceMotionSystem();
|
||||
~nsDeviceMotionSystem();
|
||||
|
||||
void Startup();
|
||||
void Shutdown();
|
||||
|
||||
io_connect_t mSmsConnection;
|
||||
nsCOMPtr<nsITimer> mUpdateTimer;
|
||||
static void UpdateHandler(nsITimer *aTimer, void *aClosure);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,96 +0,0 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Doug Turner <dougt@dougt.org>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsDeviceMotionSystem.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/vm.h>
|
||||
|
||||
#import "smslib.h"
|
||||
#define MEAN_GRAVITY 9.80665
|
||||
#define DEFAULT_SENSOR_POLL 100
|
||||
|
||||
nsDeviceMotionSystem::nsDeviceMotionSystem()
|
||||
{
|
||||
}
|
||||
|
||||
nsDeviceMotionSystem::~nsDeviceMotionSystem()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
nsDeviceMotionSystem::UpdateHandler(nsITimer *aTimer, void *aClosure)
|
||||
{
|
||||
nsDeviceMotionSystem *self = reinterpret_cast<nsDeviceMotionSystem *>(aClosure);
|
||||
if (!self) {
|
||||
NS_ERROR("no self");
|
||||
return;
|
||||
}
|
||||
sms_acceleration accel;
|
||||
smsGetData(&accel);
|
||||
|
||||
self->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION,
|
||||
accel.x * MEAN_GRAVITY,
|
||||
accel.y * MEAN_GRAVITY,
|
||||
accel.z * MEAN_GRAVITY);
|
||||
}
|
||||
|
||||
void nsDeviceMotionSystem::Startup()
|
||||
{
|
||||
smsStartup(nil, nil);
|
||||
smsLoadCalibration();
|
||||
|
||||
mUpdateTimer = do_CreateInstance("@mozilla.org/timer;1");
|
||||
if (mUpdateTimer)
|
||||
mUpdateTimer->InitWithFuncCallback(UpdateHandler,
|
||||
this,
|
||||
DEFAULT_SENSOR_POLL,
|
||||
nsITimer::TYPE_REPEATING_SLACK);
|
||||
}
|
||||
|
||||
void nsDeviceMotionSystem::Shutdown()
|
||||
{
|
||||
if (mUpdateTimer) {
|
||||
mUpdateTimer->Cancel();
|
||||
mUpdateTimer = nsnull;
|
||||
}
|
||||
|
||||
smsShutdown();
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brad Lassey <blassey@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsHapticFeedback.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsHapticFeedback, nsIHapticFeedback)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHapticFeedback::PerformSimpleAction(PRInt32 aType)
|
||||
{
|
||||
// Todo
|
||||
return NS_OK;
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brad Lassey <blassey@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIHapticFeedback.h"
|
||||
|
||||
class nsHapticFeedback : public nsIHapticFeedback
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIHAPTICFEEDBACK
|
||||
};
|
|
@ -34,6 +34,9 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "mozilla/Hal.h"
|
||||
#include "mozilla/HalSensor.h"
|
||||
|
||||
#include "nsDeviceMotion.h"
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
|
@ -47,8 +50,8 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsIPrefService.h"
|
||||
|
||||
using mozilla::TimeStamp;
|
||||
using mozilla::TimeDuration;
|
||||
using namespace mozilla;
|
||||
using namespace hal;
|
||||
|
||||
// also see sDefaultSensorHint in mobile/android/base/GeckoAppShell.java
|
||||
#define DEFAULT_SENSOR_POLL 100
|
||||
|
@ -116,12 +119,15 @@ NS_IMETHODIMP nsDeviceMotionData::GetZ(double *aZ)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsDeviceMotion, nsIDeviceMotion, nsIDeviceMotionUpdate)
|
||||
NS_IMPL_ISUPPORTS1(nsDeviceMotion, nsIDeviceMotion)
|
||||
|
||||
nsDeviceMotion::nsDeviceMotion()
|
||||
: mStarted(false),
|
||||
mEnabled(true)
|
||||
{
|
||||
mLastDOMMotionEventTime = TimeStamp::Now();
|
||||
mLastAccuracy = SENSOR_ACCURACY_UNKNOWN;
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> prefSrv = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefSrv) {
|
||||
bool bvalue;
|
||||
|
@ -219,11 +225,24 @@ NS_IMETHODIMP nsDeviceMotion::RemoveWindowListener(nsIDOMWindow *aWindow)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDeviceMotion::DeviceMotionChanged(PRUint32 type, double x, double y, double z)
|
||||
void
|
||||
nsDeviceMotion::Notify(const mozilla::hal::SensorData& aSensorData)
|
||||
{
|
||||
if (!mEnabled)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
return;
|
||||
|
||||
PRUint32 type = aSensorData.sensor();
|
||||
|
||||
double x = aSensorData.values()[0];
|
||||
double y = aSensorData.values()[1];
|
||||
double z = aSensorData.values()[2];
|
||||
|
||||
SensorAccuracyType accuracy = aSensorData.accuracy();
|
||||
|
||||
if (accuracy <= SENSOR_ACCURACY_LOW && mLastAccuracy >= SENSOR_ACCURACY_MED) {
|
||||
FireNeedsCalibration();
|
||||
}
|
||||
mLastAccuracy = accuracy;
|
||||
|
||||
nsCOMArray<nsIDeviceMotionListener> listeners = mListeners;
|
||||
for (PRUint32 i = listeners.Count(); i > 0 ; ) {
|
||||
|
@ -255,20 +274,19 @@ nsDeviceMotion::DeviceMotionChanged(PRUint32 type, double x, double y, double z)
|
|||
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(windowListeners[i]);
|
||||
if (type == nsIDeviceMotionData::TYPE_ACCELERATION ||
|
||||
type == nsIDeviceMotionData::TYPE_LINEAR_ACCELERATION ||
|
||||
type == nsIDeviceMotionData::TYPE_GYROSCOPE )
|
||||
type == nsIDeviceMotionData::TYPE_GYROSCOPE)
|
||||
FireDOMMotionEvent(domdoc, target, type, x, y, z);
|
||||
else if (type == nsIDeviceMotionData::TYPE_ORIENTATION)
|
||||
FireDOMOrientationEvent(domdoc, target, x, y, z);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDeviceMotion::NeedsCalibration()
|
||||
void
|
||||
nsDeviceMotion::FireNeedsCalibration()
|
||||
{
|
||||
if (!mEnabled)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
return;
|
||||
|
||||
nsCOMArray<nsIDeviceMotionListener> listeners = mListeners;
|
||||
for (PRUint32 i = listeners.Count(); i > 0 ; ) {
|
||||
|
@ -300,8 +318,6 @@ nsDeviceMotion::NeedsCalibration()
|
|||
FireNeedsCalibration(domdoc, target);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -409,6 +425,23 @@ nsDeviceMotion::FireDOMMotionEvent(nsIDOMDocument *domdoc,
|
|||
mLastAccelerationIncluduingGravity = nsnull;
|
||||
mLastAcceleration = nsnull;
|
||||
mLastDOMMotionEventTime = TimeStamp::Now();
|
||||
|
||||
}
|
||||
|
||||
void nsDeviceMotion::Startup()
|
||||
{
|
||||
// Bug 734855 - we probably can make this finer grain
|
||||
// based on the DOM APIs that are being invoked.
|
||||
RegisterSensorObserver(SENSOR_ACCELERATION, this);
|
||||
RegisterSensorObserver(SENSOR_ORIENTATION, this);
|
||||
RegisterSensorObserver(SENSOR_LINEAR_ACCELERATION, this);
|
||||
RegisterSensorObserver(SENSOR_GYROSCOPE, this);
|
||||
}
|
||||
|
||||
void nsDeviceMotion::Shutdown()
|
||||
{
|
||||
UnregisterSensorObserver(SENSOR_ACCELERATION, this);
|
||||
UnregisterSensorObserver(SENSOR_ORIENTATION, this);
|
||||
UnregisterSensorObserver(SENSOR_LINEAR_ACCELERATION, this);
|
||||
UnregisterSensorObserver(SENSOR_GYROSCOPE, this);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@
|
|||
#include "nsIDOMDeviceMotionEvent.h"
|
||||
#include "nsDOMDeviceMotionEvent.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "mozilla/HalSensor.h"
|
||||
|
||||
|
||||
#define NS_DEVICE_MOTION_CID \
|
||||
{ 0xecba5203, 0x77da, 0x465a, \
|
||||
|
@ -56,17 +58,18 @@
|
|||
|
||||
class nsIDOMWindow;
|
||||
|
||||
class nsDeviceMotion : public nsIDeviceMotionUpdate
|
||||
class nsDeviceMotion : public nsIDeviceMotion, public mozilla::hal::ISensorObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDEVICEMOTION
|
||||
NS_DECL_NSIDEVICEMOTIONUPDATE
|
||||
|
||||
nsDeviceMotion();
|
||||
|
||||
virtual ~nsDeviceMotion();
|
||||
|
||||
void Notify(const mozilla::hal::SensorData& aSensorData);
|
||||
|
||||
private:
|
||||
nsCOMArray<nsIDeviceMotionListener> mListeners;
|
||||
nsTArray<nsIDOMWindow*> mWindowListeners;
|
||||
|
@ -79,6 +82,7 @@ private:
|
|||
static void TimeoutHandler(nsITimer *aTimer, void *aClosure);
|
||||
|
||||
protected:
|
||||
void FireNeedsCalibration();
|
||||
|
||||
void FireNeedsCalibration(nsIDOMDocument *domdoc,
|
||||
nsIDOMEventTarget *target);
|
||||
|
@ -96,15 +100,15 @@ private:
|
|||
double y,
|
||||
double z);
|
||||
|
||||
virtual void Startup() = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
void Startup();
|
||||
void Shutdown();
|
||||
|
||||
bool mEnabled;
|
||||
mozilla::TimeStamp mLastDOMMotionEventTime;
|
||||
mozilla::hal::SensorAccuracyType mLastAccuracy;
|
||||
nsRefPtr<nsDOMDeviceAcceleration> mLastAcceleration;
|
||||
nsRefPtr<nsDOMDeviceAcceleration> mLastAccelerationIncluduingGravity;
|
||||
nsRefPtr<nsDOMDeviceRotationRate> mLastRotationRate;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -53,12 +53,6 @@ include $(topsrcdir)/config/config.mk
|
|||
include $(topsrcdir)/ipc/chromium/chromium-config.mk
|
||||
|
||||
|
||||
ifndef MOZ_ENABLE_QTMOBILITY
|
||||
CPPSRCS = \
|
||||
nsDeviceMotionSystem.cpp \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
ifdef MOZ_MAEMO_LIBLOCATION
|
||||
CPPSRCS += MaemoLocationProvider.cpp
|
||||
LOCAL_INCLUDES += $(MOZ_PLATFORM_MAEMO_CFLAGS) \
|
||||
|
@ -71,10 +65,9 @@ CPPSRCS += nsHapticFeedback.cpp
|
|||
LOCAL_INCLUDES += $(MOZ_DBUS_CFLAGS) \
|
||||
$(NULL)
|
||||
ifdef MOZ_ENABLE_QTMOBILITY
|
||||
MOCSRCS += moc_QTMLocationProvider.cpp moc_nsQTMDeviceMotionSystem.cpp
|
||||
MOCSRCS += moc_QTMLocationProvider.cpp
|
||||
CPPSRCS += $(MOCSRCS) \
|
||||
QTMLocationProvider.cpp \
|
||||
nsQTMDeviceMotionSystem.cpp \
|
||||
$(NULL)
|
||||
LOCAL_INCLUDES += $(MOZ_QT_CFLAGS) \
|
||||
-I$(topsrcdir)/dom/src/geolocation \
|
||||
|
@ -82,7 +75,4 @@ LOCAL_INCLUDES += $(MOZ_QT_CFLAGS) \
|
|||
endif
|
||||
endif
|
||||
|
||||
# We fire the nsDOMDeviceAcceleration
|
||||
LOCAL_INCLUDES += -I$(topsrcdir)/content/events/src
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -1,253 +0,0 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Michael Ventnor <m.ventnor@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "mozilla/Util.h"
|
||||
|
||||
#include "nsDeviceMotionSystem.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#define DEFAULT_SENSOR_POLL 100
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
typedef struct {
|
||||
const char* mPosition;
|
||||
const char* mCalibrate;
|
||||
nsAccelerometerSystemDriver mToken;
|
||||
} AccelerometerData;
|
||||
|
||||
static const AccelerometerData gAccelerometers[] = {
|
||||
// MacBook
|
||||
{"/sys/devices/platform/applesmc.768/position",
|
||||
"/sys/devices/platform/applesmc.768/calibrate",
|
||||
eAppleSensor},
|
||||
// Thinkpad
|
||||
{"/sys/devices/platform/hdaps/position",
|
||||
"/sys/devices/platform/hdaps/calibrate",
|
||||
eIBMSensor},
|
||||
// Maemo Fremantle
|
||||
{"/sys/class/i2c-adapter/i2c-3/3-001d/coord",
|
||||
NULL,
|
||||
eMaemoSensor},
|
||||
// HP Pavilion dv7
|
||||
{"/sys/devices/platform/lis3lv02d/position",
|
||||
"/sys/devices/platform/lis3lv02d/calibrate",
|
||||
eHPdv7Sensor},
|
||||
};
|
||||
|
||||
nsDeviceMotionSystem::nsDeviceMotionSystem() :
|
||||
mPositionFile(NULL),
|
||||
mCalibrateFile(NULL),
|
||||
mType(eNoSensor)
|
||||
{
|
||||
}
|
||||
|
||||
nsDeviceMotionSystem::~nsDeviceMotionSystem()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
nsDeviceMotionSystem::UpdateHandler(nsITimer *aTimer, void *aClosure)
|
||||
{
|
||||
nsDeviceMotionSystem *self = reinterpret_cast<nsDeviceMotionSystem *>(aClosure);
|
||||
if (!self) {
|
||||
NS_ERROR("no self");
|
||||
return;
|
||||
}
|
||||
|
||||
float xf, yf, zf;
|
||||
|
||||
switch (self->mType) {
|
||||
case eAppleSensor:
|
||||
{
|
||||
int x, y, z, calibrate_x, calibrate_y;
|
||||
fflush(self->mCalibrateFile);
|
||||
rewind(self->mCalibrateFile);
|
||||
|
||||
fflush(self->mPositionFile);
|
||||
rewind(self->mPositionFile);
|
||||
|
||||
if (fscanf(self->mCalibrateFile, "(%d, %d)", &calibrate_x, &calibrate_y) <= 0)
|
||||
return;
|
||||
|
||||
if (fscanf(self->mPositionFile, "(%d, %d, %d)", &x, &y, &z) <= 0)
|
||||
return;
|
||||
|
||||
// In applesmc:
|
||||
// - the x calibration value is negated
|
||||
// - a negative z actually means a correct-way-up computer
|
||||
// - dividing by 255 gives us the intended value of -1 to 1
|
||||
xf = ((float)(x + calibrate_x)) / 255.0;
|
||||
yf = ((float)(y - calibrate_y)) / 255.0;
|
||||
zf = ((float)z) / -255.0;
|
||||
break;
|
||||
}
|
||||
case eIBMSensor:
|
||||
{
|
||||
int x, y, calibrate_x, calibrate_y;
|
||||
fflush(self->mCalibrateFile);
|
||||
rewind(self->mCalibrateFile);
|
||||
|
||||
fflush(self->mPositionFile);
|
||||
rewind(self->mPositionFile);
|
||||
|
||||
if (fscanf(self->mCalibrateFile, "(%d, %d)", &calibrate_x, &calibrate_y) <= 0)
|
||||
return;
|
||||
|
||||
if (fscanf(self->mPositionFile, "(%d, %d)", &x, &y) <= 0)
|
||||
return;
|
||||
|
||||
xf = ((float)(x - calibrate_x)) / 180.0;
|
||||
yf = ((float)(y - calibrate_y)) / 180.0;
|
||||
zf = 1.0f;
|
||||
break;
|
||||
}
|
||||
case eMaemoSensor:
|
||||
{
|
||||
int x, y, z;
|
||||
fflush(self->mPositionFile);
|
||||
rewind(self->mPositionFile);
|
||||
|
||||
if (fscanf(self->mPositionFile, "%d %d %d", &x, &y, &z) <= 0)
|
||||
return;
|
||||
|
||||
xf = ((float)x) / -1000.0;
|
||||
yf = ((float)y) / -1000.0;
|
||||
zf = ((float)z) / -1000.0;
|
||||
break;
|
||||
}
|
||||
case eHPdv7Sensor:
|
||||
{
|
||||
int x, y, z, calibrate_x, calibrate_y, calibrate_z;
|
||||
fflush(self->mCalibrateFile);
|
||||
rewind(self->mCalibrateFile);
|
||||
|
||||
fflush(self->mPositionFile);
|
||||
rewind(self->mPositionFile);
|
||||
|
||||
if (fscanf(self->mCalibrateFile, "(%d,%d,%d)", &calibrate_x, &calibrate_y, &calibrate_z) <= 0)
|
||||
return;
|
||||
|
||||
if (fscanf(self->mPositionFile, "(%d,%d,%d)", &x, &y, &z) <= 0)
|
||||
return;
|
||||
|
||||
// Example data:
|
||||
//
|
||||
// Calibration (-4,0,51)
|
||||
// flat on the table (-5,-2,50)
|
||||
// Tilted on its left side (-60,0,-4)
|
||||
// Tilted on its right side (51,1,-1)
|
||||
// upside down (-2,3,-60)
|
||||
//
|
||||
// So assuming the calibration data shows the acceleration
|
||||
// (1G) measured with the notebook laying flat on the table
|
||||
// it would mean that our best bet, is to ignore the z-axis
|
||||
// calibration... We are still way off, but it's hard to
|
||||
// see how to get better data without doing calibration with
|
||||
// user intervention (like: Turn your notbook slowly around
|
||||
// so every edge and the top and bottom points up in turn)
|
||||
|
||||
xf = ((float)(x - calibrate_x)) / 60.0;
|
||||
yf = ((float)(y - calibrate_y)) / 60.0;
|
||||
zf = ((float)(z)) / 60.0;
|
||||
break;
|
||||
}
|
||||
|
||||
case eNoSensor:
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
self->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION, xf, yf, zf );
|
||||
}
|
||||
|
||||
void nsDeviceMotionSystem::Startup()
|
||||
{
|
||||
// Accelerometers in Linux are used by reading a file (yay UNIX!), which is
|
||||
// in a slightly different location depending on the driver.
|
||||
for (unsigned int i = 0; i < ArrayLength(gAccelerometers); i++) {
|
||||
if (!(mPositionFile = fopen(gAccelerometers[i].mPosition, "r")))
|
||||
continue;
|
||||
|
||||
mType = gAccelerometers[i].mToken;
|
||||
if (gAccelerometers[i].mCalibrate) {
|
||||
mCalibrateFile = fopen(gAccelerometers[i].mCalibrate, "r");
|
||||
if (!mCalibrateFile) {
|
||||
fclose(mPositionFile);
|
||||
mPositionFile = nsnull;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (mType == eNoSensor)
|
||||
return;
|
||||
|
||||
mUpdateTimer = do_CreateInstance("@mozilla.org/timer;1");
|
||||
if (mUpdateTimer)
|
||||
mUpdateTimer->InitWithFuncCallback(UpdateHandler,
|
||||
this,
|
||||
DEFAULT_SENSOR_POLL,
|
||||
nsITimer::TYPE_REPEATING_SLACK);
|
||||
}
|
||||
|
||||
void nsDeviceMotionSystem::Shutdown()
|
||||
{
|
||||
if (mPositionFile) {
|
||||
fclose(mPositionFile);
|
||||
mPositionFile = nsnull;
|
||||
}
|
||||
|
||||
// Fun fact: writing to the calibrate file causes the
|
||||
// driver to re-calibrate the accelerometer
|
||||
if (mCalibrateFile) {
|
||||
fclose(mCalibrateFile);
|
||||
mCalibrateFile = nsnull;
|
||||
}
|
||||
|
||||
mType = eNoSensor;
|
||||
|
||||
if (mUpdateTimer) {
|
||||
mUpdateTimer->Cancel();
|
||||
mUpdateTimer = nsnull;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Michael Ventnor <m.ventnor@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsDeviceMotionSystem_h
|
||||
#define nsDeviceMotionSystem_h
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include "nsDeviceMotion.h"
|
||||
|
||||
enum nsAccelerometerSystemDriver
|
||||
{
|
||||
eNoSensor,
|
||||
eAppleSensor,
|
||||
eIBMSensor,
|
||||
eMaemoSensor,
|
||||
eHPdv7Sensor
|
||||
};
|
||||
|
||||
class nsDeviceMotionSystem : public nsDeviceMotion
|
||||
{
|
||||
public:
|
||||
nsDeviceMotionSystem();
|
||||
~nsDeviceMotionSystem();
|
||||
|
||||
void Startup();
|
||||
void Shutdown();
|
||||
|
||||
FILE* mPositionFile;
|
||||
FILE* mCalibrateFile;
|
||||
nsAccelerometerSystemDriver mType;
|
||||
|
||||
nsCOMPtr<nsITimer> mUpdateTimer;
|
||||
static void UpdateHandler(nsITimer *aTimer, void *aClosure);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,126 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "nsQTMDeviceMotionSystem.h"
|
||||
#include <QObject>
|
||||
#include <QtSensors/QAccelerometer>
|
||||
#include <QtSensors/QRotationSensor>
|
||||
|
||||
#include "nsXULAppAPI.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace QtMobility;
|
||||
|
||||
bool
|
||||
MozQAccelerometerSensorFilter::filter(QAccelerometerReading* reading)
|
||||
{
|
||||
mSystem.DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION,
|
||||
-reading->x(),
|
||||
-reading->y(),
|
||||
-reading->z());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
MozQRotationSensorFilter::filter(QRotationReading* reading)
|
||||
{
|
||||
// QRotationReading class:
|
||||
// - the rotation around z axis (alpha) is given as z in QRotationReading;
|
||||
// - the rotation around x axis (beta) is given as x in QRotationReading;
|
||||
// - the rotation around y axis (gamma) is given as y in QRotationReading;
|
||||
// See: http://doc.qt.nokia.com/qtmobility-1.0/qrotationreading.html
|
||||
mSystem.DeviceMotionChanged(nsIDeviceMotionData::TYPE_ORIENTATION,
|
||||
reading->z(),
|
||||
reading->x(),
|
||||
reading->y());
|
||||
return true;
|
||||
}
|
||||
|
||||
nsDeviceMotionSystem::nsDeviceMotionSystem()
|
||||
{
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
||||
mAccelerometer = new QAccelerometer();
|
||||
mAccelerometerFilter = new MozQAccelerometerSensorFilter(*this);
|
||||
mAccelerometer->addFilter(mAccelerometerFilter);
|
||||
mRotation = new QRotationSensor();
|
||||
mRotationFilter = new MozQRotationSensorFilter(*this);
|
||||
mRotation->addFilter(mRotationFilter);
|
||||
}
|
||||
}
|
||||
|
||||
nsDeviceMotionSystem::~nsDeviceMotionSystem()
|
||||
{
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
||||
mAccelerometer->removeFilter(mAccelerometerFilter);
|
||||
mAccelerometer->stop();
|
||||
mRotation->removeFilter(mRotationFilter);
|
||||
mRotation->stop();
|
||||
delete mAccelerometer;
|
||||
delete mAccelerometerFilter;
|
||||
delete mRotation;
|
||||
delete mRotationFilter;
|
||||
}
|
||||
}
|
||||
|
||||
void nsDeviceMotionSystem::Startup()
|
||||
{
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
||||
mAccelerometer->start();
|
||||
if (!mAccelerometer->isActive()) {
|
||||
NS_WARNING("AccelerometerSensor didn't start!");
|
||||
}
|
||||
mRotation->start();
|
||||
if (!mRotation->isActive()) {
|
||||
NS_WARNING("RotationSensor didn't start!");
|
||||
}
|
||||
}
|
||||
else
|
||||
mozilla::dom::ContentChild::GetSingleton()->
|
||||
SendAddDeviceMotionListener();
|
||||
}
|
||||
|
||||
void nsDeviceMotionSystem::Shutdown()
|
||||
{
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
||||
mAccelerometer->stop();
|
||||
mRotation->stop();
|
||||
}
|
||||
else
|
||||
mozilla::dom::ContentChild::GetSingleton()->
|
||||
SendRemoveDeviceMotionListener();
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsDeviceMotionSystem_h
|
||||
#define nsDeviceMotionSystem_h
|
||||
|
||||
#include <QObject>
|
||||
#include <QtSensors/QAccelerometer>
|
||||
#include <QtSensors/QRotationSensor>
|
||||
#include "nsDeviceMotion.h"
|
||||
|
||||
using namespace QtMobility;
|
||||
|
||||
|
||||
class MozQAccelerometerSensorFilter;
|
||||
class MozQRotationSensorFilter;
|
||||
|
||||
class nsDeviceMotionSystem : public nsDeviceMotion
|
||||
{
|
||||
public:
|
||||
nsDeviceMotionSystem();
|
||||
virtual ~nsDeviceMotionSystem();
|
||||
|
||||
private:
|
||||
virtual void Startup();
|
||||
virtual void Shutdown();
|
||||
|
||||
QtMobility::QAccelerometer* mAccelerometer;
|
||||
MozQAccelerometerSensorFilter* mAccelerometerFilter;
|
||||
QtMobility::QRotationSensor* mRotation;
|
||||
MozQRotationSensorFilter* mRotationFilter;
|
||||
};
|
||||
|
||||
class MozQAccelerometerSensorFilter : public QObject, public QAccelerometerFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MozQAccelerometerSensorFilter(nsDeviceMotionSystem& aSystem) : mSystem(aSystem) {}
|
||||
|
||||
virtual ~MozQAccelerometerSensorFilter(){}
|
||||
|
||||
virtual bool filter(QAccelerometerReading* reading);
|
||||
|
||||
private:
|
||||
bool filter(QSensorReading *reading) { return filter(static_cast<QAccelerometerReading*>(reading)); }
|
||||
nsDeviceMotionSystem& mSystem;
|
||||
};
|
||||
|
||||
class MozQRotationSensorFilter : public QObject, public QRotationFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MozQRotationSensorFilter(nsDeviceMotionSystem& aSystem) : mSystem(aSystem) {}
|
||||
|
||||
virtual ~MozQRotationSensorFilter(){}
|
||||
|
||||
virtual bool filter(QRotationReading* reading);
|
||||
|
||||
private:
|
||||
bool filter(QSensorReading *reading) { return filter(static_cast<QRotationReading*>(reading)); }
|
||||
nsDeviceMotionSystem& mSystem;
|
||||
};
|
||||
|
||||
#endif /* nsDeviceMotionSystem_h */
|
||||
|
|
@ -55,7 +55,6 @@ LOCAL_INCLUDES += -I$(topsrcdir)/content/events/src
|
|||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
CPPSRCS = \
|
||||
nsDeviceMotionSystem.cpp \
|
||||
nsHapticFeedback.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -1,175 +0,0 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Doug Turner <dougt@dougt.org>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jesper Kristensen <mail@jesperkristensen.dk>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsDeviceMotionSystem.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "windows.h"
|
||||
|
||||
#define DEFAULT_SENSOR_POLL 100
|
||||
|
||||
////////////////////////////
|
||||
// ThinkPad
|
||||
////////////////////////////
|
||||
|
||||
typedef struct {
|
||||
int status; // Current internal state
|
||||
unsigned short x; // raw value
|
||||
unsigned short y; // raw value
|
||||
unsigned short xx; // avg. of 40ms
|
||||
unsigned short yy; // avg. of 40ms
|
||||
char temp; // raw value (could be deg celsius?)
|
||||
unsigned short x0; // Used for "auto-center"
|
||||
unsigned short y0; // Used for "auto-center"
|
||||
} ThinkPadAccelerometerData;
|
||||
|
||||
typedef void (__stdcall *ShockproofGetAccelerometerData)(ThinkPadAccelerometerData*);
|
||||
|
||||
ShockproofGetAccelerometerData gShockproofGetAccelerometerData = nsnull;
|
||||
|
||||
class ThinkPadSensor : public Sensor
|
||||
{
|
||||
public:
|
||||
ThinkPadSensor();
|
||||
~ThinkPadSensor();
|
||||
bool Startup();
|
||||
void Shutdown();
|
||||
void GetValues(double *x, double *y, double *z);
|
||||
private:
|
||||
HMODULE mLibrary;
|
||||
};
|
||||
|
||||
ThinkPadSensor::ThinkPadSensor()
|
||||
{
|
||||
}
|
||||
|
||||
ThinkPadSensor::~ThinkPadSensor()
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
ThinkPadSensor::Startup()
|
||||
{
|
||||
mLibrary = LoadLibraryW(L"sensor.dll");
|
||||
if (!mLibrary)
|
||||
return false;
|
||||
|
||||
gShockproofGetAccelerometerData = (ShockproofGetAccelerometerData)
|
||||
GetProcAddress(mLibrary, "ShockproofGetAccelerometerData");
|
||||
if (!gShockproofGetAccelerometerData) {
|
||||
FreeLibrary(mLibrary);
|
||||
mLibrary = nsnull;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ThinkPadSensor::Shutdown()
|
||||
{
|
||||
if (mLibrary == nsnull)
|
||||
return;
|
||||
|
||||
FreeLibrary(mLibrary);
|
||||
mLibrary = nsnull;
|
||||
gShockproofGetAccelerometerData = nsnull;
|
||||
}
|
||||
|
||||
void
|
||||
ThinkPadSensor::GetValues(double *x, double *y, double *z)
|
||||
{
|
||||
ThinkPadAccelerometerData accelData;
|
||||
|
||||
gShockproofGetAccelerometerData(&accelData);
|
||||
|
||||
// accelData.x and accelData.y is the acceleration measured from the accelerometer.
|
||||
// x and y is switched from what we use, and the accelerometer does not support z axis.
|
||||
// Balance point (526, 528) and 90 degree tilt (144) determined experimentally.
|
||||
*x = ((double)(accelData.y - 526)) / 144;
|
||||
*y = ((double)(accelData.x - 528)) / 144;
|
||||
*z = 1.0;
|
||||
}
|
||||
|
||||
nsDeviceMotionSystem::nsDeviceMotionSystem(){}
|
||||
nsDeviceMotionSystem::~nsDeviceMotionSystem(){}
|
||||
|
||||
void
|
||||
nsDeviceMotionSystem::UpdateHandler(nsITimer *aTimer, void *aClosure)
|
||||
{
|
||||
nsDeviceMotionSystem *self = reinterpret_cast<nsDeviceMotionSystem *>(aClosure);
|
||||
if (!self || !self->mSensor) {
|
||||
NS_ERROR("no self or sensor");
|
||||
return;
|
||||
}
|
||||
double x, y, z;
|
||||
self->mSensor->GetValues(&x, &y, &z);
|
||||
self->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION, x, y, z);
|
||||
}
|
||||
|
||||
void nsDeviceMotionSystem::Startup()
|
||||
{
|
||||
NS_ASSERTION(!mSensor, "mSensor should be null. Startup called twice?");
|
||||
|
||||
bool started = false;
|
||||
|
||||
mSensor = new ThinkPadSensor();
|
||||
if (mSensor)
|
||||
started = mSensor->Startup();
|
||||
|
||||
if (!started) {
|
||||
mSensor = nsnull;
|
||||
return;
|
||||
}
|
||||
|
||||
mUpdateTimer = do_CreateInstance("@mozilla.org/timer;1");
|
||||
if (mUpdateTimer)
|
||||
mUpdateTimer->InitWithFuncCallback(UpdateHandler,
|
||||
this,
|
||||
DEFAULT_SENSOR_POLL,
|
||||
nsITimer::TYPE_REPEATING_SLACK);
|
||||
}
|
||||
|
||||
void nsDeviceMotionSystem::Shutdown()
|
||||
{
|
||||
if (mUpdateTimer) {
|
||||
mUpdateTimer->Cancel();
|
||||
mUpdateTimer = nsnull;
|
||||
}
|
||||
|
||||
if (mSensor)
|
||||
mSensor->Shutdown();
|
||||
}
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Doug Turner <dougt@dougt.org>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsDeviceMotionSystem_h
|
||||
#define nsDeviceMotionSystem_h
|
||||
|
||||
#include "nsDeviceMotion.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
class Sensor
|
||||
{
|
||||
public:
|
||||
virtual bool Startup() = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
virtual void GetValues(double *x, double *y, double *z) = 0;
|
||||
};
|
||||
|
||||
class nsDeviceMotionSystem : public nsDeviceMotion
|
||||
{
|
||||
public:
|
||||
nsDeviceMotionSystem();
|
||||
~nsDeviceMotionSystem();
|
||||
|
||||
void Startup();
|
||||
void Shutdown();
|
||||
|
||||
nsCOMPtr<nsITimer> mUpdateTimer;
|
||||
static void UpdateHandler(nsITimer *aTimer, void *aClosure);
|
||||
|
||||
nsAutoPtr<Sensor> mSensor;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -63,9 +63,24 @@ class SensorData;
|
|||
|
||||
typedef Observer<SensorData> ISensorObserver;
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Enumeration of sensor accuracy types.
|
||||
*/
|
||||
enum SensorAccuracyType {
|
||||
SENSOR_ACCURACY_UNKNOWN = -1,
|
||||
SENSOR_ACCURACY_UNRELIABLE,
|
||||
SENSOR_ACCURACY_LOW,
|
||||
SENSOR_ACCURACY_MED,
|
||||
SENSOR_ACCURACY_HIGH,
|
||||
NUM_SENSOR_ACCURACY_TYPE
|
||||
};
|
||||
|
||||
class SensorAccuracy;
|
||||
|
||||
typedef Observer<SensorAccuracy> ISensorAccuracyObserver;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#include "IPC/IPCMessageUtils.h"
|
||||
|
||||
|
@ -80,6 +95,13 @@ namespace IPC {
|
|||
mozilla::hal::NUM_SENSOR_TYPE> {
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<mozilla::hal::SensorAccuracyType>:
|
||||
public EnumSerializer<mozilla::hal::SensorAccuracyType,
|
||||
mozilla::hal::SENSOR_ACCURACY_UNKNOWN,
|
||||
mozilla::hal::NUM_SENSOR_ACCURACY_TYPE> {
|
||||
|
||||
};
|
||||
} // namespace IPC
|
||||
|
||||
#endif /* __HAL_SENSOR_H_ */
|
||||
|
|
|
@ -46,6 +46,7 @@ VPATH = \
|
|||
$(srcdir)/sandbox \
|
||||
$(srcdir)/linux \
|
||||
$(srcdir)/windows \
|
||||
$(srcdir)/cocoa \
|
||||
$(NULL)
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
@ -99,6 +100,14 @@ CPPSRCS += \
|
|||
WindowsBattery.cpp \
|
||||
FallbackSensor.cpp \
|
||||
$(NULL)
|
||||
else ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
|
||||
CPPSRCS += \
|
||||
FallbackHal.cpp \
|
||||
$(NULL)
|
||||
CMMSRCS += \
|
||||
CocoaSensor.mm \
|
||||
smslib.mm \
|
||||
$(NULL)
|
||||
else
|
||||
CPPSRCS += \
|
||||
FallbackHal.cpp \
|
||||
|
|
|
@ -43,32 +43,14 @@ using namespace mozilla::hal;
|
|||
namespace mozilla {
|
||||
namespace hal_impl {
|
||||
|
||||
/**
|
||||
* Translate ID of sensor type from Sensor service to Android.
|
||||
*
|
||||
* Must be consistent with the definition of sensor types in
|
||||
* embedding/android/GeckoAppShell.java
|
||||
*/
|
||||
static int
|
||||
MapSensorType(SensorType aSensorType) {
|
||||
return (SENSOR_UNKNOWN <= aSensorType && aSensorType < NUM_SENSOR_TYPE) ?
|
||||
aSensorType + 1 : -1;
|
||||
}
|
||||
|
||||
void
|
||||
EnableSensorNotifications(SensorType aSensor) {
|
||||
int androidSensor = MapSensorType(aSensor);
|
||||
|
||||
MOZ_ASSERT(androidSensor != -1);
|
||||
AndroidBridge::Bridge()->EnableSensor(androidSensor);
|
||||
AndroidBridge::Bridge()->EnableSensor(aSensor);
|
||||
}
|
||||
|
||||
void
|
||||
DisableSensorNotifications(SensorType aSensor) {
|
||||
int androidSensor = MapSensorType(aSensor);
|
||||
|
||||
MOZ_ASSERT(androidSensor != -1);
|
||||
AndroidBridge::Bridge()->DisableSensor(androidSensor);
|
||||
AndroidBridge::Bridge()->DisableSensor(aSensor);
|
||||
}
|
||||
|
||||
} // hal_impl
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "Hal.h"
|
||||
#include "nsITimer.h"
|
||||
|
||||
#include "smslib.h"
|
||||
#define MEAN_GRAVITY 9.80665
|
||||
#define DEFAULT_SENSOR_POLL 100
|
||||
|
||||
using namespace mozilla::hal;
|
||||
|
||||
namespace mozilla {
|
||||
namespace hal_impl {
|
||||
|
||||
static nsITimer* sUpdateTimer = nsnull;
|
||||
|
||||
void UpdateHandler(nsITimer *aTimer, void *aClosure)
|
||||
{
|
||||
sms_acceleration accel;
|
||||
smsGetData(&accel);
|
||||
|
||||
InfallibleTArray<float> values;
|
||||
values.AppendElement(accel.x * MEAN_GRAVITY);
|
||||
values.AppendElement(accel.y * MEAN_GRAVITY);
|
||||
values.AppendElement(accel.z * MEAN_GRAVITY);
|
||||
hal::SensorData sdata(hal::SENSOR_ACCELERATION,
|
||||
PR_Now(),
|
||||
values,
|
||||
hal::SENSOR_ACCURACY_UNKNOWN);
|
||||
hal::NotifySensorChange(sdata);
|
||||
}
|
||||
|
||||
void
|
||||
EnableSensorNotifications(SensorType aSensor) {
|
||||
if (sUpdateTimer)
|
||||
return;
|
||||
|
||||
smsStartup(nil, nil);
|
||||
smsLoadCalibration();
|
||||
|
||||
CallCreateInstance("@mozilla.org/timer;1", &sUpdateTimer);
|
||||
if (sUpdateTimer)
|
||||
sUpdateTimer->InitWithFuncCallback(UpdateHandler,
|
||||
NULL,
|
||||
DEFAULT_SENSOR_POLL,
|
||||
nsITimer::TYPE_REPEATING_SLACK);
|
||||
}
|
||||
|
||||
void
|
||||
DisableSensorNotifications(SensorType aSensor) {
|
||||
if (sUpdateTimer) {
|
||||
sUpdateTimer->Cancel();
|
||||
NS_RELEASE(sUpdateTimer);
|
||||
}
|
||||
smsShutdown();
|
||||
}
|
||||
|
||||
} // hal_impl
|
||||
} // mozilla
|
|
@ -60,6 +60,7 @@ SensorseventToSensorData(const sensors_event_t& data, SensorData* aSensorData)
|
|||
aSensorData->values()[0] = data.data[0];
|
||||
aSensorData->values()[1] = data.data[1];
|
||||
aSensorData->values()[2] = data.data[2];
|
||||
aSensorData->accuracy() = SENSOR_ACCURACY_UNKNOWN;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ using mozilla::hal::FlashMode;
|
|||
using mozilla::hal::LightType;
|
||||
using mozilla::hal::LightMode;
|
||||
using mozilla::hal::SensorType;
|
||||
using mozilla::hal::SensorAccuracyType;
|
||||
using mozilla::hal::WakeLockControl;
|
||||
using mozilla::dom::ScreenOrientation;
|
||||
|
||||
|
@ -74,6 +75,7 @@ namespace hal {
|
|||
SensorType sensor;
|
||||
PRTime timestamp;
|
||||
float[] values;
|
||||
SensorAccuracyType accuracy;
|
||||
};
|
||||
|
||||
struct NetworkInformation {
|
||||
|
|
|
@ -246,7 +246,7 @@ static void Shutdown();
|
|||
defined(_WINDOWS) || \
|
||||
defined(machintosh) || \
|
||||
defined(android)
|
||||
#include "nsDeviceMotionSystem.h"
|
||||
#include "nsDeviceMotion.h"
|
||||
#endif
|
||||
#endif
|
||||
#include "nsCSPService.h"
|
||||
|
@ -301,7 +301,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(AudioManager)
|
|||
defined(_WINDOWS) || \
|
||||
defined(machintosh) || \
|
||||
defined(android)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceMotionSystem)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceMotion)
|
||||
#endif
|
||||
#if defined(ANDROID) || defined(MOZ_PLATFORM_MAEMO)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHapticFeedback)
|
||||
|
@ -1072,7 +1072,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
|
|||
defined(_WINDOWS) || \
|
||||
defined(machintosh) || \
|
||||
defined(android)
|
||||
{ &kNS_DEVICE_MOTION_CID, false, NULL, nsDeviceMotionSystemConstructor },
|
||||
{ &kNS_DEVICE_MOTION_CID, false, NULL, nsDeviceMotionConstructor },
|
||||
#endif
|
||||
#if defined(ANDROID) || defined(MOZ_PLATFORM_MAEMO)
|
||||
{ &kNS_HAPTICFEEDBACK_CID, false, NULL, nsHapticFeedbackConstructor },
|
||||
|
|
|
@ -2790,15 +2790,10 @@ abstract public class GeckoApp
|
|||
public LayerController getLayerController() { return mLayerController; }
|
||||
|
||||
// accelerometer
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy)
|
||||
{
|
||||
Log.w(LOGTAG, "onAccuracyChanged "+accuracy);
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createSensorAccuracyEvent(accuracy));
|
||||
}
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
|
||||
|
||||
public void onSensorChanged(SensorEvent event)
|
||||
{
|
||||
Log.w(LOGTAG, "onSensorChanged "+event);
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createSensorEvent(event));
|
||||
}
|
||||
|
||||
|
@ -2806,7 +2801,6 @@ abstract public class GeckoApp
|
|||
public void onLocationChanged(Location location)
|
||||
{
|
||||
Log.w(LOGTAG, "onLocationChanged "+location);
|
||||
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createLocationEvent(location));
|
||||
}
|
||||
|
||||
|
|
|
@ -585,6 +585,7 @@ public class GeckoAppShell
|
|||
|
||||
switch(aSensortype) {
|
||||
case GeckoHalDefines.SENSOR_ORIENTATION:
|
||||
Log.i(LOGTAG, "Enabling SENSOR_ORIENTATION");
|
||||
if(gOrientationSensor == null)
|
||||
gOrientationSensor = sm.getDefaultSensor(Sensor.TYPE_ORIENTATION);
|
||||
if (gOrientationSensor != null)
|
||||
|
@ -592,6 +593,7 @@ public class GeckoAppShell
|
|||
break;
|
||||
|
||||
case GeckoHalDefines.SENSOR_ACCELERATION:
|
||||
Log.i(LOGTAG, "Enabling SENSOR_ACCELERATION");
|
||||
if(gAccelerometerSensor == null)
|
||||
gAccelerometerSensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
||||
if (gAccelerometerSensor != null)
|
||||
|
@ -599,6 +601,7 @@ public class GeckoAppShell
|
|||
break;
|
||||
|
||||
case GeckoHalDefines.SENSOR_PROXIMITY:
|
||||
Log.i(LOGTAG, "Enabling SENSOR_PROXIMITY");
|
||||
if(gProximitySensor == null)
|
||||
gProximitySensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
|
||||
if (gProximitySensor != null)
|
||||
|
@ -606,19 +609,22 @@ public class GeckoAppShell
|
|||
break;
|
||||
|
||||
case GeckoHalDefines.SENSOR_LINEAR_ACCELERATION:
|
||||
Log.i(LOGTAG, "Enabling SENSOR_LINEAR_ACCELERATION");
|
||||
if(gLinearAccelerometerSensor == null)
|
||||
gLinearAccelerometerSensor = sm.getDefaultSensor(10);
|
||||
gLinearAccelerometerSensor = sm.getDefaultSensor(10 /* API Level 9 - TYPE_LINEAR_ACCELERATION */);
|
||||
if (gLinearAccelerometerSensor != null)
|
||||
sm.registerListener(GeckoApp.mAppContext, gLinearAccelerometerSensor, sDefaultSensorHint);
|
||||
break;
|
||||
|
||||
case GeckoHalDefines.SENSOR_GYROSCOPE:
|
||||
Log.i(LOGTAG, "Enabling SENSOR_GYROSCOPE");
|
||||
if(gGyroscopeSensor == null)
|
||||
gGyroscopeSensor = sm.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
|
||||
if (gGyroscopeSensor != null)
|
||||
sm.registerListener(GeckoApp.mAppContext, gGyroscopeSensor, sDefaultSensorHint);
|
||||
break;
|
||||
|
||||
default:
|
||||
Log.e(LOGTAG, "Error! SENSOR type used " + aSensortype);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -628,29 +634,36 @@ public class GeckoAppShell
|
|||
|
||||
switch (aSensortype) {
|
||||
case GeckoHalDefines.SENSOR_ORIENTATION:
|
||||
Log.i(LOGTAG, "Disabling SENSOR_ORIENTATION");
|
||||
if (gOrientationSensor != null)
|
||||
sm.unregisterListener(GeckoApp.mAppContext, gOrientationSensor);
|
||||
break;
|
||||
|
||||
case GeckoHalDefines.SENSOR_ACCELERATION:
|
||||
Log.i(LOGTAG, "Disabling SENSOR_ACCELERATION");
|
||||
if (gAccelerometerSensor != null)
|
||||
sm.unregisterListener(GeckoApp.mAppContext, gAccelerometerSensor);
|
||||
break;
|
||||
|
||||
case GeckoHalDefines.SENSOR_PROXIMITY:
|
||||
Log.i(LOGTAG, "Disabling SENSOR_PROXIMITY");
|
||||
if (gProximitySensor != null)
|
||||
sm.unregisterListener(GeckoApp.mAppContext, gProximitySensor);
|
||||
break;
|
||||
|
||||
case GeckoHalDefines.SENSOR_LINEAR_ACCELERATION:
|
||||
Log.i(LOGTAG, "Disabling SENSOR_LINEAR_ACCELERATION");
|
||||
if (gLinearAccelerometerSensor != null)
|
||||
sm.unregisterListener(GeckoApp.mAppContext, gLinearAccelerometerSensor);
|
||||
break;
|
||||
|
||||
case GeckoHalDefines.SENSOR_GYROSCOPE:
|
||||
Log.i(LOGTAG, "Disabling SENSOR_GYROSCOPE");
|
||||
if (gGyroscopeSensor != null)
|
||||
sm.unregisterListener(GeckoApp.mAppContext, gGyroscopeSensor);
|
||||
break;
|
||||
default:
|
||||
Log.e(LOGTAG, "Error! SENSOR type used " + aSensortype);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ public class GeckoEvent {
|
|||
private static final int PROXIMITY_EVENT = 23;
|
||||
private static final int ACTIVITY_RESUMING = 24;
|
||||
private static final int SCREENSHOT = 25;
|
||||
private static final int SENSOR_ACCURACY = 26;
|
||||
private static final int UNUSED2_EVENT = 26;
|
||||
private static final int SCREENORIENTATION_CHANGED = 27;
|
||||
|
||||
public static final int IME_COMPOSITION_END = 0;
|
||||
|
@ -283,6 +283,20 @@ public class GeckoEvent {
|
|||
}
|
||||
}
|
||||
|
||||
private static int HalSensorAccuracyFor(int androidAccuracy) {
|
||||
switch (androidAccuracy) {
|
||||
case SensorManager.SENSOR_STATUS_UNRELIABLE:
|
||||
return GeckoHalDefines.SENSOR_ACCURACY_UNRELIABLE;
|
||||
case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
|
||||
return GeckoHalDefines.SENSOR_ACCURACY_LOW;
|
||||
case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
|
||||
return GeckoHalDefines.SENSOR_ACCURACY_MED;
|
||||
case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
|
||||
return GeckoHalDefines.SENSOR_ACCURACY_HIGH;
|
||||
}
|
||||
return GeckoHalDefines.SENSOR_ACCURACY_UNKNOWN;
|
||||
}
|
||||
|
||||
public static GeckoEvent createSensorEvent(SensorEvent s) {
|
||||
int sensor_type = s.sensor.getType();
|
||||
GeckoEvent event = null;
|
||||
|
@ -292,6 +306,7 @@ public class GeckoEvent {
|
|||
case Sensor.TYPE_ACCELEROMETER:
|
||||
event = new GeckoEvent(SENSOR_EVENT);
|
||||
event.mFlags = GeckoHalDefines.SENSOR_ACCELERATION;
|
||||
event.mMetaState = HalSensorAccuracyFor(s.accuracy);
|
||||
event.mX = s.values[0];
|
||||
event.mY = s.values[1];
|
||||
event.mZ = s.values[2];
|
||||
|
@ -300,6 +315,7 @@ public class GeckoEvent {
|
|||
case 10 /* Requires API Level 9, so just use the raw value - Sensor.TYPE_LINEAR_ACCELEROMETER*/ :
|
||||
event = new GeckoEvent(SENSOR_EVENT);
|
||||
event.mFlags = GeckoHalDefines.SENSOR_LINEAR_ACCELERATION;
|
||||
event.mMetaState = HalSensorAccuracyFor(s.accuracy);
|
||||
event.mX = s.values[0];
|
||||
event.mY = s.values[1];
|
||||
event.mZ = s.values[2];
|
||||
|
@ -308,6 +324,7 @@ public class GeckoEvent {
|
|||
case Sensor.TYPE_ORIENTATION:
|
||||
event = new GeckoEvent(SENSOR_EVENT);
|
||||
event.mFlags = GeckoHalDefines.SENSOR_ORIENTATION;
|
||||
event.mMetaState = HalSensorAccuracyFor(s.accuracy);
|
||||
event.mX = s.values[0];
|
||||
event.mY = s.values[1];
|
||||
event.mZ = s.values[2];
|
||||
|
@ -316,6 +333,7 @@ public class GeckoEvent {
|
|||
case Sensor.TYPE_GYROSCOPE:
|
||||
event = new GeckoEvent(SENSOR_EVENT);
|
||||
event.mFlags = GeckoHalDefines.SENSOR_GYROSCOPE;
|
||||
event.mMetaState = HalSensorAccuracyFor(s.accuracy);
|
||||
event.mX = Math.toDegrees(s.values[0]);
|
||||
event.mY = Math.toDegrees(s.values[1]);
|
||||
event.mZ = Math.toDegrees(s.values[2]);
|
||||
|
@ -441,12 +459,6 @@ public class GeckoEvent {
|
|||
return event;
|
||||
}
|
||||
|
||||
public static GeckoEvent createSensorAccuracyEvent(int accuracy) {
|
||||
GeckoEvent event = new GeckoEvent(SENSOR_ACCURACY);
|
||||
event.mFlags = accuracy;
|
||||
return event;
|
||||
}
|
||||
|
||||
public static GeckoEvent createScreenOrientationEvent(short aScreenOrientation) {
|
||||
GeckoEvent event = new GeckoEvent(SCREENORIENTATION_CHANGED);
|
||||
event.mScreenOrientation = aScreenOrientation;
|
||||
|
|
|
@ -46,4 +46,10 @@ public class GeckoHalDefines
|
|||
public static final int SENSOR_PROXIMITY = 2;
|
||||
public static final int SENSOR_LINEAR_ACCELERATION = 3;
|
||||
public static final int SENSOR_GYROSCOPE = 4;
|
||||
|
||||
public static final int SENSOR_ACCURACY_UNKNOWN = -1;
|
||||
public static final int SENSOR_ACCURACY_UNRELIABLE = 0;
|
||||
public static final int SENSOR_ACCURACY_LOW = 1;
|
||||
public static final int SENSOR_ACCURACY_MED = 2;
|
||||
public static final int SENSOR_ACCURACY_HIGH = 3;
|
||||
};
|
||||
|
|
|
@ -318,28 +318,6 @@ AndroidBridge::AcknowledgeEventSync()
|
|||
env->CallStaticVoidMethod(mGeckoAppShellClass, jAcknowledgeEventSync);
|
||||
}
|
||||
|
||||
void
|
||||
AndroidBridge::EnableDeviceMotion(bool aEnable)
|
||||
{
|
||||
ALOG_BRIDGE("AndroidBridge::EnableDeviceMotion");
|
||||
|
||||
// bug 734855 - we probably can make this finer grain based on
|
||||
// the DOM APIs that are being invoked.
|
||||
if (aEnable) {
|
||||
EnableSensor(hal::SENSOR_ORIENTATION);
|
||||
EnableSensor(hal::SENSOR_ACCELERATION);
|
||||
EnableSensor(hal::SENSOR_LINEAR_ACCELERATION);
|
||||
EnableSensor(hal::SENSOR_GYROSCOPE);
|
||||
}
|
||||
else {
|
||||
DisableSensor(hal::SENSOR_ORIENTATION);
|
||||
DisableSensor(hal::SENSOR_ACCELERATION);
|
||||
DisableSensor(hal::SENSOR_LINEAR_ACCELERATION);
|
||||
DisableSensor(hal::SENSOR_GYROSCOPE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AndroidBridge::EnableLocation(bool aEnable)
|
||||
{
|
||||
|
|
|
@ -176,8 +176,6 @@ public:
|
|||
|
||||
void AcknowledgeEventSync();
|
||||
|
||||
void EnableDeviceMotion(bool aEnable);
|
||||
|
||||
void EnableLocation(bool aEnable);
|
||||
|
||||
void EnableSensor(int aSensorType);
|
||||
|
|
|
@ -475,6 +475,7 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
|
|||
mY = jenv->GetDoubleField(jobj, jYField);
|
||||
mZ = jenv->GetDoubleField(jobj, jZField);
|
||||
mFlags = jenv->GetIntField(jobj, jFlagsField);
|
||||
mMetaState = jenv->GetIntField(jobj, jMetaStateField);
|
||||
break;
|
||||
|
||||
case LOCATION_EVENT: {
|
||||
|
@ -511,7 +512,6 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
|
|||
break;
|
||||
}
|
||||
|
||||
case SENSOR_ACCURACY:
|
||||
case ACTIVITY_STOPPING:
|
||||
case ACTIVITY_START:
|
||||
case ACTIVITY_PAUSING:
|
||||
|
@ -534,7 +534,7 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
|
|||
break;
|
||||
}
|
||||
|
||||
#ifndef DEBUG_ANDROID_EVENTS
|
||||
#ifdef DEBUG_ANDROID_EVENTS
|
||||
ALOG("AndroidGeckoEvent: %p : %d", (void*)jobj, mType);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -589,7 +589,7 @@ public:
|
|||
PROXIMITY_EVENT = 23,
|
||||
ACTIVITY_RESUMING = 24,
|
||||
SCREENSHOT = 25,
|
||||
SENSOR_ACCURACY = 26,
|
||||
UNUSED2_EVENT = 26,
|
||||
SCREENORIENTATION_CHANGED = 27,
|
||||
dummy_java_enum_list_end
|
||||
};
|
||||
|
|
|
@ -56,7 +56,6 @@
|
|||
#include "prenv.h"
|
||||
|
||||
#include "AndroidBridge.h"
|
||||
#include "nsDeviceMotionSystem.h"
|
||||
#include <android/log.h>
|
||||
#include <pthread.h>
|
||||
#include <wchar.h>
|
||||
|
@ -84,7 +83,6 @@ using namespace mozilla;
|
|||
PRLogModuleInfo *gWidgetLog = nsnull;
|
||||
#endif
|
||||
|
||||
nsDeviceMotionSystem *gDeviceMotionSystem = nsnull;
|
||||
nsIGeolocationUpdate *gLocationCallback = nsnull;
|
||||
nsAutoPtr<mozilla::AndroidGeckoEvent> gLastSizeChange;
|
||||
|
||||
|
@ -333,46 +331,38 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait)
|
|||
NativeEventCallback();
|
||||
break;
|
||||
|
||||
case AndroidGeckoEvent::SENSOR_ACCURACY:
|
||||
if (curEvent->Flags() == 0)
|
||||
gDeviceMotionSystem->NeedsCalibration();
|
||||
break;
|
||||
|
||||
case AndroidGeckoEvent::SENSOR_EVENT:
|
||||
{
|
||||
mPendingSensorEvents = false;
|
||||
switch (curEvent->Flags()) {
|
||||
case hal::SENSOR_ORIENTATION:
|
||||
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ORIENTATION,
|
||||
curEvent->X(),
|
||||
-curEvent->Y(),
|
||||
-curEvent->Z());
|
||||
InfallibleTArray<float> values;
|
||||
mozilla::hal::SensorType type = (mozilla::hal::SensorType) curEvent->Flags();
|
||||
|
||||
switch (type) {
|
||||
case hal::SENSOR_ORIENTATION:
|
||||
values.AppendElement(curEvent->X());
|
||||
values.AppendElement(-curEvent->Y());
|
||||
values.AppendElement(-curEvent->Z());
|
||||
break;
|
||||
|
||||
case hal::SENSOR_ACCELERATION:
|
||||
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION,
|
||||
-curEvent->X(),
|
||||
curEvent->Y(),
|
||||
curEvent->Z());
|
||||
break;
|
||||
|
||||
case hal::SENSOR_LINEAR_ACCELERATION:
|
||||
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_LINEAR_ACCELERATION,
|
||||
-curEvent->X(),
|
||||
curEvent->Y(),
|
||||
curEvent->Z());
|
||||
break;
|
||||
|
||||
case hal::SENSOR_GYROSCOPE:
|
||||
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_GYROSCOPE,
|
||||
-curEvent->X(),
|
||||
curEvent->Y(),
|
||||
curEvent->Z());
|
||||
case hal::SENSOR_ACCELERATION:
|
||||
case hal::SENSOR_LINEAR_ACCELERATION:
|
||||
case hal::SENSOR_GYROSCOPE:
|
||||
values.AppendElement(-curEvent->X());
|
||||
values.AppendElement(curEvent->Y());
|
||||
values.AppendElement(curEvent->Z());
|
||||
break;
|
||||
|
||||
default:
|
||||
__android_log_print(ANDROID_LOG_ERROR, "Gecko", "### SENSOR_EVENT fired, but type wasn't known %d", curEvent->Flags());
|
||||
__android_log_print(ANDROID_LOG_ERROR,
|
||||
"Gecko", "### SENSOR_EVENT fired, but type wasn't known %d",
|
||||
type);
|
||||
}
|
||||
break;
|
||||
|
||||
const hal::SensorAccuracyType &accuracy = (hal::SensorAccuracyType) curEvent->MetaState();
|
||||
hal::SensorData sdata(type, PR_Now(), values, accuracy);
|
||||
hal::NotifySensorChange(sdata);
|
||||
}
|
||||
break;
|
||||
|
||||
case AndroidGeckoEvent::LOCATION_EVENT: {
|
||||
if (!gLocationCallback)
|
||||
|
@ -390,7 +380,7 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait)
|
|||
InfallibleTArray<float> values;
|
||||
values.AppendElement(curEvent->Distance());
|
||||
|
||||
hal::SensorData sdata(hal::SENSOR_PROXIMITY, PR_Now(), values);
|
||||
hal::SensorData sdata(hal::SENSOR_PROXIMITY, PR_Now(), values, hal::SENSOR_ACCURACY_UNKNOWN);
|
||||
hal::NotifySensorChange(sdata);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -41,10 +41,12 @@ interface nsIDOMWindow;
|
|||
[scriptable, uuid(1B406E32-CF42-471E-A470-6FD600BF4C7B)]
|
||||
interface nsIDeviceMotionData : nsISupports
|
||||
{
|
||||
const unsigned long TYPE_ACCELERATION = 0;
|
||||
const unsigned long TYPE_ORIENTATION = 1;
|
||||
const unsigned long TYPE_LINEAR_ACCELERATION = 2;
|
||||
const unsigned long TYPE_GYROSCOPE = 3;
|
||||
// Keep in sync with hal/HalSensor.h
|
||||
const unsigned long TYPE_ORIENTATION = 0;
|
||||
const unsigned long TYPE_ACCELERATION = 1;
|
||||
const unsigned long TYPE_PROXIMITY = 2;
|
||||
const unsigned long TYPE_LINEAR_ACCELERATION = 3;
|
||||
const unsigned long TYPE_GYROSCOPE = 4;
|
||||
|
||||
readonly attribute unsigned long type;
|
||||
|
||||
|
@ -72,14 +74,3 @@ interface nsIDeviceMotion : nsISupports
|
|||
[noscript] void removeWindowListener(in nsIDOMWindow aWindow);
|
||||
|
||||
};
|
||||
|
||||
/* for use by IPC system to notify non-chrome processes of
|
||||
* device motion events
|
||||
*/
|
||||
[uuid(C12C0157-DCFF-41B5-83F3-89179BF6CA4E)]
|
||||
interface nsIDeviceMotionUpdate : nsIDeviceMotion
|
||||
{
|
||||
/* must be called on the main thread or else */
|
||||
void deviceMotionChanged(in unsigned long type, in double x, in double y, in double z);
|
||||
void needsCalibration();
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче