More progress, implement testing application, polish color gradient calculation code as well
This commit is contained in:
parent
169d6eaa7e
commit
03ff18d178
@ -381,6 +381,7 @@ list(APPEND SOURCE_FILES
|
||||
displayapp/screens/Metronome.cpp
|
||||
displayapp/screens/Motion.cpp
|
||||
displayapp/screens/Weather.cpp
|
||||
displayapp/screens/WeatherColorTester.cpp
|
||||
displayapp/screens/FirmwareValidation.cpp
|
||||
displayapp/screens/ApplicationList.cpp
|
||||
displayapp/screens/Notifications.cpp
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "displayapp/screens/WatchFacePineTimeStyle.h"
|
||||
#include "displayapp/screens/WatchFaceTerminal.h"
|
||||
#include "displayapp/screens/Weather.h"
|
||||
#include "displayapp/screens/WeatherColorTester.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Applications {
|
||||
|
@ -20,8 +20,11 @@
|
||||
#include <FreeRTOS.h>
|
||||
#include <lvgl/src/lv_misc/lv_color.h>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
#include <nrfx_log.h>
|
||||
|
||||
using namespace Pinetime::Applications;
|
||||
@ -68,6 +71,13 @@ using namespace Pinetime::Applications;
|
||||
int outputRed = (redA + (redB - redA) * normalValue);
|
||||
int outputGreen = (greenA + (greenB - greenA) * normalValue);
|
||||
int outputBlue = (blueA + (blueB - blueA) * normalValue);
|
||||
|
||||
//increase brightness
|
||||
float incAmount = 1.2;
|
||||
outputRed = std::min(255, static_cast<int>(outputRed*incAmount));
|
||||
outputGreen = std::min(255, static_cast<int>(outputGreen*incAmount));
|
||||
outputBlue = std::min(255, static_cast<int>(outputBlue*incAmount));
|
||||
|
||||
auto lerpOutput = LV_COLOR_MAKE(outputRed, outputGreen, outputBlue);
|
||||
NRF_LOG_INFO("pointA: %i, %i, %i", redA, greenA, blueA);
|
||||
NRF_LOG_INFO("pointB: %i, %i, %i", redB, greenB, blueB);
|
||||
@ -75,32 +85,26 @@ using namespace Pinetime::Applications;
|
||||
return lerpOutput;
|
||||
}
|
||||
|
||||
const lv_color_t WeatherHelper::TemperatureColor(int16_t temperature) {
|
||||
const std::vector<int> colors = {0x5555ff, 0x00c9ff, 0x00ff3e, 0xff9b00, 0xff0000};
|
||||
std::vector<lv_color_t> stops;
|
||||
constexpr std::array<lv_color_t, 4> getColors() {
|
||||
const std::array<int, 4> colors = {0x5555ff, 0x00c9ff, 0xff9b00, 0xff0000};
|
||||
std::array<lv_color_t, 4> stops;
|
||||
int8_t i = 0;
|
||||
for (auto colorVal: colors) {
|
||||
stops.emplace_back(hexToFloat(colorVal));
|
||||
stops[i++] = (hexToFloat(colorVal));
|
||||
}
|
||||
return stops;
|
||||
}
|
||||
|
||||
const lv_color_t WeatherHelper::TemperatureColor(int16_t temperature) {
|
||||
std::array<lv_color_t, 4> stops = getColors();
|
||||
int tempRounded = RoundTemperature(temperature);
|
||||
if (tempRounded < 0) {
|
||||
tempRounded = 1;
|
||||
}
|
||||
// convert temperature to range between newMin and newMax
|
||||
float oldMax = 40;
|
||||
float oldMin = 0;
|
||||
float newMax = 1;
|
||||
float newMin = 0;
|
||||
float oldRange = (oldMax - oldMin);
|
||||
float newRange = (newMax - newMin);
|
||||
float newValue = (((tempRounded - oldMin) * newRange) / oldRange) + newMin;
|
||||
newValue = normalize(newValue);
|
||||
if (newValue <= .25f) {
|
||||
return lerp(stops[0], stops[1], newValue);
|
||||
} else if (newValue <= .50f) {
|
||||
return lerp(stops[1], stops[2], newValue);
|
||||
} else if (newValue <= .75f) {
|
||||
return lerp(stops[2], stops[3], newValue);
|
||||
} else {
|
||||
return lerp(stops[3], stops[4], newValue);
|
||||
}
|
||||
return lerp(stops[0], stops[3], newValue);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <FreeRTOS.h>
|
||||
#include <lvgl/src/lv_misc/lv_color.h>
|
||||
|
||||
@ -26,6 +26,10 @@ namespace Pinetime {
|
||||
static int16_t RoundTemperature(int16_t temp);
|
||||
static const lv_color_t TemperatureColor(int16_t temperature);
|
||||
static const char* floatToRgbHex(lv_color_t rgb);
|
||||
constexpr static float oldMax = 50;
|
||||
constexpr static float oldMin = 0;
|
||||
constexpr static float newMax = 1;
|
||||
constexpr static float newMin = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ namespace Pinetime {
|
||||
Steps,
|
||||
Dice,
|
||||
Weather,
|
||||
WeatherColorTester,
|
||||
PassKey,
|
||||
QuickSettings,
|
||||
Settings,
|
||||
|
@ -14,6 +14,7 @@ else ()
|
||||
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Metronome")
|
||||
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Navigation")
|
||||
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Weather")
|
||||
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::WeatherColorTester")
|
||||
#set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Motion")
|
||||
set(USERAPP_TYPES "${DEFAULT_USER_APP_TYPES}" CACHE STRING "List of user apps to build into the firmware")
|
||||
endif ()
|
||||
|
34
src/displayapp/screens/WeatherColorTester.cpp
Normal file
34
src/displayapp/screens/WeatherColorTester.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include "displayapp/screens/WeatherColorTester.h"
|
||||
#include "displayapp/WeatherHelper.h"
|
||||
#include "displayapp/LittleVgl.h"
|
||||
#include <nrfx_log.h>
|
||||
#include <algorithm> // std::fill
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
|
||||
WeatherColorTester::WeatherColorTester(Pinetime::Components::LittleVgl& lvgl) : lvgl {lvgl} {
|
||||
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void WeatherColorTester::Refresh() { //WeatherHelper::oldMax
|
||||
for (size_t i = 0; i < WeatherHelper::oldMax; ++i) {
|
||||
// get current color
|
||||
currentColor = WeatherHelper::TemperatureColor(i * 100);
|
||||
// create area we want to color
|
||||
lv_area_t area;
|
||||
area.y1 = x + i;
|
||||
area.x1 = 0;
|
||||
area.y2 = (x + i) + 1;
|
||||
area.x2 = y;
|
||||
NRF_LOG_INFO("area coords: %i, %i, %i, %i", area.x1, area.y1, area.x2, area.y2);
|
||||
// write the buffer to the display
|
||||
lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::None);
|
||||
std::fill(buffer, buffer + bufferSize, currentColor);
|
||||
lvgl.FlushDisplay(&area, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
WeatherColorTester::~WeatherColorTester() {
|
||||
lv_task_del(taskRefresh);
|
||||
lv_obj_clean(lv_scr_act());
|
||||
}
|
41
src/displayapp/screens/WeatherColorTester.h
Normal file
41
src/displayapp/screens/WeatherColorTester.h
Normal file
@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayapp/apps/Apps.h"
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include "displayapp/Controllers.h"
|
||||
#include <lvgl/src/lv_hal/lv_hal_disp.h>
|
||||
#include "Symbols.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Applications {
|
||||
namespace Screens {
|
||||
class WeatherColorTester : public Screen {
|
||||
public:
|
||||
explicit WeatherColorTester(Pinetime::Components::LittleVgl& lvgl);
|
||||
WeatherColorTester() = delete;
|
||||
~WeatherColorTester() override;
|
||||
void Refresh() override;
|
||||
private:
|
||||
Pinetime::Components::LittleVgl& lvgl;
|
||||
lv_task_t* taskRefresh;
|
||||
static constexpr int x = 0;
|
||||
static constexpr int y = 240;
|
||||
static constexpr int bufferSize = (480);
|
||||
lv_color_t buffer[bufferSize];
|
||||
|
||||
lv_color_t currentColor;
|
||||
//static lv_disp_draw_buf_t disp_buf;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
struct AppTraits<Apps::WeatherColorTester> {
|
||||
static constexpr Apps app = Apps::WeatherColorTester;
|
||||
static constexpr const char* icon = Screens::Symbols::bolt;
|
||||
static Screens::Screen* Create(AppControllers& controllers) {
|
||||
return new Screens::WeatherColorTester(controllers.lvgl);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user