GY-63_MS5611/libraries/hmc6352/hmc6352.h

111 lines
2.3 KiB
C
Raw Normal View History

2020-11-27 05:16:22 -05:00
#pragma once
//
2013-09-30 11:00:55 -04:00
// FILE: hmc6352.h
// AUTHOR: Rob Tillaart
2022-11-09 08:34:02 -05:00
// VERSION: 0.3.2
2013-09-30 11:00:55 -04:00
// PURPOSE: HMC6352 library for Arduino
2021-06-07 12:21:42 -04:00
2013-09-30 11:00:55 -04:00
2020-11-27 05:16:22 -05:00
#include "Wire.h"
#include "Arduino.h"
2022-11-09 08:34:02 -05:00
#define HMC6352_LIB_VERSION (F("0.3.2"))
2021-06-07 12:21:42 -04:00
// status function calls
2021-12-19 07:57:35 -05:00
#define HMC6532_OK 0
#define HMC6352_ERROR_PARAM1 -20
#define HMC6352_ERROR_PARAM2 -21
2021-06-07 12:21:42 -04:00
// I2C related errors
2021-12-19 07:57:35 -05:00
#define HMC6532_I2C_OK 0
#define HMC6532_I2C_ERROR_BUFFEROVERFLOW -1
#define HMC6532_I2C_ERROR_ADDR_NACK -2
#define HMC6532_I2C_ERROR_DATA_NACK -3
#define HMC6532_I2C_ERROR_OTHER -4
#define HMC6352_I2C_ERROR_REQ_FROM -10
2021-06-07 12:21:42 -04:00
enum hmcMode
{
STANDBY = 0, QUERY = 1, CONT = 2, ERROR
};
2021-12-19 07:57:35 -05:00
2021-06-07 12:21:42 -04:00
enum hmcOutputMode
{
HEADING = 0, RAWMAGX = 1, RAWMAGY= 2, MAGX = 3, MAGY = 4
};
2013-09-30 11:00:55 -04:00
class hmc6352
{
public:
2021-06-07 12:21:42 -04:00
hmc6352(uint8_t device, TwoWire *wire = &Wire);
2013-09-30 11:00:55 -04:00
2020-11-27 05:16:22 -05:00
#if defined (ESP8266) || defined(ESP32)
2021-06-07 12:21:42 -04:00
bool begin(uint8_t sda, uint8_t scl);
2020-11-27 05:16:22 -05:00
#endif
2021-06-07 12:21:42 -04:00
bool begin();
bool isConnected();
// BASIC CALLS FOR STANDBY MODE
2021-06-07 12:21:42 -04:00
int getHeading(void); // short for askHeading() & readHeading()
int askHeading(void);
int readHeading(void);
int wakeUp(void);
int sleep(void);
2021-06-07 12:21:42 -04:00
// EXPERT CALLS
int factoryReset();
2021-06-07 12:21:42 -04:00
int setOperationalModus(hmcMode mode, uint8_t frequency, bool periodicReset);
int getOperationalModus();
int setOutputModus(uint8_t om);
int getOutputModus();
2021-06-07 12:21:42 -04:00
int callibrationOn();
int callibrationOff();
2021-06-07 12:21:42 -04:00
// to change the start up address.
int setI2CAddress(uint8_t address);
int getI2CAddress();
2013-09-30 11:00:55 -04:00
int writeEEPROM(uint8_t address, uint8_t data);
int readEEPROM(uint8_t address);
int writeRAM(uint8_t address, uint8_t data);
int readRAM(uint8_t address);
2013-09-30 11:00:55 -04:00
2020-11-27 05:16:22 -05:00
// allow power users to set operational mode flags
int saveOpMode(byte OpMode);
2021-06-07 12:21:42 -04:00
// NOT TESTED
int setTimeDelay(uint8_t milliSeconds);
int getTimeDelay();
2021-06-07 12:21:42 -04:00
// nosm = NumberOfSummedMeasurements 1..16
int setMeasurementSumming(uint8_t nosm);
int getMeasurementSumming();
2021-06-07 12:21:42 -04:00
int updateOffsets();
int getSWVersionNumber();
2013-09-30 11:00:55 -04:00
private:
int cmd(uint8_t c);
int readCmd(uint8_t c, uint8_t address);
int writeCmd(uint8_t c, uint8_t address, uint8_t data);
2013-09-30 11:00:55 -04:00
2021-06-07 12:21:42 -04:00
uint8_t _address;
TwoWire* _wire;
2013-09-30 11:00:55 -04:00
};
2021-12-19 07:57:35 -05:00
// -- END OF FILE --