WIP
попытка дебажить PPS/SQW. работа на SWSerial (8,9) вывод в консоль Serial и на LCD
This commit is contained in:
@@ -9,12 +9,13 @@
|
||||
|
||||
#include <Arduino.h> // needed for Nano Every
|
||||
#include "GPS_RTC_Clock.h"
|
||||
#include "LED_96x8_matrix.h"
|
||||
//#include "LED_96x8_matrix.h"
|
||||
#include <DMD2.h>
|
||||
#include <LiquidCrystal_I2C.h>
|
||||
#include "Font_Chrono1.h"
|
||||
|
||||
#define pin_RTC_SQW 3;
|
||||
#define pin_RTC_SQW 3
|
||||
#define DEBUG_PORT Serial
|
||||
|
||||
SoftDMD dmd(2, 1);
|
||||
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
||||
@@ -23,42 +24,12 @@ char TempBuf[5] = "99.9"; // demo value
|
||||
char HumiBuf[3] = "99"; // demo value
|
||||
|
||||
unsigned long TMR_FPS;
|
||||
long FPS;
|
||||
|
||||
bool LCD_Simple_clock;
|
||||
bool GPS_PPS_LCD, RTC_SQW_LCD;
|
||||
volatile bool fGPS_PPS, fRTC_SQW;
|
||||
|
||||
void RTCtoLCD(bool ClockType = LCD_Simple_clock) {
|
||||
if (!NewSec && !NewMin && !NewHour) return;
|
||||
char Clock[9];
|
||||
char segment[3];
|
||||
char message[50];
|
||||
|
||||
if (ClockType) {
|
||||
snprintf(Clock, sizeof(Clock), "%.2u:%.2u:%.2u", hour(Loc_t), minute(Loc_t), second(Loc_t));
|
||||
lcd.setCursor(0,0);
|
||||
lcd.print(Clock);
|
||||
}
|
||||
else if (NewSec) {
|
||||
snprintf(segment, sizeof(segment),"%.2u", second(Loc_t));
|
||||
lcd.setCursor(6, 0);
|
||||
lcd.print(segment);
|
||||
}
|
||||
|
||||
if (NewMin) {
|
||||
snprintf(segment, sizeof(segment),"%.2u", minute(Loc_t));
|
||||
lcd.setCursor(3, 0);
|
||||
lcd.print(segment);
|
||||
snprintf(segment, sizeof(segment),"%.2u", hour(Loc_t));
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(segment);
|
||||
}
|
||||
//Serial.print("DEBUG[RTCtoLCD] millis(): "); Serial.println(micros());
|
||||
// long drift = tmr_PPS - tmr_SQW;
|
||||
//Serial.println("DEBUG[RTCtoLCD] Difference PPS - SQW: " + String(drift) + "[" + String(tmr_PPS) + "]" + "[" + String(tmr_SQW) + "]");
|
||||
// lcd.setCursor(15, 1);
|
||||
// lcd.print((micros() - tmr_PPS < 2000000) ? "P" : "p"); // Выводим "P" или "p" на 16 позиции в зависимости от условия
|
||||
// snprintf(message, sizeof(message), "micros: %d, tmr_PPS: %d", millis(), tmr_PPS);
|
||||
// Serial.println(message);
|
||||
}
|
||||
|
||||
void setup() { // the setup function runs once when you press reset or power the board
|
||||
// LCD
|
||||
@@ -68,9 +39,9 @@ void setup() { // the setup function runs once when you
|
||||
lcd.setCursor(0,0);
|
||||
lcd.print("DEBUG[setup()]");
|
||||
delay(500);
|
||||
Serial.begin(19200); // = 9600, must be same as GPS for debug
|
||||
Serial.println(); // flush serial
|
||||
Serial.println("-Arduino Reboot-"); // debug
|
||||
//Serial.begin(19200); // = 9600, must be same as GPS for debug
|
||||
//Serial.println(); // flush serial
|
||||
//Serial.println("-Arduino Reboot-"); // debug
|
||||
|
||||
GPS_RTC_Clock_setup(); // first in setup
|
||||
//Matrix_setup(); // LED display
|
||||
@@ -90,94 +61,60 @@ void loop() { // the loop function runs over and over again forever
|
||||
// }
|
||||
|
||||
GPS_RTC_Clock_loop(); // first in loop
|
||||
|
||||
RTCtoLCD();
|
||||
PrintSec();
|
||||
PrintHour();
|
||||
chkFPS();
|
||||
}
|
||||
|
||||
/////////////////////
|
||||
void RTCtoLCD() {
|
||||
if (GPS_sec) {
|
||||
DEBUG_PORT.println("DEBUG[RTCtoLCD] GPS_sec");
|
||||
GPS_PPS_LCD = !GPS_PPS_LCD;
|
||||
lcd.setCursor(2, 0);
|
||||
lcd.print((GPS_PPS_LCD) ? " " : ":");
|
||||
}
|
||||
if (RTC_sec) {
|
||||
DEBUG_PORT.println("DEBUG[RTCtoLCD] RTC_sec");
|
||||
RTC_SQW_LCD = !RTC_SQW_LCD;
|
||||
lcd.setCursor(5, 0);
|
||||
lcd.print((RTC_SQW_LCD) ? " " : ":");
|
||||
}
|
||||
//if (!GPS_sec and !RTC_sec) return;
|
||||
if (!NewSec && !NewMin && !NewHour) return;
|
||||
char Clock[9];
|
||||
char segment[3];
|
||||
char message[50];
|
||||
|
||||
if (NewSec) {
|
||||
DEBUG_PORT.println("DEBUG[RTCtoLCD] newSec");
|
||||
DEBUG_PORT.println("DEBUG[RTCtoLCD] RTCMillis: " + String(RTCMillis));
|
||||
DEBUG_PORT.println("DEBUG[RTCtoLCD] RTC_sec: " + String(RTC_sec));
|
||||
DEBUG_PORT.println("DEBUG[RTCtoLCD] millis: " + String(millis()));
|
||||
snprintf(segment, sizeof(segment),"%.2u", second(Loc_t));
|
||||
lcd.setCursor(6, 0);
|
||||
lcd.print(segment);
|
||||
}
|
||||
|
||||
if (NewMin) {
|
||||
snprintf(segment, sizeof(segment),"%.2u", minute(Loc_t));
|
||||
lcd.setCursor(3, 0);
|
||||
lcd.print(segment);
|
||||
snprintf(segment, sizeof(segment),"%.2u", hour(Loc_t));
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(segment);
|
||||
}
|
||||
}
|
||||
|
||||
void chkFPS() {
|
||||
int FPS;
|
||||
if (millis() - TMR_FPS > 1000) {
|
||||
Serial.println(TMR_FPS);
|
||||
Serial.println(millis());
|
||||
TMR_FPS = millis();
|
||||
Serial.print("DEBUG[chkFPS] "); Serial.println(FPS);
|
||||
if (micros() - TMR_FPS > 1000000) {
|
||||
DEBUG_PORT.println("DEBUG[chkFPS] FPS: " + String(FPS));
|
||||
//DEBUG_PORT.println("DEBUG[chkFPS] TMR_FPS: " + String(TMR_FPS));
|
||||
TMR_FPS = micros();
|
||||
FPS = 0;
|
||||
return;
|
||||
}
|
||||
FPS++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void PrintSec() { // print time if new second
|
||||
if (NewSec) { //
|
||||
NewSec = false; // remove flag, do only once every sec
|
||||
char startmarker = '<';
|
||||
char endmarker = '>';
|
||||
//Serial.print(startmarker); // for remote display via RS485
|
||||
//Serial.print(Loc_t); // for remote display via RS485
|
||||
//Serial.println(endmarker); // for remote display via RS485
|
||||
|
||||
char TimeBuf[9]; // time string buffer, max n-1 char
|
||||
snprintf(TimeBuf, sizeof(TimeBuf), "%.2u:%.2u:%.2u", // https://cplusplus.com/reference/cstdio/printf/
|
||||
hour(Loc_t), minute(Loc_t), second(Loc_t)); // time 24h format
|
||||
//Serial.print("Time: "); // debug
|
||||
//Serial.println(TimeBuf); // debug
|
||||
//Print_time_zone(TimeBuf); // print to LED Matrix
|
||||
PrintMin();
|
||||
}
|
||||
}
|
||||
|
||||
void PrintMin() {
|
||||
char TextBuf[12]; // date string buffer, max n-1 char
|
||||
if (!DIP_Scroll()) { // print date only or 'scrolling' text
|
||||
snprintf(TextBuf, sizeof(TextBuf), "%s %.2u %s",
|
||||
dayShortStrLoc(weekday(Loc_t)), day(Loc_t), monthShortStrLoc(month(Loc_t))); // weekday, day, month
|
||||
} else { // print 'scrolling'
|
||||
/*** HowTo ******************************************************************
|
||||
print different info every few seconds, because of limited display space
|
||||
define the amount of different text lines, must be at least 1
|
||||
define the amount of seconds each textline is displayed, must be at least 1
|
||||
define each text line, this may be duplicates of other text lines
|
||||
*****************************************************************************/
|
||||
byte text_lines = 3; // amount of different text lines printed
|
||||
byte text_timer = 5; // amount of seconds to next text
|
||||
byte text_counter(((Loc_t / text_timer) % text_lines) + 1); // range = 1..n
|
||||
if (text_counter == 1) {
|
||||
snprintf(TextBuf, sizeof(TextBuf), "%.2u%s%u",
|
||||
day(Loc_t), monthShortStrLoc(month(Loc_t)), year(Loc_t)); // day, month, year
|
||||
} else if (text_counter == 2) {
|
||||
snprintf(TextBuf, sizeof(TextBuf), "%s W%.2u",
|
||||
dayShortStrLoc(weekday(Loc_t)), ISOWeekNumber(Loc_t)); // weekday, week
|
||||
} else if (text_counter == 3) {
|
||||
snprintf(TextBuf, sizeof(TextBuf), "%s*C %s%%", TempBuf, HumiBuf); // * = ° degrees char in fontClock
|
||||
} else {
|
||||
snprintf(TextBuf, sizeof(TextBuf), " Err ");
|
||||
}
|
||||
}
|
||||
//Print_date_zone(TextBuf); // print to LED Matrix
|
||||
|
||||
if (NewMin) { // print date if new minute
|
||||
NewMin = false; // remove flag, do only once every min
|
||||
char DateBuf[21]; // date string buffer, max n-1 char
|
||||
// long date version
|
||||
snprintf(DateBuf, sizeof(DateBuf), "%s %.2u-%s-%u W%.2u",
|
||||
dayShortStrLoc(weekday(Loc_t)), day(Loc_t), monthShortStrLoc(month(Loc_t)), year(Loc_t), ISOWeekNumber(Loc_t));
|
||||
//Serial.print("Date long: "); // debug
|
||||
//Serial.println(DateBuf); // debug
|
||||
}
|
||||
}
|
||||
|
||||
void PrintHour() { // do if new hour
|
||||
if (NewHour) { //
|
||||
NewHour = false; // remove flag, do only once every hour
|
||||
//Serial.println("bring out the Cuckoo ;-)"); // debug
|
||||
}
|
||||
}
|
||||
|
||||
//End
|
||||
|
||||
Reference in New Issue
Block a user