RTC Driver OK
This commit is contained in:
@@ -3,8 +3,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <endian.h>
|
#include <endian.h>
|
||||||
|
|
||||||
#define DEBUGLOG_DEFAULT_LOG_LEVEL_TRACE
|
//#define DEBUGLOG_DEFAULT_LOG_LEVEL_TRACE
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
namespace drivers
|
namespace drivers
|
||||||
@@ -306,7 +305,7 @@ namespace drivers
|
|||||||
*it=highByte(beV);
|
*it=highByte(beV);
|
||||||
*(++it)=lowByte(beV);
|
*(++it)=lowByte(beV);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!write(multiRequest(device, func, reg, num, requestData)))
|
if (!write(multiRequest(device, func, reg, num, requestData)))
|
||||||
{
|
{
|
||||||
LOG_ERROR("Failed send writeMultiInteger command");
|
LOG_ERROR("Failed send writeMultiInteger command");
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "WS_PCF85063.h"
|
#include "PCF85063_Driver.h"
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
namespace drivers
|
namespace drivers
|
||||||
@@ -157,6 +157,12 @@ namespace drivers
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string PCF85063::getTimeStr() {
|
||||||
|
datetime_t dt;
|
||||||
|
readDatetime(dt);
|
||||||
|
return datetime2str(dt);
|
||||||
|
}
|
||||||
|
|
||||||
const std::string PCF85063::datetime2str(datetime_t &datetime)
|
const std::string PCF85063::datetime2str(datetime_t &datetime)
|
||||||
{
|
{
|
||||||
tm dtime;
|
tm dtime;
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ namespace drivers
|
|||||||
I2C &m_i2c;
|
I2C &m_i2c;
|
||||||
uint8_t m_address;
|
uint8_t m_address;
|
||||||
|
|
||||||
|
public:
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint16_t year;
|
uint16_t year;
|
||||||
@@ -129,6 +130,8 @@ namespace drivers
|
|||||||
const bool readAlarm(datetime_t &time);
|
const bool readAlarm(datetime_t &time);
|
||||||
const bool getAlarmFlag(uint8_t &flags);
|
const bool getAlarmFlag(uint8_t &flags);
|
||||||
|
|
||||||
|
const std::string getTimeStr();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string datetime2str(datetime_t &datetime);
|
const std::string datetime2str(datetime_t &datetime);
|
||||||
const uint8_t decToBcd(const int val);
|
const uint8_t decToBcd(const int val);
|
||||||
|
|||||||
25
src/main.cpp
25
src/main.cpp
@@ -5,6 +5,9 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <RS485_Driver.h>
|
#include <RS485_Driver.h>
|
||||||
#include <TCA9554PWR_Driver.h>
|
#include <TCA9554PWR_Driver.h>
|
||||||
|
#include <PCF85063_Driver.h>
|
||||||
|
|
||||||
|
#include <ETH.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
@@ -25,15 +28,27 @@ void loop()
|
|||||||
const uint8_t baseRegister(0x00);
|
const uint8_t baseRegister(0x00);
|
||||||
|
|
||||||
//////////////// DEVICES ////////////////
|
//////////////// DEVICES ////////////////
|
||||||
|
// Declared here to keep devices local to the main loop otherwise the kernel crashes //
|
||||||
auto i2c = drivers::I2C();
|
auto i2c = drivers::I2C();
|
||||||
auto relays = drivers::TCA9554PWR(i2c, TCA9554_ADDRESS);
|
auto relays = drivers::TCA9554PWR(i2c, TCA9554_ADDRESS);
|
||||||
auto bus = drivers::MODBUS(9600, SERIAL_8N1);
|
auto bus = drivers::MODBUS(9600, SERIAL_8N1);
|
||||||
|
auto rtc = drivers::PCF85063(i2c, PCF85063_ADDRESS);
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
///////// MAIN LOOP INSIDE LOOP ////////
|
||||||
|
////////////////////////////////////////
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
LOG_INFO("\n\n\n\n[", k++, "] Loop");
|
LOG_INFO("[", k++, "] Loop");
|
||||||
std::vector<uint16_t> results;
|
std::vector<uint16_t> results;
|
||||||
std::vector<bool> values;
|
std::vector<bool> values;
|
||||||
|
|
||||||
|
drivers::PCF85063::datetime_t dt;
|
||||||
|
rtc.readDatetime(dt);
|
||||||
|
LOG_INFO("Current Datetime", rtc.getTimeStr().c_str());
|
||||||
|
|
||||||
|
|
||||||
if (bus.readHoldingRegisters(tempBoardAddr, baseRegister, 8, results))
|
if (bus.readHoldingRegisters(tempBoardAddr, baseRegister, 8, results))
|
||||||
{
|
{
|
||||||
@@ -43,7 +58,7 @@ void loop()
|
|||||||
}
|
}
|
||||||
results.clear();
|
results.clear();
|
||||||
}
|
}
|
||||||
delay(100);
|
delay(5000);
|
||||||
|
|
||||||
LOG_INFO("\n\n====>Write Status 1");
|
LOG_INFO("\n\n====>Write Status 1");
|
||||||
bus.writeCoils(relayBoardAddr, 0x00, {true, false, true, false, true, false, true, false});
|
bus.writeCoils(relayBoardAddr, 0x00, {true, false, true, false, true, false, true, false});
|
||||||
@@ -55,7 +70,7 @@ void loop()
|
|||||||
bus.writeCoils(relayBoardAddr, 0x00, {false, true, false, true, false, true, false, true});
|
bus.writeCoils(relayBoardAddr, 0x00, {false, true, false, true, false, true, false, true});
|
||||||
bus.readCoils(relayBoardAddr, 0x00, 8, values);
|
bus.readCoils(relayBoardAddr, 0x00, 8, values);
|
||||||
printBool("====>Status 2", values);
|
printBool("====>Status 2", values);
|
||||||
|
|
||||||
delay(5000);
|
delay(5000);
|
||||||
LOG_INFO("\n\n====>Read Inputs");
|
LOG_INFO("\n\n====>Read Inputs");
|
||||||
bus.readInputs(relayBoardAddr, 0x00, 8, values);
|
bus.readInputs(relayBoardAddr, 0x00, 8, values);
|
||||||
@@ -63,4 +78,8 @@ void loop()
|
|||||||
|
|
||||||
delay(5000);
|
delay(5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
///////// MAIN LOOP INSIDE LOOP ////////
|
||||||
|
////////////////////////////////////////
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user