diff options
author | hans@chromium.org <hans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-27 19:52:36 +0000 |
---|---|---|
committer | hans@chromium.org <hans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-27 19:52:36 +0000 |
commit | dbdd535d60e77e926e005770b3f7406f73b161c9 (patch) | |
tree | 7fc5872ce0021c1b1f475bab53ac2ab950607d5f /chrome | |
parent | 3e53c10b59d57a012b5d40f3c66ec2a30b11245c (diff) | |
download | chromium_src-dbdd535d60e77e926e005770b3f7406f73b161c9.zip chromium_src-dbdd535d60e77e926e005770b3f7406f73b161c9.tar.gz chromium_src-dbdd535d60e77e926e005770b3f7406f73b161c9.tar.bz2 |
Added tested and corrected accelerometer support for the following MacBook / MacBook Pro models:
- MacBookPro2,2
- MacBookPro3,1
- MacBookPro4,1
- MacBookPro5,1
- MacBookPro6,2
- MacBookPro7,1
This patch fixes the axis inversion problems on these.
Landing for Leandro Gracia Gil <leandrogracia@google.com>.
Original code review: http://codereview.chromium.org/3177035/show
BUG=44654
TEST=None
Review URL: http://codereview.chromium.org/3275002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57721 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/device_orientation/accelerometer_mac.cc | 112 | ||||
-rw-r--r-- | chrome/browser/device_orientation/accelerometer_mac.h | 4 |
2 files changed, 69 insertions, 47 deletions
diff --git a/chrome/browser/device_orientation/accelerometer_mac.cc b/chrome/browser/device_orientation/accelerometer_mac.cc index eb0990710..8634db2 100644 --- a/chrome/browser/device_orientation/accelerometer_mac.cc +++ b/chrome/browser/device_orientation/accelerometer_mac.cc @@ -59,22 +59,32 @@ namespace device_orientation { -// Per-axis sensor data. -struct AccelerometerMac::AxisData { - // Non-zero if the axis is valid in this sensor. - int enabled; - - // Location in struct of first byte. - int index; +struct AccelerometerMac::GenericMacbookSensor { + // Name of device to be read. + const char* service_name; // Number of bytes of the axis data. - int size; + int axis_size; - // Value meaning "zero g". + // Default calibration value for zero g. float zero_g; - // (can be negative if the sensor axis is reversed). + // Default calibration value for one g (negative when axis is inverted). float one_g; + + // Kernel function index. + unsigned int function; + + // Size of the sensor record to be sent/received. + unsigned int record_size; +}; + +struct AccelerometerMac::AxisData { + // Location of the first byte representing the axis in the sensor data. + int index; + + // Axis inversion flag. The value changes often between models. + bool inverted; }; // Sudden Motion Sensor descriptor. @@ -82,17 +92,16 @@ struct AccelerometerMac::SensorDescriptor { // Prefix of model to be tested. const char* model_name; - // Name of device to be read. - const char* service_name; - - // Kernel function index. - unsigned int function; - - // Size of record to be sent/received. - unsigned int record_size; + // Axis-specific data (x,y,z order). + AxisData axis[3]; +}; - // Description of three axes (x,y,z). - AxisData axes[3]; +// Typical sensor parameters in MacBook models. +const AccelerometerMac::GenericMacbookSensor + AccelerometerMac::kGenericSensor = { + "SMCMotionSensor", 2, + 0, 251, + 5, 40 }; // Supported sensor descriptors. Add entries here to enhance compatibility. @@ -100,26 +109,33 @@ struct AccelerometerMac::SensorDescriptor { const AccelerometerMac::SensorDescriptor AccelerometerMac::kSupportedSensors[] = { // Tested by leandrogracia on a 15'' MacBook Pro. - { "MacBookPro5,4", "SMCMotionSensor", 5, 40, { - { 1, 0, 2, 0, 251 }, - { 1, 2, 2, 0, 251 }, - { 1, 4, 2, 0, 251 } - } }, + { "MacBookPro2,2", { { 0, true }, { 2, true }, { 4, false } } }, + + // Tested by leandrogracia on a 15'' MacBook Pro. + { "MacBookPro3,1", { { 0, false }, { 2, true }, { 4, true } } }, + + // Tested by leandrogracia on a 15'' MacBook Pro. + { "MacBookPro4,1", { { 0, true }, { 2, true }, { 4, false } } }, + + // Tested by leandrogracia on a 15'' MacBook Pro. + { "MacBookPro5,1", { { 0, false }, { 2, false }, { 4, false } } }, + + // Tested by leandrogracia on a 15'' MacBook Pro. + { "MacBookPro5,4", { { 0, false }, { 2, false }, { 4, false } } }, // Tested by leandrogracia on a 13'' MacBook Pro. - { "MacBookPro5,5", "SMCMotionSensor", 5, 40, { - { 1, 0, 2, 0, -251 }, - { 1, 2, 2, 0, -251 }, - { 1, 4, 2, 0, 251 } - } }, + { "MacBookPro5,5", { { 0, true }, { 2, true }, { 4, false } } }, + + // Tested by leandrogracia on a 15'' MacBook Pro. + { "MacBookPro6,2", { { 0, true }, { 2, false }, { 4, true } } }, + + // Tested by leandrogracia on a 13'' MacBook Pro. + { "MacBookPro7,1", { { 0, true }, { 2, true }, { 4, false } } }, // Generic MacBook accelerometer sensor data. - // Added for forward compatibility (there may be problems with inverted axes). - {"", "SMCMotionSensor", 5, 40, { - { 1, 0, 2, 0, -251 }, - { 1, 2, 2, 0, -251 }, - { 1, 4, 2, 0, 251 } - } } + // Added for compatibility with non-tested models + // Note: there may be problems with inverted axes. + { "", { { 0, true }, { 2, true }, { 4, false } } } }; // Create a AccelerometerMac object and return NULL if no valid sensor found. @@ -153,10 +169,10 @@ bool AccelerometerMac::GetOrientation(Orientation* orientation) { std::fill(output_record_.begin(), output_record_.end(), 0x00); // Read record data from memory. - const size_t kInputSize = sensor_->record_size; - size_t output_size = sensor_->record_size; + const size_t kInputSize = kGenericSensor.record_size; + size_t output_size = kGenericSensor.record_size; - if (IOConnectCallStructMethod(io_connection_, sensor_->function, + if (IOConnectCallStructMethod(io_connection_, kGenericSensor.function, static_cast<const char *>(&input_record_[0]), kInputSize, &output_record_[0], &output_size) != KERN_SUCCESS) { return false; @@ -167,8 +183,8 @@ bool AccelerometerMac::GetOrientation(Orientation* orientation) { for (int i = 0; i < 3; ++i) { int sensor_value = 0; - int size = sensor_->axes[i].size; - int index = sensor_->axes[i].index; + int size = kGenericSensor.axis_size; + int index = sensor_->axis[i].index; // Important Note: little endian is assumed as this code is mac-only // and PowerPC is currently not supported. @@ -177,8 +193,8 @@ bool AccelerometerMac::GetOrientation(Orientation* orientation) { sensor_value = ExtendSign(sensor_value, size); // Correct value using the current calibration. - axis_value[i] = static_cast<float>(sensor_value - sensor_->axes[i].zero_g) / - sensor_->axes[i].one_g; + axis_value[i] = static_cast<float>(sensor_value - kGenericSensor.zero_g) / + kGenericSensor.one_g; // Make sure we reject any NaN or infinite values. if (!isfinite(axis_value[i])) @@ -189,6 +205,10 @@ bool AccelerometerMac::GetOrientation(Orientation* orientation) { axis_value[i] = -1.0; else if (axis_value[i] > 1.0) axis_value[i] = 1.0; + + // Apply axis inversion. + if (sensor_->axis[i].inverted) + axis_value[i] = -axis_value[i]; } // Transform the accelerometer values to W3C draft angles. @@ -268,7 +288,7 @@ bool AccelerometerMac::Init() { // Get a dictionary of the services matching to the one in the sensor. CFMutableDictionaryRef dict = - IOServiceMatching(sensor_candidate->service_name); + IOServiceMatching(kGenericSensor.service_name); if (dict == NULL) continue; @@ -299,8 +319,8 @@ bool AccelerometerMac::Init() { return false; // Allocate and initialize input/output records. - input_record_.resize(sensor_->record_size, 0x01); - output_record_.resize(sensor_->record_size, 0x00); + input_record_.resize(kGenericSensor.record_size, 0x01); + output_record_.resize(kGenericSensor.record_size, 0x00); // Try to retrieve the current orientation. Orientation test_orientation; diff --git a/chrome/browser/device_orientation/accelerometer_mac.h b/chrome/browser/device_orientation/accelerometer_mac.h index 873ff79..5771cea 100644 --- a/chrome/browser/device_orientation/accelerometer_mac.h +++ b/chrome/browser/device_orientation/accelerometer_mac.h @@ -78,10 +78,12 @@ class AccelerometerMac : public DataFetcher { // Extend the sign of an integer of size bytes to a 32-bit one. static int ExtendSign(int value, size_t size); + struct GenericMacbookSensor; struct SensorDescriptor; struct AxisData; - // List of supported sensors. + // Generic sensor data and list of supported sensors. + static const GenericMacbookSensor kGenericSensor; static const SensorDescriptor kSupportedSensors[]; // Local sensor if supported, else NULL. |