|
72 | 72 |
|
73 | 73 | #ifdef PLUGIN_031
|
74 | 74 | #include "../4_Display.h"
|
| 75 | +#include "../7_Utils.h" |
| 76 | + |
| 77 | +/*********************************************************************************************\ |
| 78 | + * Calculates CRC-8 checksum |
| 79 | + * reference http://lucsmall.com/2012/04/29/weather-station-hacking-part-2/ |
| 80 | + * http://lucsmall.com/2012/04/30/weather-station-hacking-part-3/ |
| 81 | + * https://github.com/lucsmall/WH2-Weather-Sensor-Library-for-Arduino/blob/master/WeatherSensorWH2.cpp |
| 82 | + \*********************************************************************************************/ |
| 83 | +#define Plugin_031_ProtocolAlectoCRC8(addr, len) crc8((addr), (len), 0x31, 0) |
75 | 84 |
|
76 |
| -uint8_t Plugin_031_ProtocolAlectoCRC8(uint8_t *addr, uint8_t len); |
77 | 85 | // unsigned int Plugin_031_ProtocolAlectoRainBase = 0;
|
78 | 86 |
|
79 | 87 | boolean Plugin_031(byte function, const char *string)
|
@@ -188,28 +196,5 @@ boolean Plugin_031(byte function, const char *string)
|
188 | 196 | return true;
|
189 | 197 | }
|
190 | 198 |
|
191 |
| -/*********************************************************************************************\ |
192 |
| - * Calculates CRC-8 checksum |
193 |
| - * reference http://lucsmall.com/2012/04/29/weather-station-hacking-part-2/ |
194 |
| - * http://lucsmall.com/2012/04/30/weather-station-hacking-part-3/ |
195 |
| - * https://github.com/lucsmall/WH2-Weather-Sensor-Library-for-Arduino/blob/master/WeatherSensorWH2.cpp |
196 |
| - \*********************************************************************************************/ |
197 |
| -uint8_t Plugin_031_ProtocolAlectoCRC8(uint8_t *addr, uint8_t len) |
198 |
| -{ |
199 |
| - uint8_t crc = 0; |
200 |
| - // Indicated changes are from reference CRC-8 function in OneWire library |
201 |
| - while (len--) |
202 |
| - { |
203 |
| - uint8_t inbyte = *addr++; |
204 |
| - for (uint8_t i = 8; i; i--) |
205 |
| - { |
206 |
| - uint8_t mix = (crc ^ inbyte) & 0x80; // changed from & 0x01 |
207 |
| - crc <<= 1; // changed from right shift |
208 |
| - if (mix) |
209 |
| - crc ^= 0x31; // changed from 0x8C; |
210 |
| - inbyte <<= 1; // changed from right shift |
211 |
| - } |
212 |
| - } |
213 |
| - return crc; |
214 |
| -} |
| 199 | + |
215 | 200 | #endif // PLUGIN_031
|
0 commit comments