-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathSensor.h
59 lines (55 loc) · 1.55 KB
/
Sensor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Copyright (c) 2013 by Jerry Sy aka d0ughb0y
* mail-to: [email protected]
* Commercial use of this software without
* permission is absolutely prohibited.
*/
#ifndef _Sensor_h
#define _Sensor_h
#include "Arduino.h"
class Sensor {
public:
enum SensorType {_ph,_orp,_cond};
enum SensorAddrType {_serial, _i2c};
Sensor(const char* name, SensorType type, SensorAddrType addr, boolean isEZO);
virtual boolean init();
virtual void update();
virtual void update(uint16_t rawtemp);
virtual boolean getresponse(){return false;};
virtual float getVal();
virtual void calibrate(char* calstr);
virtual void reset();
virtual boolean isInitialized();
virtual long getEC();
virtual char* getName();
protected:
boolean _initialized;
boolean _isEZO;
boolean _ready;
long _ec;
char _name[8];
SensorType _type;
SensorAddrType _addrType;
char _scratch[15];//store serial reading here
float _value; //last reading value
uint16_t _temp; //temp used for temp compensation
uint8_t _retrycount;
virtual void send(const char* command) {};
};
class SensorSerial:public Sensor {
public:
SensorSerial(const char* name, SensorType type, HardwareSerial* saddr, boolean isEZO);
protected:
HardwareSerial* _saddr;
boolean getresponse();
void send(const char* command);
};
class SensorI2C:public Sensor {
public:
SensorI2C(const char* name, SensorType type, uint8_t i2caddr);
protected:
uint8_t _i2caddr;
boolean getresponse();
void send(const char* command);
};
#endif