From de42c1cc4796f3874f1ed07a884bb08d93ba4f63 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Mon, 12 Feb 2018 15:54:56 +0100 Subject: [PATCH] gamma correction and status string --- src/alarmsound.h | 2 +- src/led.cpp | 5 +++-- src/main.cpp | 10 ++++++---- src/mp3.cpp | 3 ++- src/screen.cpp | 2 +- src/screen.h | 1 + 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/alarmsound.h b/src/alarmsound.h index 2c8af86..e0f8c9b 100644 --- a/src/alarmsound.h +++ b/src/alarmsound.h @@ -2,7 +2,7 @@ * under Creative Commons 0 License * https://freesound.org/people/Rudmer_Rotteveel/sounds/316920/ */ -unsigned char alarmsound[] = { +const unsigned char alarmsound[] PROGMEM = { 0xff, 0xfb, 0x90, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x6e, 0x66, 0x6f, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x4c, diff --git a/src/led.cpp b/src/led.cpp index 884575e..7e88799 100644 --- a/src/led.cpp +++ b/src/led.cpp @@ -47,7 +47,7 @@ void Led::loop_off(void) { if (wakeupIndex > 240) color = CRGB::White; fill_solid(leds, NUM_LEDS, color); // fadeToBlackBy( leds, NUM_LEDS, 255-wakeupIndex); - FastLED.setBrightness(wakeupIndex); + setBrightness(wakeupIndex); if (wakeupIndex < 100) { leds[3] = CRGB::Black; leds[NUM_LEDS-4] = CRGB::Black; @@ -95,7 +95,8 @@ void Led::setBrightness(uint8_t brightness) { if (brightness > 254) { // don't set first byte to 255 on tm1829 FastLED.setBrightness(254); } else { - FastLED.setBrightness(brightness); + uint8_t b = pow(((double)brightness/255.0), 4.2) * 255.0; + FastLED.setBrightness(b); } } diff --git a/src/main.cpp b/src/main.cpp index d0e06a0..542359a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,7 +40,7 @@ extern "C" { int rom_phy_get_vdd33(); -//uint8_t temprature_sens_read(); +uint8_t temprature_sens_read(); //uint32_t hall_sens_read(); } @@ -49,6 +49,7 @@ U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 16, /* clock=*/ 15 char timeStr[20]; char weatherStr[32]; +char statusStr[32]; RTC_DATA_ATTR static int boot_count = 0; RTC_DATA_ATTR struct tm alarmTime; RTC_DATA_ATTR bool alarmArmed = false; @@ -382,9 +383,10 @@ void loop() lastButtonPress = millis(); led.wakeUpLight(0); Serial.println("WAKEUP TIME!!!!!"); - mp3.setVolume(2); +// mp3.setVolume(10); // mp3.start_Progmem(); // delay(1500); + mp3.setVolume(2); mp3.start("http://radioessen.cast.addradio.de/radioessen/simulcast/high/stream.mp3"); led.changeAnimation(2, 0); } @@ -396,8 +398,8 @@ void loop() Serial.printf("voltage: %d\n", voltage); strftime(timeStr, sizeof(timeStr), "%H:%M:%S", &timeinfo); - sprintf(weatherStr, "%.1f°C %.1f%% %dmV", bme280.readTemperature(), bme280.readHumidity(), voltage); -// sprintf(weatherStr, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure()); + sprintf(weatherStr, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure()); + sprintf(statusStr, "%.1f°C %dmV %u %s", temperatureRead(), voltage, ESP.getFreeHeap()/1024, isAlarmActive()?"A":"_"); Serial.print("Free Heap: "); Serial.println(ESP.getFreeHeap()); diff --git a/src/mp3.cpp b/src/mp3.cpp index c737d4f..07961f8 100644 --- a/src/mp3.cpp +++ b/src/mp3.cpp @@ -23,6 +23,7 @@ char titleStr[64]; // convert mp3 files with `xxd -i alarm.wav > alarmsound.h` +// has to be: const unsigned char alarmsound[] PROGMEM = ... MP3::MP3() { strncpy_P(URL, "http://streaming.shoutcast.com/80sPlanet?lang=en-US", sizeof(URL)); @@ -107,7 +108,7 @@ void MP3::mp3_decoder_task(void *pvParameters) { // strcpy(titleStr, "loading..."); - if (fromProgmem) file = new AudioFileSourcePROGMEM(alarmsound, sizeof(alarmsound)); + if (fromProgmem) file = new AudioFileSourcePROGMEM(alarmsound, alarmsound_len); else file = new AudioFileSourceICYStream(URL); file->RegisterMetadataCB(MDCallback, (void*)"ICY"); buff = new AudioFileSourceBuffer(file, preallocateBuffer, preallocateBufferSize); diff --git a/src/screen.cpp b/src/screen.cpp index efefbb6..bae31ac 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -256,7 +256,7 @@ void MainScreen::draw() { u8g2.setFont(u8g2_font_profont12_mf); // choose a suitable font u8g2.drawUTF8(0, 30, weatherStr); - if (isAlarmActive()) u8g2.drawUTF8(110,42, "A"); + u8g2.drawUTF8(0,42, statusStr); u8g2.setFont(u8g2_font_prospero_bold_nbp_tf); // choose a suitable font diff --git a/src/screen.h b/src/screen.h index f721173..5681820 100644 --- a/src/screen.h +++ b/src/screen.h @@ -27,6 +27,7 @@ enum menuType { eNone=0, eWelcomeScreen, eMainScreen, eMainMenu, eStationMenu, e extern U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2; extern char timeStr[]; extern char weatherStr[]; +extern char statusStr[]; extern BME280 bme280; extern MP3 mp3; extern menuType menuChange;