Closed
Bug 512345
Opened 15 years ago
Closed 15 years ago
Implement accelerometer support for Linux and Maemo
Categories
(Core :: Widget: Gtk, defect)
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)
11.13 KB,
patch
|
Details | Diff | 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 1•15 years ago
|
||
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-
Assignee | ||
Comment 2•15 years ago
|
||
(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.
Comment 3•15 years ago
|
||
#ifdef NS_OSSO works. It is defined on any nokia device running maemo.
Comment 4•15 years ago
|
||
(we define it)
Assignee | ||
Comment 5•15 years ago
|
||
Addresses review comments.
Attachment #396308 -
Attachment is obsolete: true
Attachment #396413 -
Flags: review?(doug.turner)
Assignee | ||
Comment 6•15 years ago
|
||
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)
Assignee | ||
Comment 7•15 years ago
|
||
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.
Assignee | ||
Comment 8•15 years ago
|
||
Er, hang on, that interface may be specific to Maemo I think, others might use a different sysfs location. Ignore previous whinge.
Comment 9•15 years ago
|
||
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.
Comment 10•15 years ago
|
||
michael, we g2g on the review then? should I ignore comments 7 and 8?
Assignee | ||
Comment 11•15 years ago
|
||
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)?
Comment 12•15 years ago
|
||
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.
Assignee | ||
Comment 13•15 years ago
|
||
(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.
Assignee | ||
Comment 14•15 years ago
|
||
Attachment #396416 -
Attachment is obsolete: true
Attachment #396690 -
Flags: review?(doug.turner)
Attachment #396416 -
Flags: review?(doug.turner)
Assignee | ||
Comment 15•15 years ago
|
||
After looking further into things, I think 255.0 is the wrong value for Thinkpads. Not that I have one. :(
Assignee | ||
Comment 16•15 years ago
|
||
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)
Assignee | ||
Comment 17•15 years ago
|
||
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 18•15 years ago
|
||
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 19•15 years ago
|
||
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-
Assignee | ||
Comment 20•15 years ago
|
||
(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?
Comment 21•15 years ago
|
||
> 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?
Assignee | ||
Comment 22•15 years ago
|
||
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 23•15 years ago
|
||
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 24•15 years ago
|
||
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+
Comment 25•15 years ago
|
||
good suggestions olli.
Try builds:
https://build.mozilla.org/tryserver-builds/dougt@mozilla.com-try-80f4cdc242b9/
Assignee | ||
Comment 26•15 years ago
|
||
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
Assignee | ||
Updated•15 years ago
|
Keywords: checkin-needed
Comment 27•15 years ago
|
||
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
Updated•15 years ago
|
Attachment #397243 -
Flags: approval1.9.2?
Comment 28•15 years ago
|
||
patch 6 is olli's comments incorporated.
Assignee | ||
Comment 29•15 years ago
|
||
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
Comment 30•15 years ago
|
||
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 +}
Assignee | ||
Comment 31•15 years ago
|
||
Yeah, that's good.
Updated•15 years ago
|
Attachment #397243 -
Flags: approval1.9.2? → approval1.9.2+
Comment 32•15 years ago
|
||
status1.9.2:
--- → beta1-fixed
Comment 33•15 years ago
|
||
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)?
Comment 34•15 years ago
|
||
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.
Description
•