+ 0.1.03 Cozir

+ added SetOperatingMode()
This commit is contained in:
rob tillaart 2014-11-16 16:04:43 +01:00
parent 9afc94a7e0
commit 3ef3907e67
2 changed files with 57 additions and 43 deletions

View File

@ -1,8 +1,9 @@
//
// FILE: Cozir.cpp
// AUTHOR: DirtGambit & Rob Tillaart
// VERSION: 0.1.02
// VERSION: 0.1.03
// PURPOSE: library for COZIR range of sensors for Arduino
// Polling Mode
// URL:
//
// READ DATASHEET BEFORE USE OF THIS LIB !
@ -22,6 +23,7 @@
COZIR::COZIR(NewSoftSerial& nss) : CZR_Serial(nss)
#endif
{
nss.begin(9600);
// overide default streaming (takes to much perf
SetOperatingMode(CZR_POLLING);
// delay for initialization
@ -42,8 +44,6 @@ void COZIR::SetOperatingMode(uint8_t mode)
Command(buffer);
}
////////////////////////////////////////////////////////////
//
// POLLING MODE
@ -61,7 +61,8 @@ float COZIR::Fahrenheit()
float COZIR::Celsius()
{
uint16_t rv = Request("T");
return 0.1 * rv;
float f = 0.1 * (rv - 1000.0);
return f;
}
float COZIR::Humidity()
@ -147,8 +148,6 @@ uint8_t COZIR::GetDigiFilter()
return Request("a");
}
////////////////////////////////////////////////////////////
//
// STREAMING MODE
@ -175,7 +174,6 @@ void COZIR::GetRecentFields()
Command("Q");
}
////////////////////////////////////////////////////////////
//
// EEPROM - USE WITH CARE
@ -198,8 +196,6 @@ uint8_t COZIR::GetEEPROM(uint8_t address)
return Request(buffer);
}
////////////////////////////////////////////////////////////
//
// COMMAND MODE
@ -219,25 +215,39 @@ void COZIR::GetConfiguration()
/////////////////////////////////////////////////////////
// PRIVATE
void COZIR::Command(char* s)
void COZIR::Command(const char* s)
{
CZR_Serial.print(s);
CZR_Serial.print("\r\n");
}
uint16_t COZIR::Request(char* s)
uint16_t COZIR::Request(const char* s)
{
Command(s);
// empty buffer
buffer[0] = '\0';
// read answer; there may be a 100ms delay!
// TODO: PROPER TIMEOUT CODE.
delay(100);
delay(200);
int idx = 0;
while(CZR_Serial.available())
{
buffer[idx++] = CZR_Serial.read();
}
buffer[idx] = '\0';
return atoi(&buffer[1]);
uint16_t rv = 0;
switch(buffer[0])
{
case 'T' :
rv = atoi(&buffer[5]);
if (buffer[4] == 1) rv += 1000;
// negative values are mapped above 1000..1250 => capture this in Celsius()
break;
default :
rv = atoi(&buffer[2]);
break;
}
return rv;
}
// -- END OF FILE --

View File

@ -1,8 +1,9 @@
//
// FILE: Cozir.h
// AUTHOR: DirtGambit & Rob Tillaart
// VERSION: 0.1.02
// VERSION: see COZIR_LIB_VERSION
// PURPOSE: library for COZIR range of sensors for Arduino
// Polling Mode
// URL:
//
// READ DATASHEET BEFORE USE OF THIS LIB !
@ -21,7 +22,7 @@
#include "NewSoftSerial.h"
#endif
#define COZIR_LIB_VERSION 0.1.02
#define COZIR_LIB_VERSION "0.1.03"
// OUTPUTFIELDS
// See datasheet for details.
@ -44,7 +45,7 @@
// easy default setting for streaming
#define CZR_HTC (CZR_HUMIDITY | CZR_RAWTEMP | CZR_RAWCO2)
// not in datasheet for debug only
#define CZR_ALL 0x3FFF
#define CZR_ALL 0x3FFE
// OPERATING MODES
#define CZR_COMMAND 0x00
@ -60,8 +61,6 @@ class COZIR
COZIR(NewSoftSerial&);
#endif
void SetOperatingMode(uint8_t mode);
float Celsius();
float Fahrenheit();
float Humidity();
@ -94,9 +93,14 @@ class COZIR
#else
NewSoftSerial& CZR_Serial;
#endif
void SetOperatingMode(uint8_t mode);
void Command(const char* );
uint16_t Request(const char* );
char buffer[20];
void Command(char* );
uint16_t Request(char* );
};
#endif
// -- END OF FILE --