diff --git a/src/modules/sensors/IoTWiegand/IoTWiegand.cpp b/src/modules/sensors/IoTWiegand/IoTWiegand.cpp new file mode 100644 index 00000000..d4cd8a0d --- /dev/null +++ b/src/modules/sensors/IoTWiegand/IoTWiegand.cpp @@ -0,0 +1,78 @@ +#include "Global.h" +#include "classes/IoTItem.h" + +#include + +#define PIN_D0 D5 +#define PIN_D1 D6 + +WiegandNG wg; + +void PrintBinary(WiegandNG &tempwg) { + volatile unsigned char *buffer=tempwg.getRawData(); + unsigned int bufferSize = tempwg.getBufferSize(); + unsigned int countedBits = tempwg.getBitCounted(); + + unsigned int countedBytes = (countedBits/8); + if ((countedBits % 8)>0) countedBytes++; + // unsigned int bitsUsed = countedBytes * 8; + + for (unsigned int i=bufferSize-countedBytes; i< bufferSize;i++) { + unsigned char bufByte=buffer[i]; + for(int x=0; x<8;x++) { + if ( (((bufferSize-i) *8)-x) <= countedBits) { + if((bufByte & 0x80)) { + Serial.print("1"); + } + else { + Serial.print("0"); + } + } + bufByte<<=1; + } + } + Serial.println(); +} + +class IoTWiegand : public IoTItem { + + public: + IoTWiegand(String parameters) : IoTItem(parameters) { + // int pinD0; + // int pinD1; + + // jsonRead(parameters, "pinD0", pinD0); + // jsonRead(parameters, "pinD1", pinD1); + + unsigned int pinD0 = D5; + unsigned int pinD1 = D6; + unsigned int wiegandbits = 48; + unsigned int packetGap = 15; // 25 ms between packet + + // if(!wg.begin(pinD0, pinD1, wiegandbits, packetGap)) { + // Serial.println("Out of memory!"); + // } + + } + + void loop() { + if(wg.available()) { + wg.pause(); // pause Wiegand pin interrupts + Serial.print("Bits="); + Serial.println(wg.getBitCounted()); // display the number of bits counted + Serial.print("RAW Binary="); + PrintBinary(wg); // display raw data in binary form, raw data inclusive of PARITY + wg.clear(); // compulsory to call clear() to enable interrupts for subsequent data + } + } + + ~IoTWiegand(){}; +}; + +void* getAPI_IoTWiegand(String subtype, String param) { + if (subtype == F("IoTWiegand")) { + return new IoTWiegand(param); + } else { + return nullptr; + } +} diff --git a/src/modules/sensors/IoTWiegand/items.json b/src/modules/sensors/IoTWiegand/items.json new file mode 100644 index 00000000..a4961357 --- /dev/null +++ b/src/modules/sensors/IoTWiegand/items.json @@ -0,0 +1,15 @@ +[ + { + "name": "Считыватель Wiegand", + "num": 31, + "type": "Reading", + "subtype": "IoTWiegand", + "id": "wg", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Считыватель", + "int": 0, + "pinD0": 13, + "pinD1": 12 + } +] \ No newline at end of file diff --git a/src/modules/sensors/IoTWiegand/platformio.ini b/src/modules/sensors/IoTWiegand/platformio.ini new file mode 100644 index 00000000..0a4331bd --- /dev/null +++ b/src/modules/sensors/IoTWiegand/platformio.ini @@ -0,0 +1,12 @@ +[env:esp8266_4mb] +lib_deps = + https://github.com/jpliew/Wiegand-NG-Multi-Bit-Wiegand-Library-for-Arduino + +[env:esp32_4mb] +lib_deps = + https://github.com/jpliew/Wiegand-NG-Multi-Bit-Wiegand-Library-for-Arduino + +[iotm] + ;exclude = false + exclude = true +