Closed Bug 512345 Opened 15 years ago Closed 15 years ago

Implement accelerometer support for Linux and Maemo

Categories

(Core :: Widget: Gtk, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
Tracking Status
status1.9.2 --- beta1-fixed

People

(Reporter: ventnor.bugzilla, Assigned: ventnor.bugzilla)

References

Details

Attachments

(1 file, 7 obsolete files)

Attached patch Patch (obsolete) — Splinter Review
Bug 485943 implemented accelerometer support for OSX and some WinCE devices. This adds support for Maemo 5, as well as the laptop models that Linux supports (applesmc or hdaps).
Attachment #396308 - Flags: review?(doug.turner)
Comment on attachment 396308 [details] [diff] [review] Patch Nice. Awesome. Great. A few small nits, but otherwise fine: +#define NORMALIZE_FACTOR 255.0 +#define MAEMO_NORMALIZE_FACTOR -1000.0 Lets just have one #define set based on #ifdef's: #ifdef NS_MAEMO #define NORMALIZE_FACTOR 255.0 #else ... nsAccelerometerGtk::Startup could this be data driven so that we don't have to add more code when another linux variate is added? For example, something like: typedef struct { char * fileName; int type; } Accelerometers; Accelerometers gAccelerometers[] = { {"/sys/devices/platform/applesmc.768/position", eAppleSensor}, ... {} } for (x in gAccelerometers) // <-- don't you wish C had that? { if (access(x.fileName ...) mType = x.type mPositionFile = mCalibrateFile = ... Also, check out bug 512237. Smaug mentioned two thing we should change with the cocoa port that must apply to all implementations. One more patch, and I think we are there.
Attachment #396308 - Flags: review?(doug.turner) → review-
(In reply to comment #1) > (From update of attachment 396308 [details] [diff] [review]) > Nice. Awesome. Great. A few small nits, but otherwise fine: > > +#define NORMALIZE_FACTOR 255.0 > +#define MAEMO_NORMALIZE_FACTOR -1000.0 > > > Lets just have one #define set based on #ifdef's: > > #ifdef NS_MAEMO > #define NORMALIZE_FACTOR 255.0 > #else > ... Does NS_MAEMO exist? I don't know about making this conditional on Maemo (despite the variable names) since this depends on the presence of a certain device and Linux driver, not just for Maemo (even though Maemo is the only major user so far). This is why I check the sysfs rather than use ifdefs.
#ifdef NS_OSSO works. It is defined on any nokia device running maemo.
(we define it)
Attached patch Patch 2 (obsolete) — Splinter Review
Addresses review comments.
Attachment #396308 - Attachment is obsolete: true
Attachment #396413 - Flags: review?(doug.turner)
Attached patch Patch 2.1 (obsolete) — Splinter Review
There's actually a quirk in the applesmc driver we need to deal with, to do with calibration.
Attachment #396413 - Attachment is obsolete: true
Attachment #396416 - Flags: review?(doug.turner)
Attachment #396413 - Flags: review?(doug.turner)
OK, I really really REALLY don't want to make that third accelerometer interface dependent on Maemo or OSSO. I've seen videos of "desktop" Linuxes on some other tablets or mobile devices and after doing some research they seem to be using the same brand of sensor.
Er, hang on, that interface may be specific to Maemo I think, others might use a different sysfs location. Ignore previous whinge.
michael, don't worry about pref'ing the update interval, or filtering the update notifications. We can do this in the super class. i have a patch that I need to attach somewhere that does this.
michael, we g2g on the review then? should I ignore comments 7 and 8?
The latest patch implements filtering of update notifications, should I remove that first? Also, you said you were pref'ing the update interval, what should I make the backend timer interval (currently 50ms)?
Michael, take a look at the work in progress in bug 512237. I think we need to tweak it a bit due to the lack of std::abs on wince.
(In reply to comment #12) > Michael, take a look at the work in progress in bug 512237. I think we need to > tweak it a bit due to the lack of std::abs on wince. I think there's PR_ABS, though. I'll update the patch based on that.
Attached patch Patch 3 (obsolete) — Splinter Review
Attachment #396416 - Attachment is obsolete: true
Attachment #396690 - Flags: review?(doug.turner)
Attachment #396416 - Flags: review?(doug.turner)
Depends on: 512237
After looking further into things, I think 255.0 is the wrong value for Thinkpads. Not that I have one. :(
Attached patch Patch 4 (obsolete) — Splinter Review
hdaps-gl tells us that HDAPS needs its own normalisation factor.
Attachment #396690 - Attachment is obsolete: true
Attachment #396713 - Flags: review?(doug.turner)
Attachment #396690 - Flags: review?(doug.turner)
Attached patch Patch 4.1 (obsolete) — Splinter Review
Whoops, had a typo in there.
Attachment #396713 - Attachment is obsolete: true
Attachment #396970 - Flags: review?(doug.turner)
Attachment #396713 - Flags: review?(doug.turner)
Comment on attachment 396970 [details] [diff] [review] Patch 4.1 >+// The proposal for accelerometer events defines values between -1 and 1. >+#define APPLE_NORMALIZE_FACTOR 255.0 >+#define IBM_NORMALIZE_FACTOR 180.0 >+#define MAEMO_NORMALIZE_FACTOR -1000.0 Lets drop these in favor of adding a X_NORMALIZE_FACTOR, Y_NORMALIZE_FACTOR, Z_NORMALIZE_FACTOR to the Accelerometer. >+ // MacBook >+ {"/sys/devices/platform/applesmc.768/position", >+ "/sys/devices/platform/applesmc.768/calibrate", >+ eAppleSensor 255.0 255.0 -255.0 }, I wonder if you can change this switch to be completely data driven (so that you don't have a switch at all?) Maybe create another structure that you can copy Accelerometer into, and have the 3 (x,y,z) calibration fields in it? >+ switch (self->mType) { >+ case eAppleSensor: >+ { >+ if (access(gAccelerometers[i].mPosition, R_OK) != 0) >+ continue; Can we just call fopen instead of access?
Comment on attachment 396970 [details] [diff] [review] Patch 4.1 btw, they don't have to be actually name X_NORM*_FACTOR :-)
Attachment #396970 - Flags: review?(doug.turner) → review-
(In reply to comment #18) > (From update of attachment 396970 [details] [diff] [review]) > > > >+// The proposal for accelerometer events defines values between -1 and 1. > >+#define APPLE_NORMALIZE_FACTOR 255.0 > >+#define IBM_NORMALIZE_FACTOR 180.0 > >+#define MAEMO_NORMALIZE_FACTOR -1000.0 > > > Lets drop these in favor of adding a X_NORMALIZE_FACTOR, Y_NORMALIZE_FACTOR, > Z_NORMALIZE_FACTOR to the Accelerometer. > > >+ // MacBook > >+ {"/sys/devices/platform/applesmc.768/position", > >+ "/sys/devices/platform/applesmc.768/calibrate", > >+ eAppleSensor > 255.0 > 255.0 > -255.0 > }, I thought about doing that but I didn't like the idea of storing a float and constantly having to retrieve it from the struct. Should I just add it as a magic number rather than a macro? > I wonder if you can change this switch to be completely data driven (so that > you don't have a switch at all?) Maybe create another structure that you can > copy Accelerometer into, and have the 3 (x,y,z) calibration fields in it? > > > >+ switch (self->mType) { > >+ case eAppleSensor: > >+ { I don't really understand what you mean here. The problem is that each accelerometer driver provides the coordinates in different ways that requires their own parsing. > >+ if (access(gAccelerometers[i].mPosition, R_OK) != 0) > >+ continue; > > Can we just call fopen instead of access? IIRC doesn't access detect more errors more cleanly?
> I thought about doing that but I didn't like the idea of storing a float and constantly having to retrieve it from the struct. Should I just add it as a magic number rather than a macro? I just didn't like having this sort of data floating around outside of the structure which already has device specific data (like the file path and sensor type). >I don't really understand what you mean here. Just ignore. I was hoping that it could be data driven, but it does look like each does a slightly different thing :( > IIRC doesn't access detect more errors more cleanly? Such as? Either you get a FILE * or not. that is all we need right?
Attached patch Patch 5 (obsolete) — Splinter Review
Call me old fashioned, but I'd prefer not to have to read from memory any more than we have to when we're doing polling as frequent as this.
Attachment #396970 - Attachment is obsolete: true
Attachment #397243 - Flags: review?(doug.turner)
Comment on attachment 397243 [details] [diff] [review] Patch 5 olli, would you mind looking at this patch as well.
Attachment #397243 - Flags: review?(doug.turner)
Attachment #397243 - Flags: review?(Olli.Pettay)
Attachment #397243 - Flags: review+
Comment on attachment 397243 [details] [diff] [review] Patch 5 >diff --git a/widget/src/gtk2/nsAccelerometerGtk.cpp b/widget/src/gtk2/nsAccelerometerGtk.cpp Actually, is there anything gtk specific in the implementation? If not, perhaps the files could be called just nsAccelerometer.h/cpp, or nsAccelerometerUnix.h/cpp. (I'm not sure about the status of QT port, but at least on Linux that could probably use the same Accelerometer implementation.) >+void nsAccelerometerGtk::Startup() ... >+ if (!mCalibrateFile) { >+ fclose(mPositionFile); mPositionFile = NULL; >+void nsAccelerometerGtk::Shutdown() ... >+ if (mPositionFile) >+ fclose(mPositionFile); if (mPositionFile) { fclose(mPositionFile); mPositionFile = NULL; } ... >+ if (mCalibrateFile) >+ fclose(mCalibrateFile); if (mCalibrateFile) { fclose(mCalibrateFile); mCalibrateFile = NULL; } mType = eNoSensor;
Attachment #397243 - Flags: review?(Olli.Pettay) → review+
Attached patch Patch 6Splinter Review
dougt, I'll need you to check this in for me. If you could make a blog post asking Linux Thinkpad users to test things out, that would also be appreciated :)
Attachment #397243 - Attachment is obsolete: true
Keywords: checkin-needed
okay. pushed. Will post something soon -- as soon as there are Minefield nightlies available. http://hg.mozilla.org/mozilla-central/rev/860134e65933 Great work!
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Attachment #397243 - Flags: approval1.9.2?
patch 6 is olli's comments incorporated.
Oops, I forgot to add the mType = eNoSensor; line into Shutdown() like Olli wanted... dougt, could you check that line in as a followup?
Keywords: checkin-needed
I think I did: 2.198 + fclose(mCalibrateFile); 2.199 + mCalibrateFile = nsnull; 2.200 + } 2.201 + 2.202 + mType = eNoSensor; 2.203 + 2.204 + if (mUpdateTimer) { 2.205 + mUpdateTimer->Cancel(); 2.206 + mUpdateTimer = nsnull; 2.207 + } 2.208 +}
Yeah, that's good.
Attachment #397243 - Flags: approval1.9.2? → approval1.9.2+
One question about power management :) Are you parsing acc data all the time? is it going to be disconnected when device goes to idle state or when browser page is not visible on the screen (browser goes to background)?
romaxa, power management was not considered during the implementation of this feature. We will not disconnect creating events during system idle. Please file a new bug.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: