GY-63_MS5611/libraries/DS2401/DS2401.h

74 lines
1.2 KiB
C
Raw Normal View History

2023-12-31 11:24:35 -05:00
#pragma once
//
// FILE: DS2401.h
// AUTHOR: Rob Tillaart
// PURPOSE: Library for the DS2401 1-wire unique identification chip.
2024-01-01 11:09:38 -05:00
// VERSION: 0.1.1
2023-12-31 11:24:35 -05:00
// URL: https://github.com/RobTillaart/DS2401
#include "Arduino.h"
#include "OneWire.h"
2024-01-01 11:09:38 -05:00
#define DS2401_LIB_VERSION (F("0.1.1"))
2023-12-31 11:24:35 -05:00
class DS2401
{
public:
explicit DS2401(OneWire * ow)
{
_oneWire = ow;
}
bool begin()
{
// reset address
for (int i = 0; i < 8; i++)
{
_address[i] = 0x00;
}
_oneWire->reset();
_oneWire->reset_search();
_oneWire->search(_address);
// ds2401 has an family ID of 0x01 but this way
// all one-wire devices can be used as UID.
return (_address[0] != 0x00) && (_oneWire->crc8(_address, 7) == _address[7]);
}
2024-01-01 11:09:38 -05:00
2023-12-31 11:24:35 -05:00
void getUID(uint8_t * buffer)
{
memcpy(buffer, _address, 8);
}
2024-01-01 11:09:38 -05:00
2023-12-31 11:24:35 -05:00
bool compareUID(uint8_t * buffer)
{
return memcmp(buffer, _address, 8);
}
2024-01-01 11:09:38 -05:00
void getUID6(uint8_t * buffer)
{
memcpy(buffer, &_address[1], 6);
}
bool compareUID6(uint8_t * buffer)
{
return memcmp(buffer, &_address[1], 6);
}
2023-12-31 11:24:35 -05:00
private:
OneWire * _oneWire;
uint8_t _address[8];
};
// -- END OF FILE --