You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DFRobot_AS393DFRobot_AS39355/DFRobot_AS3935_I2C.h

96 lines
2.7 KiB

6 years ago
#ifndef DFRobot_AS3935_I2C_h
#define DFRobot_AS3935_I2C_h
6 years ago
#include "Arduino.h"
#include "stdlib.h"
#include "Wire.h"
6 years ago
6 years ago
// I2C address
#define AS3935_ADD1 0x01 // A0=high, A1=low
#define AS3935_ADD3 0x03 // A0=high, A1=high
#define AS3935_ADD2 0x02 // A0=low, A1=high
6 years ago
//#define ENABLE_DBG
#ifdef ENABLE_DBG
#define DBG(...){Serial.print("[");Serial.print(__FUNCTION__);\
Serial.print("():");Serial.print(__LINE__);\
Serial.print("]");Serial.print(__VA_ARGS__); Serial.println("");}
#else
#define DBG(...)
#endif
6 years ago
class DFRobot_AS3935_I2C
6 years ago
{
public:
6 years ago
DFRobot_AS3935_I2C(uint8_t irqx, uint8_t devAddx);
6 years ago
DFRobot_AS3935_I2C(uint8_t irqx);
uint8_t begin(void);
6 years ago
/*! Set i2c address */
void setI2CAddress(uint8_t devAddx);
/*! Manual calibration */
void manualCal(uint8_t capacitance, uint8_t location, uint8_t disturber);
/*! reset registers to default */
6 years ago
int defInit(void);
6 years ago
void disturberEn(void);
void disturberDis(void);
void setIRQOutputSource(uint8_t irqSelect);
void setTuningCaps(uint8_t capVal);
/*! 0 = unknown src, 1 = lightning detected, 2 = disturber, 3 = Noise level too high */
uint8_t getInterruptSrc(void);
/*! Get rid of non-distance data */
uint8_t getLightningDistKm(void);
/*! Get lightning energy intensity */
uint32_t getStrikeEnergyRaw(void);
uint8_t setMinStrikes(uint8_t minStrk);
void clearStatistics(void);
void setIndoors(void);
void setOutdoors(void);
uint8_t getNoiseFloorLvl(void);
void setNoiseFloorLvl(uint8_t nfSel);
uint8_t getWatchdogThreshold(void);
void setWatchdogThreshold(uint8_t wdth);
uint8_t getSpikeRejection(void);
void setSpikeRejection(uint8_t srej);
void setLcoFdiv(uint8_t fdiv);
/*! View register data */
void printAllRegs(void);
6 years ago
void powerUp(void);
6 years ago
6 years ago
private:
6 years ago
uint8_t irq, devAdd;
uint8_t singRegRead(uint8_t regAdd);//原始I2C数据读取
void singRegWrite(uint8_t regAdd, uint8_t dataMask, uint8_t regData);//原始数据发送
6 years ago
int reset(void);
6 years ago
void powerDown(void);
6 years ago
void calRCO(void);
/**
* @brief Write register value through IIC bus
*
* @param reg Register address 8bits
* @param pBuf Storage cache to write data in
* @param size The length of data to be written
*/
void writeReg(uint8_t reg, void *pBuf, size_t size);
//void writeRegNoStop(uint8_t reg, void *pBuf, size_t size)
/**
* @brief Read register value through IIC bus
*
* @param reg Register address 8bits
* @param pBuf Read data storage cache
* @param size Read the length of data
* @return Return the read length
*/
size_t readReg(uint8_t reg, void *pBuf, size_t size);
6 years ago
};
#endif