mirror of https://github.com/arendst/Tasmota.git
Merge pull request #6943 from climberhunt/development
extend Honeywell HPMA library for compact devices
This commit is contained in:
commit
ffdc7088d5
|
@ -6,7 +6,7 @@
|
||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <HPMA115S0.h>
|
#include <hpma115S0.h>
|
||||||
#include <SoftwareSerial.h>
|
#include <SoftwareSerial.h>
|
||||||
|
|
||||||
//Create an instance of software serial
|
//Create an instance of software serial
|
||||||
|
|
|
@ -45,7 +45,7 @@ void HPMA115S0::Init() {
|
||||||
* @param size of buffer
|
* @param size of buffer
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void HPMA115S0::SendCmd(unsigned char * cmdBuf, unsigned int cmdSize) {
|
void HPMA115S0::SendCmd(const char * cmdBuf, unsigned int cmdSize) {
|
||||||
//Clear RX
|
//Clear RX
|
||||||
while (_serial.available())
|
while (_serial.available())
|
||||||
_serial.read();
|
_serial.read();
|
||||||
|
@ -114,18 +114,28 @@ int HPMA115S0::ReadCmdResp(unsigned char * dataBuf, unsigned int dataBufSize, un
|
||||||
* @return returns true if valid measurements were read from sensor
|
* @return returns true if valid measurements were read from sensor
|
||||||
*/
|
*/
|
||||||
boolean HPMA115S0::ReadParticleMeasurement(unsigned int * pm2_5, unsigned int * pm10) {
|
boolean HPMA115S0::ReadParticleMeasurement(unsigned int * pm2_5, unsigned int * pm10) {
|
||||||
unsigned char cmdBuf[] = {0x68, 0x01, 0x04, 0x93};
|
const char cmdBuf[] = {0x68, 0x01, 0x04, 0x93};
|
||||||
static unsigned char dataBuf[HPM_READ_PARTICLE_MEASURMENT_LEN - 1];
|
static unsigned char dataBuf[HPM_READ_PARTICLE_MEASURMENT_LEN_C - 1];
|
||||||
|
int len;
|
||||||
|
|
||||||
//Serial.println("PS- Reading Particle Measurements..." );
|
// Serial.println("PS- Reading Particle Measurements..." );
|
||||||
|
|
||||||
//Send command
|
//Send command
|
||||||
SendCmd(cmdBuf, 4);
|
SendCmd(cmdBuf, 4);
|
||||||
|
|
||||||
//Read response
|
//Read response
|
||||||
if (ReadCmdResp(dataBuf, sizeof(dataBuf), READ_PARTICLE_MEASURMENT) == (HPM_READ_PARTICLE_MEASURMENT_LEN - 1)) {
|
len = ReadCmdResp(dataBuf, sizeof(dataBuf), READ_PARTICLE_MEASURMENT);
|
||||||
_pm2_5 = dataBuf[0] * 256 + dataBuf[1];
|
if ((len == (HPM_READ_PARTICLE_MEASURMENT_LEN - 1)) || (len == (HPM_READ_PARTICLE_MEASURMENT_LEN_C - 1))) {
|
||||||
_pm10 = dataBuf[2] * 256 + dataBuf[3];
|
|
||||||
|
if (len == (HPM_READ_PARTICLE_MEASURMENT_LEN - 1)) {
|
||||||
|
// HPMA115S0 Standard devices
|
||||||
|
_pm2_5 = dataBuf[0] * 256 + dataBuf[1];
|
||||||
|
_pm10 = dataBuf[2] * 256 + dataBuf[3];
|
||||||
|
} else {
|
||||||
|
// HPMA115C0 Compact devices
|
||||||
|
_pm2_5 = dataBuf[2] * 256 + dataBuf[3];
|
||||||
|
_pm10 = dataBuf[6] * 256 + dataBuf[7];
|
||||||
|
}
|
||||||
*pm2_5 = _pm2_5;
|
*pm2_5 = _pm2_5;
|
||||||
*pm10 = _pm10;
|
*pm10 = _pm10;
|
||||||
// Serial.println("PS- PM 2.5: " + String(_pm2_5) + " ug/m3" );
|
// Serial.println("PS- PM 2.5: " + String(_pm2_5) + " ug/m3" );
|
||||||
|
@ -140,7 +150,7 @@ boolean HPMA115S0::ReadParticleMeasurement(unsigned int * pm2_5, unsigned int *
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void HPMA115S0::StartParticleMeasurement() {
|
void HPMA115S0::StartParticleMeasurement() {
|
||||||
unsigned char cmd[] = {0x68, 0x01, 0x01, 0x96};
|
const char cmd[] = {0x68, 0x01, 0x01, 0x96};
|
||||||
SendCmd(cmd, 4);
|
SendCmd(cmd, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +159,7 @@ void HPMA115S0::StartParticleMeasurement() {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void HPMA115S0::StopParticleMeasurement() {
|
void HPMA115S0::StopParticleMeasurement() {
|
||||||
unsigned char cmd[] = {0x68, 0x01, 0x02, 0x95};
|
const char cmd[] = {0x68, 0x01, 0x02, 0x95};
|
||||||
SendCmd(cmd, 4);
|
SendCmd(cmd, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +168,7 @@ void HPMA115S0::StopParticleMeasurement() {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void HPMA115S0::EnableAutoSend() {
|
void HPMA115S0::EnableAutoSend() {
|
||||||
unsigned char cmd[] = {0x68, 0x01, 0x40, 0x57};
|
const char cmd[] = {0x68, 0x01, 0x40, 0x57};
|
||||||
SendCmd(cmd, 4);
|
SendCmd(cmd, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +177,7 @@ void HPMA115S0::EnableAutoSend() {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void HPMA115S0::DisableAutoSend() {
|
void HPMA115S0::DisableAutoSend() {
|
||||||
unsigned char cmd[] = {0x68, 0x01, 0x20, 0x77};
|
const char cmd[] = {0x68, 0x01, 0x20, 0x77};
|
||||||
SendCmd(cmd, 4);
|
SendCmd(cmd, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,9 @@
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
#define HPM_CMD_RESP_HEAD 0x40
|
#define HPM_CMD_RESP_HEAD 0x40
|
||||||
#define HPM_MAX_RESP_SIZE 8 // max command response size is 8 bytes
|
#define HPM_MAX_RESP_SIZE 16 // max command response size is 16 bytes
|
||||||
#define HPM_READ_PARTICLE_MEASURMENT_LEN 5
|
#define HPM_READ_PARTICLE_MEASURMENT_LEN 5
|
||||||
|
#define HPM_READ_PARTICLE_MEASURMENT_LEN_C 13
|
||||||
|
|
||||||
enum CMD_TYPE_T {
|
enum CMD_TYPE_T {
|
||||||
READ_PARTICLE_MEASURMENT = 0x04,
|
READ_PARTICLE_MEASURMENT = 0x04,
|
||||||
|
@ -53,8 +54,8 @@ public:
|
||||||
/**
|
/**
|
||||||
* @brief Function that sends a read command to sensor
|
* @brief Function that sends a read command to sensor
|
||||||
* @return returns true if valid measurements were read from sensor
|
* @return returns true if valid measurements were read from sensor
|
||||||
*/boolean ReadParticleMeasurement(unsigned int * pm2_5, unsigned int * pm10)
|
*/
|
||||||
;
|
boolean ReadParticleMeasurement(unsigned int * pm2_5, unsigned int * pm10);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Function that starts sensor measurement
|
* @brief Function that starts sensor measurement
|
||||||
|
@ -108,7 +109,7 @@ private:
|
||||||
* @param size of buffer
|
* @param size of buffer
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void SendCmd(unsigned char * command, unsigned int size);
|
void SendCmd(const char * command, unsigned int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Function that reads command response from sensor
|
* @brief Function that reads command response from sensor
|
||||||
|
|
Loading…
Reference in New Issue