Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devel #3

Merged
merged 5 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# These are supported funding model platforms

liberapay: hpsaturn
github: hpsaturn
patreon: hpsaturn


21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

## Overview


## Details


## Log output

```cpp


```
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

## Summary
13 changes: 13 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Description

*Replace this paragraph with a description of what this PR is doing. If you're modifying existing behavior, describe the existing behavior, how this PR is changing it, and what motivated the change. If you're changing visual properties, consider including before/after screenshots (and runnable code snippets to reproduce them).*

## Related Issues

*Replace this paragraph with a list of issues related to this PR from our [issue database]. Indicate, which of these issues are resolved or fixed by this PR. There should be at least one issue listed here.*

## Tests

I added the following tests:

*Replace this with a list of the tests that you added as part of this PR.
35 changes: 35 additions & 0 deletions .github/workflows/platformio.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PlatformIO

on:
push:
branches:
- master
paths-ignore:
- '**/README.md'

pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix:
python-version: [3.7]
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U platformio
pio upgrade
pio pkg update
- name: Build test
run: |
pio run
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.pio
.swp
.vscode
releases
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
[![PlatformIO](https://github.com/hpsaturn/m5stickc-dcf77-hat/workflows/PlatformIO/badge.svg)](https://github.com/hpsaturn/m5stickc-dcf77-hat/actions/)

# M5StickC DCF77 HAT

Basic hat implementation of a DCF77 receiver for M5StickC-Plus or compatible ESP32 devices. This firmware uses a improvement of Arduino-DCF77 library, it is using events callback to improve the GUI and signal representation.

<table>
<tr>
<td>
Don't forget to star ⭐ this repository
</td>
</tr>
</table>

## Device

The current firmware was tested on 77.5KHZ single frequency device. It is the 4 pins version and it was bought here in [Aliexpress](https://www.aliexpress.com/item/1005005254051736.html).
Expand Down
10 changes: 3 additions & 7 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@
version = 0.1.2

[env:esp32dev]
platform = espressif32
platform = espressif32 @ 4.4.0
board = esp32dev
framework = arduino
upload_speed = 1500000
monitor_speed = 115200
monitor_filters =
esp32_exception_decoder
build_flags =
-D CORE_DEBUG_LEVEL=0
; -D VERBOSE_DEBUG=1
-D CORE_DEBUG_LEVEL=0
lib_deps =
https://github.com/hpsaturn/M5StickC-Plus.git
https://github.com/hpsaturn/Arduino-DCF77.git
adafruit/RTClib@^2.1.1
; Time@1.6.1
; Timezone@1.2.4
https://github.com/hpsaturn/Arduino-DCF77.git
165 changes: 124 additions & 41 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,66 +1,89 @@
#include <Arduino.h>
#include <DCF77.h>
#include <RTClib.h>

#include "gui.h"

#define DCF77_PON_PIN 0 // DCF77 operation pin
#define DCF_PIN 26 // Connection pin to DCF 77 device
#define DCF_INTERRUPT 26 // Interrupt number associated with pin
#define DCF77_PON_PIN 0 // DCF77 operation pin
#define DCF_PIN 26 // Connection pin to DCF 77 device
#define DCF_INTERRUPT 26 // Interrupt number associated with pin

#define M5STICKCPLUS_LED GPIO_NUM_10

DCF77 DCF = DCF77(DCF_PIN, DCF_INTERRUPT, true);

#define BRIGHT_SIZE 5
int backlight[BRIGHT_SIZE] = {5, 15, 30, 50, 70};
int brightness = 1; // MAX brightness is BRIGHT_SIZE
int brightness = 1; // MAX brightness is BRIGHT_SIZE

int signalpos = SIGNMARG; // signal bar position
int bandposy = SIGNPOSY; // signals band position

class mDCF77EventsCallback : public DCF77EventsCallback {
volatile unsigned char mySignal = 0;
volatile uint64_t myTimerInterval = 0;

typedef enum {
BUFFER_MSG_NONE,
BUFFER_MSG_EOM,
BUFFER_MSG_BF,
} buffer_msg_t;

volatile buffer_msg_t myOnBufferMsg = BUFFER_MSG_NONE;

typedef enum {
TIME_UPDATE_MSG_NONE,
TIME_UPDATE_MSG_CLOSE_TO_INTERNAL_CLOCK,
TIME_UPDATE_MSG_TIME_LAG_CONSISTENT,
TIME_UPDATE_MSG_TIME_LAG_INCONSISTENT,
} time_update_t;

volatile time_update_t myOnTimeUpdateMsg = TIME_UPDATE_MSG_NONE;

typedef enum {
PARITY_ERROR_NONE,
PARITY_ERROR_ERR,
} parity_error_t;

volatile parity_error_t myOnParityError = PARITY_ERROR_NONE;

uint64_t millis64() {
return (esp_timer_get_time() / 1000ULL);
}

class mDCF77EventsCallback : public DCF77EventsCallback {
void onSignal(unsigned char signal) {
Serial.print(signal);
mySignal = signal;
digitalWrite(M5STICKCPLUS_LED, LOW);
if (signal == 0)
M5.Lcd.fillRect(signalpos, bandposy, 2, SIGNHIGH, TFT_DARKGREY);
myTimerInterval = millis64() + 100;
else
M5.Lcd.fillRect(signalpos, bandposy, 2, SIGNHIGH, TFT_GREEN);
signalpos = signalpos + 2;
myTimerInterval = millis64() + 200;
};

void onBufferMsg(const char* msg) {
Serial.println(msg);
signalpos = SIGNMARG;
M5.Lcd.setTextSize(2);
if (String(msg) == "EoM") {
printBuffer(msg, TFT_RED);
printParity("Ukn", TFT_CYAN);
printStatus("Decoding..");
bandposy = SIGNPOSY;
} else if (String(msg) == "BF") {
printBuffer(msg,TFT_WHITE);
printParity("Ok", TFT_WHITE);
bandposy = bandposy + SIGNHIGH + 3;
if (bandposy >= (SIGNPOSY + (SIGNHIGH + 3) * MAXBANDS)) {
bandposy = SIGNPOSY;
}
}
M5.Lcd.fillRect(SIGNMARG, bandposy, 121, SIGNHIGH, BLACK);
if (String(msg) == "EoM")
myOnBufferMsg = BUFFER_MSG_EOM;
else if (String(msg) == "BF")
myOnBufferMsg = BUFFER_MSG_BF;
};

void onTimeUpdateMsg(const char* msg){
printStatus(msg);
void onTimeUpdateMsg(const char* msg) {
if (String(msg) == "Close to internal clock")
myOnTimeUpdateMsg = TIME_UPDATE_MSG_CLOSE_TO_INTERNAL_CLOCK;
else if (String(msg) == "Time lag consistent")
myOnTimeUpdateMsg = TIME_UPDATE_MSG_TIME_LAG_CONSISTENT;
else if (String(msg) == "Time lag inconsistent")
myOnTimeUpdateMsg = TIME_UPDATE_MSG_TIME_LAG_INCONSISTENT;
};

void onParityError() {
updateField(TFT_WIDTH - 60, INFOPOSY+DATEHIGH+7, 60, DATEHIGH, TFT_CYAN);
M5.Lcd.printf("P:Err");
myOnParityError = PARITY_ERROR_ERR;
};
};

void dcfLoop() {
static uint_fast64_t tts = 0; // timestamp for GUI refresh
if (millis() - tts > 1000) {
tts = millis();
if (millis64() - tts > 1000) {
tts = millis64();
time_t DCFtime = DCF.getTime(); // Check if new DCF77 time is available
if (DCFtime != 0) {
Serial.printf("\rTime is updated: ");
Expand All @@ -73,18 +96,80 @@ void dcfLoop() {
}
}

void cbLoop() {
if ((myTimerInterval > 0) && (millis64() > myTimerInterval)) {
myTimerInterval = 0;
digitalWrite(M5STICKCPLUS_LED, HIGH);

if (mySignal == 0)
M5.Lcd.fillRect(signalpos, bandposy, 2, SIGNHIGH, TFT_DARKGREY);
else
M5.Lcd.fillRect(signalpos, bandposy, 2, SIGNHIGH, TFT_GREEN);
signalpos = signalpos + 2;
}

if (myOnBufferMsg != BUFFER_MSG_NONE) {
signalpos = SIGNMARG;
M5.Lcd.setTextSize(2);
switch (myOnBufferMsg) {
case BUFFER_MSG_EOM:
printBuffer("EoM", TFT_RED);
printParity("Ukn", TFT_CYAN);
printStatus("Decoding..");
bandposy = SIGNPOSY;
break;
case BUFFER_MSG_BF:
printBuffer("BF", TFT_WHITE);
printParity("Ok", TFT_WHITE);
bandposy = bandposy + SIGNHIGH + 3;
if (bandposy >= (SIGNPOSY + (SIGNHIGH + 3) * MAXBANDS)) {
bandposy = SIGNPOSY;
}
break;
}
M5.Lcd.fillRect(SIGNMARG, bandposy, 121, SIGNHIGH, BLACK);
myOnBufferMsg = BUFFER_MSG_NONE;
}

if (myOnTimeUpdateMsg != TIME_UPDATE_MSG_NONE) {
switch (myOnTimeUpdateMsg) {
case TIME_UPDATE_MSG_CLOSE_TO_INTERNAL_CLOCK:
printStatus("Close to internal clock");
break;
case TIME_UPDATE_MSG_TIME_LAG_CONSISTENT:
printStatus("Time lag consistent");
break;
case TIME_UPDATE_MSG_TIME_LAG_INCONSISTENT:
printStatus("Time lag inconsistent");
break;
default:
printStatus("Unknown time update msg");
break;
}
myOnTimeUpdateMsg = TIME_UPDATE_MSG_NONE;
}

if (myOnParityError == PARITY_ERROR_ERR) {
updateField(TFT_WIDTH - 60, INFOPOSY + DATEHIGH + 7, 60, DATEHIGH, TFT_CYAN);
M5.Lcd.printf("P:Err");
myOnParityError = PARITY_ERROR_NONE;
}
}

void setup() {
Serial.begin(115200);
M5.begin();
pinMode(M5STICKCPLUS_LED, OUTPUT);
digitalWrite(M5STICKCPLUS_LED, HIGH);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setTextColor(WHITE);
M5.Lcd.drawLine(0,DATEPOSY+DATEHIGH*3+2,TFT_WHITE,DATEPOSY+DATEHIGH*2+2,TFT_WHITE);
M5.Lcd.drawLine(0, DATEPOSY + DATEHIGH * 3 + 2, TFT_WHITE, DATEPOSY + DATEHIGH * 2 + 2, TFT_WHITE);

M5.Axp.ScreenBreath(backlight[brightness]);

delay(200);
Serial.flush();

// Configure DCF77
// (LOW = Normal operation, HIGH = standby)
pinMode(DCF77_PON_PIN, OUTPUT);
Expand All @@ -98,19 +183,17 @@ void setup() {
printStatus("It will take at least 2 minutes");
}

void buttonLoop(){
M5.update();
void buttonLoop() {
M5.update();
if (M5.BtnA.wasReleased()) { // If the button A is pressed.
if (brightness++ >= BRIGHT_SIZE-1) brightness = 0;
if (brightness++ >= BRIGHT_SIZE - 1) brightness = 0;
M5.Axp.ScreenBreath(backlight[brightness]);
}
}

void loop() {
buttonLoop();
dcfLoop();
cbLoop();
delay(80);
}



Loading