@@ -7,44 +7,47 @@ v0.2.0 - copy from 0.1.9 and remove coments and debug data
77v0.2.1 - add new funcion - enable, disable and remove some variables
88v0.2.2 - rename data array to buffer, and use data array for data per chanel
99v0.2.3 - save data directly to data array
10- v0.2.4 - rename get functions to decode and create new getfunctions and some isFFF functions
10+ v0.2.4 - rename get functions to decode and create new getfunctions and some isFFF functions
1111v0.2.5 - correct some daty types
1212v0.2.6 - set prefix _ for global private objects
1313v0.3.0 - do it like class
1414v0.3.1 - change all to static
1515v0.3.2 - rename class to SensorT25
1616v0.4.0 - save it like library
17+ v0.4.1 - rename BIT0 and 1 to TBIT0 and 1, user IRAM_ATTR for IRQ handler
18+ v0.4.2 - ESP32 is not supporting float in IRQ handler, use int instead
1719*/
1820
1921#include < SensorT25.h>
2022
2123unsigned long SensorT25::_buffer[BUFF_ROW] = {0L ,0L ,0L }; // raw data buffer
2224boolean SensorT25::_valid[SENSCOUNT] = {false ,false ,false }; // valid dta forsensor
2325byte SensorT25::_sid[SENSCOUNT]; // sensor ID
24- float SensorT25::_temperature[SENSCOUNT]; // temperature
26+ // float SensorT25::_temperature[SENSCOUNT]; // temperature
27+ int SensorT25::_itemperature[SENSCOUNT]; // temperature
2528unsigned long SensorT25::_time[SENSCOUNT]; // last set time
2629boolean SensorT25::_start = LOW; // start data reading flag
27- boolean SensorT25::_space = LOW; // space is starting
30+ boolean SensorT25::_space = LOW; // space is starting
2831boolean SensorT25::_bit0 = LOW;
2932boolean SensorT25::_bit1 = LOW;
3033byte SensorT25::_bits = 0 ; // bits counter in data word
3134byte SensorT25::_repeat = 0 ; // counter for repeated reading
3235unsigned long SensorT25::_lastTime = 0 ; // variable for last time point
3336byte SensorT25::_irq_pin; // number of used IRQ PIN
34- // methods
35- void SensorT25::enable (byte irq_pin) // enable data reading - INT0,INT1 name, number 2 or 3 for UNO
36- {
37- _irq_pin = irq_pin;
37+ // methods
38+ void SensorT25::enable (byte irq_pin) // enable data reading - INT0,INT1 name, number 2 or 3 for UNO
39+ {
40+ _irq_pin = irq_pin;
3841 pinMode (irq_pin, INPUT_PULLUP); // input for RF receiver
3942 attachInterrupt (digitalPinToInterrupt (irq_pin), _irqHandler, CHANGE); // IRQ handler for RF receiver
4043}
41-
44+
4245void SensorT25::disable (byte irq_pin) // disable daata reading
4346{
4447 detachInterrupt (digitalPinToInterrupt (irq_pin)); // stop IRQ
4548}
4649
47- // are data valid for channel
50+ // are data valid for channel
4851boolean SensorT25::isValid (byte channel)
4952{
5053 return (isValidChannel (channel) ? _valid[channel] : false );
@@ -62,19 +65,20 @@ void SensorT25::setInValid(byte channel)
6265// get sensor ID for channel
6366byte SensorT25::getSID (byte channel)
6467{
65- return (isValidChannel (channel) ? _sid[channel] : 0 );
68+ return (isValidChannel (channel) ? _sid[channel] : 0 );
6669}
6770
6871// get temperature for channel
6972float SensorT25::getTemperature (byte channel)
7073{
71- return (isValidChannel (channel) ? _temperature[channel] : 0 );
74+ // return (isValidChannel(channel) ? _temperature[channel] : 0);
75+ return (isValidChannel (channel) ? float (_itemperature[channel])/10 : 0 );
7276}
7377
7478// get temperature value age in s
7579long SensorT25::getValueAge (byte channel)
7680{
77- return (isValidChannel (channel) ? (millis () - _time[channel])/1000 : 0 );
81+ return (isValidChannel (channel) ? (millis () - _time[channel])/1000 : 0 );
7882}
7983
8084// channel number validation
@@ -83,7 +87,7 @@ boolean SensorT25::isValidChannel(byte channel)
8387 return ( channel >= 0 && channel < SENSCOUNT);
8488}
8589
86- // return specified bits from sensor word
90+ // return specified bits from sensor word
8791unsigned int SensorT25::_decodeBits (unsigned long buffer, unsigned long mask, byte shift )
8892{
8993 return ((buffer & mask) >> shift);
@@ -102,69 +106,77 @@ byte SensorT25::_decodeChanel(unsigned long buffer)
102106}
103107
104108// decode temperature from data word
105- float SensorT25::_decodeTemp (unsigned long buffer)
109+ // float SensorT25::_decodeTemp(unsigned long buffer)
110+ // {
111+ // int t = _decodeBits(buffer, TEM_MASK, TEM_SHIFT);
112+ // if (t > 2047) {t = t - 4095;}
113+ // return float(t)/10;
114+ // }
115+
116+ // decode temperature from data word
117+ int SensorT25::_idecodeTemp (unsigned long buffer)
106118{
107119 int t = _decodeBits (buffer, TEM_MASK, TEM_SHIFT);
108120 if (t > 2047 ) {t = t - 4095 ;}
109- return float (t)/ 10 ;
121+ return t ;
110122}
111123
112- // IRQ handler for decode bits
124+ // IRQ handler for decode bits ...
113125void SensorT25::_irqHandler ()
114126{
115127 unsigned long currentTime = micros (); // shot time
116128 int duration = currentTime - _lastTime; // calculate duration
117129 _lastTime = currentTime; // memory curent time
118130 boolean state = digitalRead (_irq_pin); // read input status
119- if (!state) // goes from HIGH to LOW
120- {
131+ if (!state) // goes from HIGH to LOW
132+ {
121133 _space = _isImpuls (duration - IMPULSE, ITRESHOLD); // if impuls time is valid
122- }
134+ }
123135 else if (_space) // goes from LOW to HIGH
124- {
136+ {
125137 if (!_start) // start flag is false
126- {
138+ {
127139 _start = _isImpuls (duration - PAUSE, STRESHOLD); // start temperature data it was pause signal
128- }
140+ }
129141 else // start flag is true
130142 {
131- _bit0 = _isImpuls (duration - BIT0 , STRESHOLD); // is it bit 0
132- _bit1 = _isImpuls (duration - BIT1 , STRESHOLD); // is it bit 1
143+ _bit0 = _isImpuls (duration - TBIT0 , STRESHOLD); // is it bit 0
144+ _bit1 = _isImpuls (duration - TBIT1 , STRESHOLD); // is it bit 1
133145 if (_bit0 ^ _bit1) // XOR / only one is true
134146 {
135147 _bit1 && bitSet (_buffer[_repeat],DATA_LONG - _bits - 1 ); // write bit 1
136148 _bit0 && bitClear (_buffer[_repeat],DATA_LONG - _bits - 1 ); // write bit 0
137149 _bits++; // increment bit counter
138- }
139- else // both or nothing bit
150+ }
151+ else // both or nothing bit
140152 {
141153 _resetTWord (); // reset reading
142154 }
143155 if (_bits >= DATA_LONG) // last bit was reading
144156 {
145157 if (_repeat > 0 ) // is it temp sentence hienr then 0
146158 {
147- if (_buffer[_repeat] != _buffer[_repeat-1 ]) // current temp word is differnt than previous
159+ if (_buffer[_repeat] != _buffer[_repeat-1 ]) // current temp word is differnt than previous
148160 {
149161 _resetTWord (); // reset reading
150162 }
151163 }
152164 _repeat++; // increment temp word reading
153165 _newTWord (); // reset counters and flags
154166 }
155- }
167+ }
156168 }
157-
169+
158170 // write valid data to data array
159171 if (_repeat >= BUFF_ROW) // buffer is full
160172 {
161173 byte ch = (_decodeChanel (_buffer[0 ])); // set channel
162174 _valid[ch] = true ; // set data valid
163175 _sid[ch] = (_decodeSID (_buffer[0 ])); // sensor ID // save sensor ID
164- _temperature [ch] = (_decodeTemp (_buffer[0 ])); // save temperature
176+ _itemperature [ch] = (_idecodeTemp (_buffer[0 ])); // save temperature
165177 _time[ch] = millis (); // save data timestamp
166178 _resetTWord (); // reset reading
167- }
179+ }
168180}
169181
170182void SensorT25::_resetTWord () // reset reading
@@ -183,4 +195,4 @@ void SensorT25::_newTWord () // reset temp wo
183195boolean SensorT25::_isImpuls (int duration, byte TRESHOLD) // is it valid impulse
184196{
185197 return (abs (duration) <= TRESHOLD);
186- }
198+ }
0 commit comments