OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | |
5 // This file is based on the SMSLib library. | |
6 // | |
7 // SMSLib Sudden Motion Sensor Access Library | |
8 // Copyright (c) 2010 Suitable Systems | |
9 // All rights reserved. | |
10 // | |
11 // Developed by: Daniel Griscom | |
12 // Suitable Systems | |
13 // http://www.suitable.com | |
14 // | |
15 // Permission is hereby granted, free of charge, to any person obtaining a | |
16 // copy of this software and associated documentation files (the | |
17 // "Software"), to deal with the Software without restriction, including | |
18 // without limitation the rights to use, copy, modify, merge, publish, | |
19 // distribute, sublicense, and/or sell copies of the Software, and to | |
20 // permit persons to whom the Software is furnished to do so, subject to | |
21 // the following conditions: | |
22 // | |
23 // - Redistributions of source code must retain the above copyright notice, | |
24 // this list of conditions and the following disclaimers. | |
25 // | |
26 // - Redistributions in binary form must reproduce the above copyright | |
27 // notice, this list of conditions and the following disclaimers in the | |
28 // documentation and/or other materials provided with the distribution. | |
29 // | |
30 // - Neither the names of Suitable Systems nor the names of its | |
31 // contributors may be used to endorse or promote products derived from | |
32 // this Software without specific prior written permission. | |
33 // | |
34 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
35 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
36 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
37 // IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR | |
38 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
39 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
40 // SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. | |
41 // | |
42 // For more information about SMSLib, see | |
43 // <http://www.suitable.com/tools/smslib.html> | |
44 // or contact | |
45 // Daniel Griscom | |
46 // Suitable Systems | |
47 // 1 Centre Street, Suite 204 | |
48 // Wakefield, MA 01880 | |
49 // (781) 665-0053 | |
50 | 4 |
51 #ifndef CONTENT_BROWSER_DEVICE_ORIENTATION_ACCELEROMETER_MAC_H_ | 5 #ifndef CONTENT_BROWSER_DEVICE_ORIENTATION_ACCELEROMETER_MAC_H_ |
52 #define CONTENT_BROWSER_DEVICE_ORIENTATION_ACCELEROMETER_MAC_H_ | 6 #define CONTENT_BROWSER_DEVICE_ORIENTATION_ACCELEROMETER_MAC_H_ |
53 #pragma once | 7 #pragma once |
54 | 8 |
55 #include <vector> | 9 #include <vector> |
56 | 10 |
57 #include <IOKit/IOKitLib.h> | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "content/browser/device_orientation/data_fetcher.h" |
58 | 14 |
59 #include "base/compiler_specific.h" | 15 class SuddenMotionSensor; |
60 #include "content/browser/device_orientation/data_fetcher.h" | |
61 | 16 |
62 namespace device_orientation { | 17 namespace device_orientation { |
63 | 18 |
64 // Provides an easy-to-use interface to retrieve data | |
65 // from the MacBook family accelerometer. | |
66 class AccelerometerMac : public DataFetcher { | 19 class AccelerometerMac : public DataFetcher { |
67 public: | 20 public: |
68 static DataFetcher* Create(); | 21 static DataFetcher* Create(); |
69 | 22 |
70 // Implement DataFetcher. | 23 // Implement DataFetcher. |
71 virtual bool GetOrientation(Orientation* orientation) OVERRIDE; | 24 virtual bool GetOrientation(Orientation* orientation) OVERRIDE; |
72 | 25 |
73 virtual ~AccelerometerMac(); | 26 virtual ~AccelerometerMac(); |
74 | 27 |
75 private: | 28 private: |
76 AccelerometerMac(); | 29 AccelerometerMac(); |
77 bool Init(); | 30 bool Init(); |
78 | 31 |
79 // Extend the sign of an integer of size bytes to a 32-bit one. | 32 scoped_ptr<SuddenMotionSensor> sudden_motion_sensor_; |
80 static int ExtendSign(int value, size_t size); | |
81 | |
82 struct GenericMacbookSensor; | |
83 struct SensorDescriptor; | |
84 struct AxisData; | |
85 | |
86 // Generic sensor data and list of supported sensors. | |
87 static const GenericMacbookSensor kGenericSensor; | |
88 static const SensorDescriptor kSupportedSensors[]; | |
89 | |
90 // Local sensor if supported, else NULL. | |
91 const SensorDescriptor* sensor_; | |
92 | |
93 // IOKit connection to the local sensor. | |
94 io_connect_t io_connection_; | |
95 | |
96 // Input memory used for sensor I/O. | |
97 std::vector<char> input_record_; | |
98 | |
99 // Output memory used for sensor I/O. | |
100 std::vector<char> output_record_; | |
101 }; | 33 }; |
102 | 34 |
103 } // namespace device_orientation | 35 } // namespace device_orientation |
104 | 36 |
105 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_ACCELEROMETER_MAC_H_ | 37 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_ACCELEROMETER_MAC_H_ |
OLD | NEW |