From 46b82f7995942f5651141ce463c2d6900665d15a Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 11 Jan 2023 11:32:20 +0100 Subject: [PATCH 01/11] code cleanup --- src/abfall.cpp | 2 +- src/http_client.cpp | 3 +-- src/utils.cpp | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/abfall.cpp b/src/abfall.cpp index f914b7c..c4b21e9 100644 --- a/src/abfall.cpp +++ b/src/abfall.cpp @@ -30,8 +30,8 @@ int main() { #ifdef DEBUG printf("!!! DEBUG mode !!!\n"); -#endif printf("Firmware version: %s\n", PROJECT_VERSION); +#endif wifi_enable(); // Enable Wifi in order to set time and retrieve data diff --git a/src/http_client.cpp b/src/http_client.cpp index 9ea3e99..c899c6c 100644 --- a/src/http_client.cpp +++ b/src/http_client.cpp @@ -1,6 +1,5 @@ #include "http_client.h" -#include #include std::unique_ptr myBodyBuffer = nullptr; @@ -72,7 +71,7 @@ std::string HttpClient::retrieveWasteDatesAsCsv() { received = false; #ifdef DEBUG - std::cout << result << std::endl; + printf("%s", result.c_str()); #endif return result; diff --git a/src/utils.cpp b/src/utils.cpp index 8a97c95..5584cb0 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -213,7 +213,9 @@ void recover_from_sleep(uint scb_orig, uint clock0_orig, uint clock1_orig) { } void perform_sleep(datetime_t &untilDt) { +#ifdef DEBUG printf("Going to sleep...\n"); +#endif uart_default_tx_wait_blocking(); sleep_goto_sleep_until(&untilDt, nullptr); From 2829cfa4e2bb5f382abf2ff1ddd92cc13b2eb0e2 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 11 Jan 2023 11:33:53 +0100 Subject: [PATCH 02/11] disable usb stdio --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2a23ef7..79fc2d9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,7 +51,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug") pico_enable_stdio_usb(${CMAKE_PROJECT_NAME} 0) else() pico_enable_stdio_uart(${CMAKE_PROJECT_NAME} 0) - pico_enable_stdio_usb(${CMAKE_PROJECT_NAME} 1) + pico_enable_stdio_usb(${CMAKE_PROJECT_NAME} 0) endif() target_link_libraries(${CMAKE_PROJECT_NAME} From a7072fcdf7b949af166e902f9ac1b4c3712102d3 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 11 Jan 2023 11:34:46 +0100 Subject: [PATCH 03/11] push version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c088b1..21c085f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ if (PICO_SDK_VERSION_STRING VERSION_LESS "1.4.0") message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.4.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}") endif() -project(abfall VERSION "1.0.0" LANGUAGES C CXX ASM) +project(abfall VERSION "1.1.0" LANGUAGES C CXX ASM) # Initialise the Raspberry Pi Pico SDK pico_sdk_init() From 433bfefa7d2296338648beccb17dd3bf9a4903db Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 11 Jan 2023 12:02:17 +0100 Subject: [PATCH 04/11] code cleanup --- src/utils.cpp | 1 - src/utils.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils.cpp b/src/utils.cpp index 5584cb0..fbea4a1 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -6,7 +6,6 @@ #include "pico/sleep.h" #include "pico/stdlib.h" -// #include "stdlib.h" #include "hardware/clocks.h" #include "hardware/rosc.h" #include "hardware/structs/scb.h" diff --git a/src/utils.h b/src/utils.h index f7c9d2c..56702a1 100644 --- a/src/utils.h +++ b/src/utils.h @@ -33,6 +33,6 @@ void recover_from_sleep(uint scb_orig, uint clock0_orig, uint clock1_orig); void perform_sleep(datetime_t &untilDt); -//void add_one_day(datetime_t &dt); +void add_one_day(datetime_t &dt); void add_one_hour(datetime_t &dt); \ No newline at end of file From e9ce09a02959c0631108a2adcd0d230b49d05611 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 11 Jan 2023 12:40:21 +0100 Subject: [PATCH 05/11] get rid of xhrono --- src/abfall.cpp | 12 ++++++------ src/utils.cpp | 43 ++++++++++++++++++++++++++++++++++++------- src/utils.h | 3 +-- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/abfall.cpp b/src/abfall.cpp index c4b21e9..9464034 100644 --- a/src/abfall.cpp +++ b/src/abfall.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include @@ -83,11 +82,12 @@ int main() { rtc_get_datetime(&dt); - chrono::year_month_day tomorrowYMD(chrono::year{dt.year}, - chrono::month{static_cast(dt.month)}, - chrono::day{static_cast(dt.day + 1)}); - auto it = std::find_if(dates.begin(), dates.end(), [&tomorrowYMD](const WasteDate &date) { - return date.date == tomorrowYMD; + datetime_t tomorrowYMD = dt; + add_one_day(tomorrowYMD); + + auto it = std::find_if(dates.begin(), dates.end(), [&tomorrowYMD](const WasteDate &x) { + return tomorrowYMD.year == x.date.year && tomorrowYMD.month == x.date.month && + tomorrowYMD.day == x.date.day; }); int8_t hour = isDST(dt) ? dt.hour + 1 : dt.hour; diff --git a/src/utils.cpp b/src/utils.cpp index fbea4a1..9c8caf2 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,14 +1,16 @@ #include "utils.h" +#include + #include #include #include -#include "pico/sleep.h" -#include "pico/stdlib.h" #include "hardware/clocks.h" #include "hardware/rosc.h" #include "hardware/structs/scb.h" +#include "pico/sleep.h" +#include "pico/stdlib.h" using namespace std; @@ -35,17 +37,42 @@ bool isDST(const datetime_t &dt) { return previousSunday < 25; } -chrono::year_month_day stringToDate(const std::string &dateStr) { +int8_t calcDotw(int year, int month, int day) { + int mon; + if (month > 2) + mon = month; // for march to december month code is same as month + else { + mon = (12 + month); // for Jan and Feb, month code will be 13 and 14 + year--; // decrease year for month Jan and Feb + } + int y = year % 100; // last two digit + int c = year / 100; // first two digit + int w = (day + floor((13 * (mon + 1)) / 5) + y + floor(y / 4) + floor(c / 4) - (2 * c)); + w = (w % 7) - 1; + return w; +} + +datetime_t stringToDate(const std::string &dateStr) { istringstream partss(dateStr); string day_str, month_str, year_str; + getline(partss, day_str, '.'); getline(partss, month_str, '.'); getline(partss, year_str, '.'); + int day = atoi(day_str.c_str()); int month = atoi(month_str.c_str()); int year = atoi(year_str.c_str()); - chrono::year_month_day date{chrono::year{year}, chrono::month{(uint)month}, - chrono::day{(uint)day}}; + + datetime_t date; + date.year = year; + date.month = month; + date.day = day; + date.dotw = calcDotw(year, month, day); + date.hour = 0; + date.min = 0; + date.sec = 0; + return date; } @@ -82,8 +109,10 @@ std::vector parseCsv(const std::string &csv) { // Take existing date or create a new one. std::vector::iterator it; - it = std::find_if(wasteDates.begin(), wasteDates.end(), - [&date](const WasteDate &x) { return date == x.date; }); + it = std::find_if(wasteDates.begin(), wasteDates.end(), [&date](const WasteDate &x) { + return date.year == x.date.year && date.month == x.date.month && + date.day == x.date.day; + }); if (it == wasteDates.end()) { WasteDate wd; wd.date = date; diff --git a/src/utils.h b/src/utils.h index 56702a1..bfce9c4 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include @@ -15,7 +14,7 @@ enum class Waste { }; struct WasteDate { - std::chrono::year_month_day date; + datetime_t date; std::vector wasteTypes; }; From 2e62919999f5083827beaced62af01d0904c3826 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 11 Jan 2023 12:48:10 +0100 Subject: [PATCH 06/11] push version number --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 21c085f..efa2610 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ if (PICO_SDK_VERSION_STRING VERSION_LESS "1.4.0") message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.4.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}") endif() -project(abfall VERSION "1.1.0" LANGUAGES C CXX ASM) +project(abfall VERSION "1.2.0" LANGUAGES C CXX ASM) # Initialise the Raspberry Pi Pico SDK pico_sdk_init() From e9fef4f4d3a2ca4cfc0477d1421c42a2db66338b Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Thu, 12 Jan 2023 08:49:02 +0100 Subject: [PATCH 07/11] using new language feature --- CMakeLists.txt | 2 +- src/ws2812.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index efa2610..07932d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.13) set(CMAKE_C_STANDARD 11) -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 23) # Initialise pico_sdk from installed location # (note this can come from environment, CMake cache etc) diff --git a/src/ws2812.cpp b/src/ws2812.cpp index edf35b7..d21074b 100644 --- a/src/ws2812.cpp +++ b/src/ws2812.cpp @@ -1,10 +1,12 @@ #include "ws2812.h" +#include + WS2812::WS2812(uint gpio, PIO pio, uint sm) : m_pio{pio}, m_gpio{gpio}, m_sm{sm} { init(); } WS2812::~WS2812() { deinit(); } -void WS2812::switchColor(Color color) { putPixel(static_cast(color)); } +void WS2812::switchColor(Color color) { putPixel(std::to_underlying(color)); } void WS2812::blinkReady() { for (int i = 0; i < 2; i++) { From 5b12a9cd1631eb2874d7a235128c130b1f5f83e2 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Fri, 13 Jan 2023 17:53:25 +0100 Subject: [PATCH 08/11] fix setting dotw --- src/utils.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils.cpp b/src/utils.cpp index 9c8caf2..d07a4f4 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -261,11 +261,14 @@ void add_one_day(datetime_t &dt) { dt.year += 1; dt.month = 1; dt.day = 1; + dt.dotw = (dt.dotw + 1) % 7; } else if (dt.day == daysPerMonth[dt.month]) { dt.month = (dt.month + 1) % 12; dt.day = 1; + dt.dotw = (dt.dotw + 1) % 7; } else { dt.day += 1; + dt.dotw = (dt.dotw + 1) % 7; } } From 89f646fc6cdba25df36ad008ea7e1a4cb6388546 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Fri, 13 Jan 2023 17:53:55 +0100 Subject: [PATCH 09/11] push version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 07932d2..c5d5d1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ if (PICO_SDK_VERSION_STRING VERSION_LESS "1.4.0") message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.4.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}") endif() -project(abfall VERSION "1.2.0" LANGUAGES C CXX ASM) +project(abfall VERSION "1.2.1" LANGUAGES C CXX ASM) # Initialise the Raspberry Pi Pico SDK pico_sdk_init() From 58f364d930da43eb2a28e0bef586822073174e34 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 14 Jun 2023 15:01:33 +0200 Subject: [PATCH 10/11] hostname changed --- src/http_client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/http_client.cpp b/src/http_client.cpp index c899c6c..4809783 100644 --- a/src/http_client.cpp +++ b/src/http_client.cpp @@ -49,7 +49,7 @@ std::string HttpClient::retrieveWasteDatesAsCsv() { std::string result(""); - err_t err = httpc_get_file_dns("beenas.brodbeck-online.de", port, "/abfall/abfall.csv", + err_t err = httpc_get_file_dns("hornet.brodbeck-online.de", port, "/abfall/abfall.csv", &m_settings, body_callback, nullptr, nullptr); // If there was an error, return empty result. @@ -75,4 +75,4 @@ std::string HttpClient::retrieveWasteDatesAsCsv() { #endif return result; -} \ No newline at end of file +} From 82178c139866539f10752bbbb39f596dad8f4f58 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 14 Jun 2023 15:02:43 +0200 Subject: [PATCH 11/11] new version 1.2.2 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c5d5d1b..ce3a8f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ if (PICO_SDK_VERSION_STRING VERSION_LESS "1.4.0") message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.4.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}") endif() -project(abfall VERSION "1.2.1" LANGUAGES C CXX ASM) +project(abfall VERSION "1.2.2" LANGUAGES C CXX ASM) # Initialise the Raspberry Pi Pico SDK pico_sdk_init()