Compare commits

..

No commits in common. "main" and "powersave" have entirely different histories.

7 changed files with 26 additions and 59 deletions

View file

@ -3,7 +3,7 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD 20)
# Initialise pico_sdk from installed location # Initialise pico_sdk from installed location
# (note this can come from environment, CMake cache etc) # (note this can come from environment, CMake cache etc)
@ -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}") message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.4.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
endif() endif()
project(abfall VERSION "1.2.2" LANGUAGES C CXX ASM) project(abfall VERSION "1.0.0" LANGUAGES C CXX ASM)
# Initialise the Raspberry Pi Pico SDK # Initialise the Raspberry Pi Pico SDK
pico_sdk_init() pico_sdk_init()

View file

@ -51,7 +51,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
pico_enable_stdio_usb(${CMAKE_PROJECT_NAME} 0) pico_enable_stdio_usb(${CMAKE_PROJECT_NAME} 0)
else() else()
pico_enable_stdio_uart(${CMAKE_PROJECT_NAME} 0) pico_enable_stdio_uart(${CMAKE_PROJECT_NAME} 0)
pico_enable_stdio_usb(${CMAKE_PROJECT_NAME} 0) pico_enable_stdio_usb(${CMAKE_PROJECT_NAME} 1)
endif() endif()
target_link_libraries(${CMAKE_PROJECT_NAME} target_link_libraries(${CMAKE_PROJECT_NAME}

View file

@ -1,6 +1,7 @@
#include <cstdio> #include <cstdio>
#include <algorithm> #include <algorithm>
#include <chrono>
#include <iostream> #include <iostream>
#include <string> #include <string>
@ -29,8 +30,8 @@ int main() {
#ifdef DEBUG #ifdef DEBUG
printf("!!! DEBUG mode !!!\n"); printf("!!! DEBUG mode !!!\n");
printf("Firmware version: %s\n", PROJECT_VERSION);
#endif #endif
printf("Firmware version: %s\n", PROJECT_VERSION);
wifi_enable(); // Enable Wifi in order to set time and retrieve data wifi_enable(); // Enable Wifi in order to set time and retrieve data
@ -82,12 +83,11 @@ int main() {
rtc_get_datetime(&dt); rtc_get_datetime(&dt);
datetime_t tomorrowYMD = dt; chrono::year_month_day tomorrowYMD(chrono::year{dt.year},
add_one_day(tomorrowYMD); chrono::month{static_cast<unsigned>(dt.month)},
chrono::day{static_cast<unsigned>(dt.day + 1)});
auto it = std::find_if(dates.begin(), dates.end(), [&tomorrowYMD](const WasteDate &x) { auto it = std::find_if(dates.begin(), dates.end(), [&tomorrowYMD](const WasteDate &date) {
return tomorrowYMD.year == x.date.year && tomorrowYMD.month == x.date.month && return date.date == tomorrowYMD;
tomorrowYMD.day == x.date.day;
}); });
int8_t hour = isDST(dt) ? dt.hour + 1 : dt.hour; int8_t hour = isDST(dt) ? dt.hour + 1 : dt.hour;

View file

@ -1,5 +1,6 @@
#include "http_client.h" #include "http_client.h"
#include <iostream>
#include <memory> #include <memory>
std::unique_ptr<char[]> myBodyBuffer = nullptr; std::unique_ptr<char[]> myBodyBuffer = nullptr;
@ -49,7 +50,7 @@ std::string HttpClient::retrieveWasteDatesAsCsv() {
std::string result(""); std::string result("");
err_t err = httpc_get_file_dns("hornet.brodbeck-online.de", port, "/abfall/abfall.csv", err_t err = httpc_get_file_dns("beenas.brodbeck-online.de", port, "/abfall/abfall.csv",
&m_settings, body_callback, nullptr, nullptr); &m_settings, body_callback, nullptr, nullptr);
// If there was an error, return empty result. // If there was an error, return empty result.
@ -71,7 +72,7 @@ std::string HttpClient::retrieveWasteDatesAsCsv() {
received = false; received = false;
#ifdef DEBUG #ifdef DEBUG
printf("%s", result.c_str()); std::cout << result << std::endl;
#endif #endif
return result; return result;

View file

@ -1,16 +1,15 @@
#include "utils.h" #include "utils.h"
#include <cmath>
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include "pico/sleep.h"
#include "pico/stdlib.h"
// #include "stdlib.h"
#include "hardware/clocks.h" #include "hardware/clocks.h"
#include "hardware/rosc.h" #include "hardware/rosc.h"
#include "hardware/structs/scb.h" #include "hardware/structs/scb.h"
#include "pico/sleep.h"
#include "pico/stdlib.h"
using namespace std; using namespace std;
@ -37,42 +36,17 @@ bool isDST(const datetime_t &dt) {
return previousSunday < 25; return previousSunday < 25;
} }
int8_t calcDotw(int year, int month, int day) { chrono::year_month_day stringToDate(const std::string &dateStr) {
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); istringstream partss(dateStr);
string day_str, month_str, year_str; string day_str, month_str, year_str;
getline(partss, day_str, '.'); getline(partss, day_str, '.');
getline(partss, month_str, '.'); getline(partss, month_str, '.');
getline(partss, year_str, '.'); getline(partss, year_str, '.');
int day = atoi(day_str.c_str()); int day = atoi(day_str.c_str());
int month = atoi(month_str.c_str()); int month = atoi(month_str.c_str());
int year = atoi(year_str.c_str()); int year = atoi(year_str.c_str());
chrono::year_month_day date{chrono::year{year}, chrono::month{(uint)month},
datetime_t date; chrono::day{(uint)day}};
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; return date;
} }
@ -109,10 +83,8 @@ std::vector<WasteDate> parseCsv(const std::string &csv) {
// Take existing date or create a new one. // Take existing date or create a new one.
std::vector<WasteDate>::iterator it; std::vector<WasteDate>::iterator it;
it = std::find_if(wasteDates.begin(), wasteDates.end(), [&date](const WasteDate &x) { it = std::find_if(wasteDates.begin(), wasteDates.end(),
return date.year == x.date.year && date.month == x.date.month && [&date](const WasteDate &x) { return date == x.date; });
date.day == x.date.day;
});
if (it == wasteDates.end()) { if (it == wasteDates.end()) {
WasteDate wd; WasteDate wd;
wd.date = date; wd.date = date;
@ -241,9 +213,7 @@ void recover_from_sleep(uint scb_orig, uint clock0_orig, uint clock1_orig) {
} }
void perform_sleep(datetime_t &untilDt) { void perform_sleep(datetime_t &untilDt) {
#ifdef DEBUG
printf("Going to sleep...\n"); printf("Going to sleep...\n");
#endif
uart_default_tx_wait_blocking(); uart_default_tx_wait_blocking();
sleep_goto_sleep_until(&untilDt, nullptr); sleep_goto_sleep_until(&untilDt, nullptr);
@ -261,14 +231,11 @@ void add_one_day(datetime_t &dt) {
dt.year += 1; dt.year += 1;
dt.month = 1; dt.month = 1;
dt.day = 1; dt.day = 1;
dt.dotw = (dt.dotw + 1) % 7;
} else if (dt.day == daysPerMonth[dt.month]) { } else if (dt.day == daysPerMonth[dt.month]) {
dt.month = (dt.month + 1) % 12; dt.month = (dt.month + 1) % 12;
dt.day = 1; dt.day = 1;
dt.dotw = (dt.dotw + 1) % 7;
} else { } else {
dt.day += 1; dt.day += 1;
dt.dotw = (dt.dotw + 1) % 7;
} }
} }

View file

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <chrono>
#include <string> #include <string>
#include <vector> #include <vector>
@ -14,7 +15,7 @@ enum class Waste {
}; };
struct WasteDate { struct WasteDate {
datetime_t date; std::chrono::year_month_day date;
std::vector<Waste> wasteTypes; std::vector<Waste> wasteTypes;
}; };
@ -32,6 +33,6 @@ void recover_from_sleep(uint scb_orig, uint clock0_orig, uint clock1_orig);
void perform_sleep(datetime_t &untilDt); 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); void add_one_hour(datetime_t &dt);

View file

@ -1,12 +1,10 @@
#include "ws2812.h" #include "ws2812.h"
#include <utility>
WS2812::WS2812(uint gpio, PIO pio, uint sm) : m_pio{pio}, m_gpio{gpio}, m_sm{sm} { init(); } WS2812::WS2812(uint gpio, PIO pio, uint sm) : m_pio{pio}, m_gpio{gpio}, m_sm{sm} { init(); }
WS2812::~WS2812() { deinit(); } WS2812::~WS2812() { deinit(); }
void WS2812::switchColor(Color color) { putPixel(std::to_underlying(color)); } void WS2812::switchColor(Color color) { putPixel(static_cast<uint32_t>(color)); }
void WS2812::blinkReady() { void WS2812::blinkReady() {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {