Merge branch 'brightness-app' of JF/PineTime into develop
commit
2c55ab20b4
@ -0,0 +1,70 @@
|
||||
#include <hal/nrf_gpio.h>
|
||||
#include "BrightnessController.h"
|
||||
|
||||
using namespace Pinetime::Controllers;
|
||||
|
||||
|
||||
void BrightnessController::Init() {
|
||||
nrf_gpio_cfg_output(pinLcdBacklight1);
|
||||
nrf_gpio_cfg_output(pinLcdBacklight2);
|
||||
nrf_gpio_cfg_output(pinLcdBacklight3);
|
||||
Set(level);
|
||||
}
|
||||
|
||||
void BrightnessController::Set(BrightnessController::Levels level) {
|
||||
this->level = level;
|
||||
switch(level) {
|
||||
default:
|
||||
case Levels::High:
|
||||
nrf_gpio_pin_clear(pinLcdBacklight1);
|
||||
nrf_gpio_pin_clear(pinLcdBacklight2);
|
||||
nrf_gpio_pin_clear(pinLcdBacklight3);
|
||||
break;
|
||||
case Levels::Medium:
|
||||
nrf_gpio_pin_clear(pinLcdBacklight1);
|
||||
nrf_gpio_pin_clear(pinLcdBacklight2);
|
||||
nrf_gpio_pin_set(pinLcdBacklight3);
|
||||
break;
|
||||
case Levels::Low:
|
||||
nrf_gpio_pin_clear(pinLcdBacklight1);
|
||||
nrf_gpio_pin_set(pinLcdBacklight2);
|
||||
nrf_gpio_pin_set(pinLcdBacklight3);
|
||||
break;
|
||||
case Levels::Off:
|
||||
nrf_gpio_pin_set(pinLcdBacklight1);
|
||||
nrf_gpio_pin_set(pinLcdBacklight2);
|
||||
nrf_gpio_pin_set(pinLcdBacklight3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void BrightnessController::Lower() {
|
||||
switch(level) {
|
||||
case Levels::High: Set(Levels::Medium); break;
|
||||
case Levels::Medium: Set(Levels::Low); break;
|
||||
case Levels::Low: Set(Levels::Off); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
void BrightnessController::Higher() {
|
||||
switch(level) {
|
||||
case Levels::Off: Set(Levels::Low); break;
|
||||
case Levels::Low: Set(Levels::Medium); break;
|
||||
case Levels::Medium: Set(Levels::High); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
BrightnessController::Levels BrightnessController::Level() const {
|
||||
return level;
|
||||
}
|
||||
|
||||
void BrightnessController::Backup() {
|
||||
backupLevel = level;
|
||||
}
|
||||
|
||||
void BrightnessController::Restore() {
|
||||
Set(backupLevel);
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Controllers {
|
||||
class BrightnessController {
|
||||
public:
|
||||
enum class Levels {Off, Low, Medium, High};
|
||||
void Init();
|
||||
|
||||
void Set(Levels level);
|
||||
Levels Level() const;
|
||||
void Lower();
|
||||
void Higher();
|
||||
|
||||
void Backup();
|
||||
void Restore();
|
||||
|
||||
private:
|
||||
static constexpr uint8_t pinLcdBacklight1 = 14;
|
||||
static constexpr uint8_t pinLcdBacklight2 = 22;
|
||||
static constexpr uint8_t pinLcdBacklight3 = 23;
|
||||
Levels level = Levels::High;
|
||||
Levels backupLevel = Levels::High;
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
#include <libs/lvgl/lvgl.h>
|
||||
#include "Brightness.h"
|
||||
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
|
||||
void slider_event_cb(lv_obj_t * slider, lv_event_t event) {
|
||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||
auto* brightnessSlider = static_cast<Brightness*>(slider->user_data);
|
||||
brightnessSlider->OnValueChanged();
|
||||
}
|
||||
}
|
||||
|
||||
Brightness::Brightness(Pinetime::Applications::DisplayApp *app, Controllers::BrightnessController& brightness) : Screen(app), brightness{brightness} {
|
||||
slider = lv_slider_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_user_data(slider, this);
|
||||
lv_obj_set_width(slider, LV_DPI * 2);
|
||||
lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_set_event_cb(slider, slider_event_cb);
|
||||
lv_slider_set_range(slider, 0, 2);
|
||||
lv_slider_set_value(slider, LevelToInt(brightness.Level()), LV_ANIM_OFF);
|
||||
|
||||
slider_label = lv_label_create(lv_scr_act(), NULL);
|
||||
lv_label_set_text(slider_label, LevelToString(brightness.Level()));
|
||||
lv_obj_set_auto_realign(slider_label, true);
|
||||
lv_obj_align(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
|
||||
}
|
||||
|
||||
Brightness::~Brightness() {
|
||||
lv_obj_clean(lv_scr_act());
|
||||
}
|
||||
|
||||
bool Brightness::Refresh() {
|
||||
return running;
|
||||
}
|
||||
|
||||
bool Brightness::OnButtonPushed() {
|
||||
running = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *Brightness::LevelToString(Pinetime::Controllers::BrightnessController::Levels level) {
|
||||
switch(level) {
|
||||
case Pinetime::Controllers::BrightnessController::Levels::Off: return "Off";
|
||||
case Pinetime::Controllers::BrightnessController::Levels::Low: return "Low";
|
||||
case Pinetime::Controllers::BrightnessController::Levels::Medium: return "Medium";
|
||||
case Pinetime::Controllers::BrightnessController::Levels::High: return "High";
|
||||
default : return "???";
|
||||
}
|
||||
}
|
||||
|
||||
void Brightness::OnValueChanged() {
|
||||
SetValue(lv_slider_get_value(slider));
|
||||
}
|
||||
|
||||
void Brightness::SetValue(uint8_t value) {
|
||||
switch(value) {
|
||||
case 0: brightness.Set(Controllers::BrightnessController::Levels::Low); break;
|
||||
case 1: brightness.Set(Controllers::BrightnessController::Levels::Medium); break;
|
||||
case 2: brightness.Set(Controllers::BrightnessController::Levels::High); break;
|
||||
}
|
||||
lv_label_set_text(slider_label, LevelToString(brightness.Level()));
|
||||
}
|
||||
|
||||
uint8_t Brightness::LevelToInt(Pinetime::Controllers::BrightnessController::Levels level) {
|
||||
switch(level) {
|
||||
case Pinetime::Controllers::BrightnessController::Levels::Off: return 0;
|
||||
case Pinetime::Controllers::BrightnessController::Levels::Low: return 0;
|
||||
case Pinetime::Controllers::BrightnessController::Levels::Medium: return 1;
|
||||
case Pinetime::Controllers::BrightnessController::Levels::High: return 2;
|
||||
default : return 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <libs/lvgl/src/lv_core/lv_obj.h>
|
||||
#include <Components/Brightness/BrightnessController.h>
|
||||
#include "Screen.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Applications {
|
||||
namespace Screens {
|
||||
class Brightness : public Screen {
|
||||
public:
|
||||
Brightness(DisplayApp* app, Controllers::BrightnessController& brightness);
|
||||
~Brightness() override;
|
||||
bool Refresh() override;
|
||||
bool OnButtonPushed() override;
|
||||
|
||||
void OnValueChanged();
|
||||
private:
|
||||
bool running = true;
|
||||
Controllers::BrightnessController& brightness;
|
||||
|
||||
lv_obj_t * slider_label;
|
||||
lv_obj_t * slider;
|
||||
|
||||
const char* LevelToString(Controllers::BrightnessController::Levels level);
|
||||
uint8_t LevelToInt(Controllers::BrightnessController::Levels level);
|
||||
void SetValue(uint8_t value);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue