pre
This commit is contained in:
parent
63d9bfb524
commit
cf35e07c2f
|
@ -100,7 +100,8 @@ void IRAM_ATTR refreshInputBankB()
|
||||||
inputBufferB = inputBankB.read8();
|
inputBufferB = inputBankB.read8();
|
||||||
}
|
}
|
||||||
|
|
||||||
rtctime_t ESPMega_getTime() {
|
rtctime_t ESPMega_getTime()
|
||||||
|
{
|
||||||
tmElements_t timeElement;
|
tmElements_t timeElement;
|
||||||
RTC.read(timeElement);
|
RTC.read(timeElement);
|
||||||
rtctime_t time;
|
rtctime_t time;
|
||||||
|
@ -109,18 +110,19 @@ rtctime_t ESPMega_getTime() {
|
||||||
time.seconds = timeElement.Second;
|
time.seconds = timeElement.Second;
|
||||||
time.day = timeElement.Day;
|
time.day = timeElement.Day;
|
||||||
time.month = timeElement.Month;
|
time.month = timeElement.Month;
|
||||||
time.year = timeElement.Year+1970;
|
time.year = timeElement.Year + 1970;
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESPMega_setTime(int hours,int minutes, int seconds, int day, int month, int year) {
|
void ESPMega_setTime(int hours, int minutes, int seconds, int day, int month, int year)
|
||||||
|
{
|
||||||
tmElements_t timeElement;
|
tmElements_t timeElement;
|
||||||
timeElement.Hour = hours;
|
timeElement.Hour = hours;
|
||||||
timeElement.Minute = minutes;
|
timeElement.Minute = minutes;
|
||||||
timeElement.Second = seconds;
|
timeElement.Second = seconds;
|
||||||
timeElement.Day = day;
|
timeElement.Day = day;
|
||||||
timeElement.Month = month;
|
timeElement.Month = month;
|
||||||
timeElement.Year = year-1970;
|
timeElement.Year = year - 1970;
|
||||||
RTC.write(timeElement);
|
RTC.write(timeElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,24 +156,23 @@ void ESPMega_dacWrite(int id, int value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* void ESPMega_rtcNTPUpdate()
|
bool ESPMega_updateTimeFromNTP()
|
||||||
{
|
{
|
||||||
ntpTimeClient.update();
|
struct tm timeinfo;
|
||||||
if (ntpTimeClient.updated())
|
if (getLocalTime(&timeinfo))
|
||||||
{
|
{
|
||||||
int day = ntpTimeClient.getDay();
|
rtctime_t rtctime = ESPMega_getTime();
|
||||||
int month = ntpTimeClient.getMonth();
|
if (rtctime.hours != timeinfo.tm_hour || rtctime.minutes != timeinfo.tm_min ||
|
||||||
int year = ntpTimeClient.getYear();
|
rtctime.seconds != timeinfo.tm_sec || rtctime.day != timeinfo.tm_mday ||
|
||||||
int hours = ntpTimeClient.getHours();
|
rtctime.month != timeinfo.tm_mon + 1 || rtctime.year != timeinfo.tm_year + 1900)
|
||||||
int minutes = ntpTimeClient.getMinutes();
|
{
|
||||||
int seconds = ntpTimeClient.getSeconds();
|
ESPMega_setTime(timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec,
|
||||||
ESPMega_RTC.setYear(year);
|
timeinfo.tm_mday, timeinfo.tm_mon + 1, timeinfo.tm_year + 1900);
|
||||||
ESPMega_RTC.setMonth(month);
|
|
||||||
ESPMega_RTC.setDay(day);
|
}
|
||||||
ESPMega_RTC.setHour(hours);
|
return true;
|
||||||
ESPMega_RTC.setMinute(minutes);
|
|
||||||
ESPMega_RTC.setSecond(seconds);
|
|
||||||
}
|
}
|
||||||
} */
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -5,12 +5,13 @@
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <Adafruit_PWMServoDriver.h>
|
#include <Adafruit_PWMServoDriver.h>
|
||||||
#include <PCF8574.h>
|
#include <PCF8574.h>
|
||||||
#ifdef ANALOG_CARD_ENABLE
|
|
||||||
#include <Adafruit_ADS1X15.h>
|
|
||||||
#include <MCP4725.h>
|
|
||||||
#include <I2C_eeprom.h>
|
#include <I2C_eeprom.h>
|
||||||
#include <TimeLib.h>
|
#include <TimeLib.h>
|
||||||
#include <DS1307RTC.h>
|
#include <DS1307RTC.h>
|
||||||
|
#include <time.h>
|
||||||
|
#ifdef ANALOG_CARD_ENABLE
|
||||||
|
#include <Adafruit_ADS1X15.h>
|
||||||
|
#include <MCP4725.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define INPUT_BANK_A_ADDRESS 0x21
|
#define INPUT_BANK_A_ADDRESS 0x21
|
||||||
|
@ -23,12 +24,13 @@
|
||||||
#define DAC1_ADDRESS 0x61
|
#define DAC1_ADDRESS 0x61
|
||||||
#define DAC2_ADDRESS 0x62
|
#define DAC2_ADDRESS 0x62
|
||||||
#define DAC3_ADDRESS 0x63
|
#define DAC3_ADDRESS 0x63
|
||||||
#define EEPROM_ADDRESS 0x70
|
#define EEPROM_ADDRESS 0x5A
|
||||||
|
|
||||||
//#define USE_INTERRUPT
|
//#define USE_INTERRUPT
|
||||||
#define INPUT_BANK_A_INTERRUPT 36
|
#define INPUT_BANK_A_INTERRUPT 36
|
||||||
#define INPUT_BANK_B_INTERRUPT 39
|
#define INPUT_BANK_B_INTERRUPT 39
|
||||||
extern I2C_eeprom ESPMega_EEPROM;
|
extern I2C_eeprom ESPMega_EEPROM;
|
||||||
|
#define ESPMega_configNTP configTime
|
||||||
struct rtctime_t {
|
struct rtctime_t {
|
||||||
uint8_t hours;
|
uint8_t hours;
|
||||||
uint8_t minutes;
|
uint8_t minutes;
|
||||||
|
@ -99,6 +101,14 @@ rtctime_t ESPMega_getTime();
|
||||||
*/
|
*/
|
||||||
void ESPMega_setTime(int hours,int minutes, int seconds, int day, int month, int year);
|
void ESPMega_setTime(int hours,int minutes, int seconds, int day, int month, int year);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the onboard RTC's time
|
||||||
|
* by using time from the NTP server
|
||||||
|
* configured with ESPMega_configNTP();
|
||||||
|
* @return true when updated successfully.
|
||||||
|
*/
|
||||||
|
bool ESPMega_updateTimeFromNTP();
|
||||||
|
|
||||||
#ifdef ANALOG_CARD_ENABLE
|
#ifdef ANALOG_CARD_ENABLE
|
||||||
/**
|
/**
|
||||||
* Read one of the ESPMega Analog Card's Analog Input pins (A0-A7)
|
* Read one of the ESPMega Analog Card's Analog Input pins (A0-A7)
|
||||||
|
|
|
@ -22,5 +22,5 @@ lib_deps = adafruit/Adafruit PWM Servo Driver Library@^2.4.1
|
||||||
robtillaart/MCP4725@^0.3.7
|
robtillaart/MCP4725@^0.3.7
|
||||||
robtillaart/I2C_EEPROM@^1.7.3
|
robtillaart/I2C_EEPROM@^1.7.3
|
||||||
paulstoffregen/Time@^1.6.1
|
paulstoffregen/Time@^1.6.1
|
||||||
paulstoffregen/DS1307RTC
|
paulstoffregen/DS1307RTC@0.0.0-alpha+sha.c2590c0033
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
|
@ -33,8 +33,9 @@
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
Wire.setClock(50000);
|
||||||
Wire.begin(14,33);
|
Wire.begin(14,33);
|
||||||
|
|
||||||
Serial.begin(115200); // Leonardo: wait for serial monitor
|
Serial.begin(115200); // Leonardo: wait for serial monitor
|
||||||
Serial.println("\nI2C Scanner");
|
Serial.println("\nI2C Scanner");
|
||||||
}
|
}
|
|
@ -1,12 +0,0 @@
|
||||||
#include <ESPMegaPRO.h>
|
|
||||||
void setup() {
|
|
||||||
ESPMega_begin();
|
|
||||||
Serial.begin(115200);
|
|
||||||
ESPMega_setTime(16,35,0,16,9,2023);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
delay(1000);
|
|
||||||
rtctime_t tm = ESPMega_getTime();
|
|
||||||
Serial.printf("%02d:%02d:%02d %02d/%02d/%04d\n", tm.hours,tm.minutes,tm.seconds,tm.day,tm.month,tm.year);
|
|
||||||
}
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
#include <ESPMegaPRO.h>
|
||||||
|
#include <ETH.h>
|
||||||
|
|
||||||
|
uint8_t utc_offset = 7;
|
||||||
|
|
||||||
|
IPAddress IP(192, 168, 0, 241);
|
||||||
|
IPAddress SUBNET(255, 255, 255, 0);
|
||||||
|
IPAddress GATEWAY(192, 168, 0, 1);
|
||||||
|
IPAddress DNS(10, 192, 1, 1);
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
ESPMega_begin();
|
||||||
|
Serial.begin(115200);
|
||||||
|
ETH.begin();
|
||||||
|
ETH.config(IP, GATEWAY, SUBNET, DNS, DNS);
|
||||||
|
delay(5000);
|
||||||
|
char ntp[19];
|
||||||
|
DNS.toString().toCharArray(ntp, 19);
|
||||||
|
ESPMega_configNTP(utc_offset * 3600, 0, ntp);
|
||||||
|
ESPMega_updateTimeFromNTP();
|
||||||
|
//ESPMega_setTime(0,10,52,9,11,2008);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
rtctime_t time = ESPMega_getTime();
|
||||||
|
Serial.printf("RTC: %02d:%02d:%02d %02d/%02d/%04d\n", time.hours, time.minutes, time.seconds, time.day, time.month, time.year);
|
||||||
|
delay(1000);
|
||||||
|
}
|
Loading…
Reference in New Issue