BrickUp API Service for Docker version.

HMC5883L.h 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*****************************************************************************/
  2. // Function: Header file for HMC5883L
  3. // Hardware: Grove - 3-Axis Digital Compass
  4. // Arduino IDE: Arduino-1.0
  5. // Author: Frankie.Chu
  6. // Date: Jan 10,2013
  7. // Version: v1.0
  8. // by www.seeedstudio.com
  9. //
  10. // This library is free software; you can redistribute it and/or
  11. // modify it under the terms of the GNU Lesser General Public
  12. // License as published by the Free Software Foundation; either
  13. // version 2.1 of the License, or (at your option) any later version.
  14. //
  15. // This library is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. // Lesser General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU Lesser General Public
  21. // License along with this library; if not, write to the Free Software
  22. // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. //
  24. /*******************************************************************************/
  25. #ifndef __HMC5883L_H__
  26. #define __HMC5883L_H__
  27. #include <Arduino.h>
  28. #include <Wire.h>
  29. #define HMC5883L_ADDRESS 0x1E
  30. #define CONFIGURATION_REGISTERA 0x00
  31. #define CONFIGURATION_REGISTERB 0x01
  32. #define MODE_REGISTER 0x02
  33. #define DATA_REGISTER_BEGIN 0x03
  34. #define MEASUREMENT_CONTINUOUS 0x00
  35. #define MEASUREMENT_SINGLE_SHOT 0x01
  36. #define MEASUREMENT_IDLE 0x03
  37. #define ERRORCODE_1 "Entered scale was not valid, valid gauss values are: 0.88, 1.3, 1.9, 2.5, 4.0, 4.7, 5.6, 8.1"
  38. #define ERRORCODE_1_NUM 1
  39. struct MagnetometerScaled
  40. {
  41. float XAxis;
  42. float YAxis;
  43. float ZAxis;
  44. };
  45. struct MagnetometerRaw
  46. {
  47. short XAxis;
  48. short YAxis;
  49. short ZAxis;
  50. };
  51. class HMC5883L
  52. {
  53. public: // used by xadow phone
  54. void initCompass();
  55. int getCompass();
  56. public:
  57. HMC5883L();
  58. MagnetometerRaw readRawAxis();
  59. MagnetometerScaled readScaledAxis();
  60. short setMeasurementMode(uint8_t mode);
  61. short setScale(float gauss);
  62. char* getErrorText(short errorCode);
  63. protected:
  64. void write(short address, short byte);
  65. uint8_t* read(short address, short length);
  66. private:
  67. float m_Scale;
  68. };
  69. #endif