From 2f3f91a54a5172dbfc26a2a7db8f1175d64070dc Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Mon, 12 Oct 2009 20:08:52 -0700 Subject: [PATCH] Bug 521848 - Accelerometer on newer MBP have x and y reversed. r=josh --HG-- extra : rebase_source : f2945dbb9820b944dbedfaea43c3fad7926cd966 --- widget/src/cocoa/nsAccelerometerX.mm | 36 +++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/widget/src/cocoa/nsAccelerometerX.mm b/widget/src/cocoa/nsAccelerometerX.mm index 78f673c8220b..f248524765b2 100644 --- a/widget/src/cocoa/nsAccelerometerX.mm +++ b/widget/src/cocoa/nsAccelerometerX.mm @@ -38,6 +38,13 @@ #include "nsIServiceManager.h" #include "stdlib.h" +#include +#include +#include + +#define MODEL_NAME_LENGTH 64 +static char gModelName[MODEL_NAME_LENGTH]; + nsAccelerometerX::nsAccelerometerX() { } @@ -116,12 +123,22 @@ nsAccelerometerX::UpdateHandler(nsITimer *aTimer, void *aClosure) const int normalizeFactor = 250.5; - // x seems to be the opposite of what i would expect. we want lifting the - // right side of the MacBookPro to mean a negative x. - - xf = ((float)data->x) / normalizeFactor * (-1); - yf = ((float)data->y) / normalizeFactor; - zf = ((float)data->z) / normalizeFactor; + if (!strcmp(gModelName, "MacBookPro5,1")) { + xf = ((float)data->x) / normalizeFactor; + yf = (((float)data->y) / normalizeFactor) * -1; + zf = ((float)data->z) / normalizeFactor; + } + else if (!strcmp(gModelName, "MacBookPro5,3")) { + xf = ((float)data->y) / normalizeFactor; + yf = (((float)data->x) / normalizeFactor) * -1; + zf = (((float)data->z) / normalizeFactor) * -1; + } + else + { + xf = (((float)data->x) / normalizeFactor) * -1; + yf = ((float)data->y) / normalizeFactor; + zf = ((float)data->z) / normalizeFactor; + } free(input); free(output); @@ -162,6 +179,13 @@ void nsAccelerometerX::Startup() mach_port_deallocate(mach_task_self(), port); + /* get the version of the hardware we are running on. */ + int mib[2]; + size_t len = MODEL_NAME_LENGTH; + mib[0] = CTL_HW; + mib[1] = HW_MODEL; + sysctl(mib, 2, gModelName, &len, NULL, 0); + mUpdateTimer = do_CreateInstance("@mozilla.org/timer;1"); if (mUpdateTimer) mUpdateTimer->InitWithFuncCallback(UpdateHandler,