diff --git a/alarm.mp3 b/alarm.mp3 new file mode 100644 index 0000000..1c13d71 Binary files /dev/null and b/alarm.mp3 differ diff --git a/alarm.wav b/alarm.wav deleted file mode 100644 index 855e382..0000000 Binary files a/alarm.wav and /dev/null differ diff --git a/platformio.ini b/platformio.ini index 246f2b0..db1f4b4 100644 --- a/platformio.ini +++ b/platformio.ini @@ -15,7 +15,8 @@ board = heltec_wifi_lora_32 board_f_cpu = 240000000L board_f_flash = 80000000L framework = arduino -build_flags = -DLOG_LOCAL_LEVEL=ESP_LOG_VERBOSE -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -DDEBUG_INT_ALLOC_DECISIONS=1 -DCONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL=y +build_flags = -DLOG_LOCAL_LEVEL=ESP_LOG_VERBOSE -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -DDEBUG_INT_ALLOC_DECISIONS=1 +; -DCONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL=y lib_deps = ; Basecamp diff --git a/src/hardware.h b/src/hardware.h index a05bb66..b38cd81 100644 --- a/src/hardware.h +++ b/src/hardware.h @@ -6,8 +6,8 @@ // KEY_BUILTIN = 0 static constexpr uint8_t buttonPin = 0; static constexpr uint8_t sensorPin = 0; -static constexpr uint8_t rotaryPinA = 39; -static constexpr uint8_t rotaryPinB = 38; +static constexpr uint8_t rotaryPinA = 35; +static constexpr uint8_t rotaryPinB = 34; static constexpr uint8_t rotaryPinButton = 2; static constexpr uint8_t PROGMEM LED_PIN = 21; static constexpr uint8_t PROGMEM NUM_LEDS = 10; @@ -34,10 +34,10 @@ static constexpr int batteryLimit = 2800; * 3V3 O O 3V3 * GND O < 36 only input, no pullups * RX * (3) < 37 only input, no pullups - * TX * (1) < 38 ROTARY_A only input, no pullups - * RST * BUTTON < 39 ROTARY_B only input, no pullups - * 0 * KEY_BUILTIN < 34 only input, no pullups - * 22 * ? < 35 only input, no pullups + * TX * (1) < 38 only input, no pullups + * RST * BUTTON hall < 39 only input, no pullups + * 0 * KEY_BUILTIN < 34 ROTARY_B only input, no pullups + * 22 * ? < 35 ROTARY_A only input, no pullups * BME280_SDO 19 * LoRa_MISO ? * 32 * BME280_CS 23 * ? * 33 * 18 x LoRa_CS * 25 MAX98_DIN diff --git a/src/main.cpp b/src/main.cpp index c190dac..96a79a5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -321,6 +321,14 @@ struct tm getAlarmTime() { return alarmTime; } +bool isAlarmActive(){ + time_t now; + time(&now); + double seconds = difftime(now, mktime(&alarmTime)); + if (seconds > -24*60*60 && seconds <=0) return true; + else return false; +} + void obtain_time(void) { sntp_setoperatingmode(SNTP_OPMODE_POLL); @@ -348,6 +356,7 @@ void rotation(int i, int direction, int buttonPressed) { } if (direction == 1) screen->next(); else if (direction == -1) screen->previous(); + Serial.println("rotation call returned"); } diff --git a/src/main.h b/src/main.h index 43cd262..38b2dd5 100644 --- a/src/main.h +++ b/src/main.h @@ -7,6 +7,7 @@ void suspend(uint32_t secondsToSleep); void suspend(); void setAlarmTime(struct tm time); struct tm getAlarmTime(); +bool isAlarmActive(); void loop(); void rotation(int i, int direction, int buttonPressed); void obtain_time(void); diff --git a/src/rotary.cpp b/src/rotary.cpp index 8cb51d5..637a8b8 100644 --- a/src/rotary.cpp +++ b/src/rotary.cpp @@ -28,7 +28,7 @@ bool Rotary::begin(uint8_t pinA, uint8_t pinB, uint8_t pinButton) { "encoderTask", /* String with name of task. */ 2048, /* Stack size in words. */ this, /* Parameter passed as input of the task */ - tskIDLE_PRIORITY+2, /* Priority of the task. */ + tskIDLE_PRIORITY+1, /* Priority of the task. */ &taskHandle); /* Task handle. */ attachInterrupt(digitalPinToInterrupt(pinA), doEncoder, CHANGE); @@ -47,7 +47,8 @@ void Rotary::task(void *pvParameters) { uint32_t ulNotificationValue; while(true) { ulNotificationValue = ulTaskNotifyTake( pdTRUE, portMAX_DELAY ); - delay(2); // wait until bounce settled + Serial.println("rotation task"); + delay(1); // wait until bounce settled (1 or 2 is fine) if (digitalRead(pinButton) == HIGH) { buttonPressed = true; @@ -75,8 +76,9 @@ void Rotary::task(void *pvParameters) { ulNotificationValue = ulTaskNotifyTake( pdTRUE, 0 ); // clear pending notifications - debouncePulses++; - if (debouncePulses > 3) { // update every 4 pulses +// debouncePulses++; +// if (debouncePulses > 3) { // update every 4 pulses + if (digitalRead(pinB) == HIGH && digitalRead(pinA) == HIGH) { // update everytime inbetween positions debouncePulses = 0; if (encoderPos > encoderPosOld+1) { value++; // if the value has at least changed for 2 diff --git a/src/screen.cpp b/src/screen.cpp index 3a9c192..efefbb6 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -255,6 +255,9 @@ void MainScreen::draw() { u8g2.drawStr(0, 20, timeStr); u8g2.setFont(u8g2_font_profont12_mf); // choose a suitable font u8g2.drawUTF8(0, 30, weatherStr); + + if (isAlarmActive()) u8g2.drawUTF8(110,42, "A"); + u8g2.setFont(u8g2_font_prospero_bold_nbp_tf); // choose a suitable font u8g2_uint_t width = u8g2.getUTF8Width(titleStr); // calculate the pixel width of the text