2020-11-27 05:16:22 -05:00
|
|
|
#pragma once
|
2017-09-13 02:58:18 -04:00
|
|
|
//
|
2013-09-30 11:00:55 -04:00
|
|
|
// FILE: hmc6352.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2020-11-27 05:16:22 -05:00
|
|
|
// VERSION: 0.2.0
|
2013-09-30 11:00:55 -04:00
|
|
|
// PURPOSE: HMC6352 library for Arduino
|
|
|
|
//
|
2020-11-27 05:16:22 -05:00
|
|
|
// HISTORY: see cpp file
|
2013-09-30 11:00:55 -04:00
|
|
|
|
2020-11-27 05:16:22 -05:00
|
|
|
#include "Wire.h"
|
2017-09-13 02:58:18 -04:00
|
|
|
#include "Arduino.h"
|
|
|
|
|
2020-11-27 05:16:22 -05:00
|
|
|
#define HMC6352_LIB_VERSION "0.2.0"
|
2017-09-13 02:58:18 -04:00
|
|
|
|
2020-11-27 05:16:22 -05:00
|
|
|
/* ERROR CODES ALL FUNCTIONS
|
|
|
|
//
|
|
|
|
// * twi_writeTo codes (== endTransmission commands)
|
|
|
|
// 0 .. OK
|
|
|
|
// -1 .. length to long for buffer
|
|
|
|
// -2 .. address send, NACK received
|
|
|
|
// -3 .. data send, NACK received
|
|
|
|
// -4 .. other twi error (lost bus arbitration, bus error, ..)
|
|
|
|
//
|
|
|
|
// * requestFrom
|
|
|
|
// -10 .. not enough values returned
|
|
|
|
//
|
|
|
|
// * function calls
|
|
|
|
// 0 .. OK
|
|
|
|
// -20 .. error param1
|
|
|
|
// -21 .. error param2
|
|
|
|
// -22 .. error param3
|
|
|
|
//
|
|
|
|
*/
|
2013-09-30 11:00:55 -04:00
|
|
|
|
|
|
|
enum hmcMode { STANDBY=0, QUERY=1, CONT=2, ERROR};
|
|
|
|
|
|
|
|
class hmc6352
|
|
|
|
{
|
2017-09-13 02:58:18 -04:00
|
|
|
public:
|
|
|
|
hmc6352(uint8_t device);
|
2013-09-30 11:00:55 -04:00
|
|
|
|
2020-11-27 05:16:22 -05:00
|
|
|
#if defined (ESP8266) || defined(ESP32)
|
|
|
|
void begin(uint8_t sda, uint8_t scl);
|
|
|
|
#endif
|
|
|
|
void begin();
|
|
|
|
|
2017-09-13 02:58:18 -04:00
|
|
|
// BASIC CALLS FOR STANDBY MODE
|
|
|
|
int getHeading(void); // just a merge of ask & read
|
|
|
|
int askHeading(void);
|
|
|
|
int readHeading(void);
|
2013-09-30 11:03:06 -04:00
|
|
|
|
2017-09-13 02:58:18 -04:00
|
|
|
int wakeUp(void);
|
|
|
|
int sleep(void);
|
2013-09-30 11:03:06 -04:00
|
|
|
|
2017-09-13 02:58:18 -04:00
|
|
|
// EXPERT CALLS
|
|
|
|
int factoryReset();
|
2013-09-30 11:03:06 -04:00
|
|
|
|
2017-09-13 02:58:18 -04:00
|
|
|
int setOperationalModus(hmcMode m, uint8_t freq, bool periodicReset);
|
|
|
|
int getOperationalModus();
|
2013-09-30 11:03:06 -04:00
|
|
|
|
2017-09-13 02:58:18 -04:00
|
|
|
int setOutputModus(uint8_t om);
|
|
|
|
int getOutputModus();
|
2013-09-30 11:03:06 -04:00
|
|
|
|
2017-09-13 02:58:18 -04:00
|
|
|
int callibrationOn(void);
|
|
|
|
int callibrationOff(void);
|
2013-09-30 11:03:06 -04:00
|
|
|
|
2017-09-13 02:58:18 -04:00
|
|
|
int setI2CAddress(uint8_t address);
|
|
|
|
int getI2CAddress();
|
2013-09-30 11:00:55 -04:00
|
|
|
|
2017-09-13 02:58:18 -04:00
|
|
|
int writeEEPROM(uint8_t address, uint8_t data);
|
|
|
|
int readEEPROM(uint8_t address);
|
2013-09-30 11:03:06 -04:00
|
|
|
|
2017-09-13 02:58:18 -04:00
|
|
|
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);
|
|
|
|
|
2017-09-13 02:58:18 -04:00
|
|
|
// NOT TESTED / UNKNOWN
|
|
|
|
int setTimeDelay(uint8_t msec);
|
|
|
|
int getTimeDelay();
|
|
|
|
int setMeasurementSumming(uint8_t ms);
|
|
|
|
int getMeasurementSumming();
|
|
|
|
int updateOffsets(void);
|
2013-09-30 11:00:55 -04:00
|
|
|
|
2017-09-13 02:58:18 -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
|
|
|
|
2017-09-13 02:58:18 -04:00
|
|
|
uint8_t _device;
|
2013-09-30 11:00:55 -04:00
|
|
|
};
|
|
|
|
|
2020-11-27 05:16:22 -05:00
|
|
|
// -- END OF FILE --
|