mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-25 05:33:55 +08:00
add set_brightness in framebuffer.h (#1659)
old-commit-hash: 8ad1135e80
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
#include <GLES2/gl2.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#define BACKLIGHT_CONTROL "/sys/class/leds/lcd-backlight/brightness"
|
||||
#define BACKLIGHT_LEVEL "205"
|
||||
|
||||
using namespace android;
|
||||
@@ -123,14 +122,7 @@ extern "C" FramebufferState* framebuffer_init(
|
||||
|
||||
printf("gl version %s\n", glGetString(GL_VERSION));
|
||||
|
||||
|
||||
// set brightness
|
||||
int brightness_fd = open(BACKLIGHT_CONTROL, O_RDWR);
|
||||
if (brightness_fd != -1){
|
||||
const char brightness_level[] = BACKLIGHT_LEVEL;
|
||||
write(brightness_fd, brightness_level, strlen(brightness_level));
|
||||
close(brightness_fd);
|
||||
}
|
||||
set_brightness(BACKLIGHT_LEVEL);
|
||||
|
||||
if (out_w) *out_w = w;
|
||||
if (out_h) *out_h = h;
|
||||
@@ -143,3 +135,12 @@ extern "C" void framebuffer_swap(FramebufferState *s) {
|
||||
assert(glGetError() == GL_NO_ERROR);
|
||||
}
|
||||
|
||||
extern "C" bool set_brightness(int brightness) {
|
||||
FILE *f = fopen("/sys/class/leds/lcd-backlight/brightness", "wb");
|
||||
if (f != NULL) {
|
||||
fprintf(f, "%d", brightness);
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef FRAMEBUFFER_H
|
||||
#define FRAMEBUFFER_H
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -13,6 +12,7 @@ FramebufferState* framebuffer_init(
|
||||
|
||||
void framebuffer_set_power(FramebufferState *s, int mode);
|
||||
void framebuffer_swap(FramebufferState *s);
|
||||
bool set_brightness(int brightness);
|
||||
|
||||
/* Display power modes */
|
||||
enum {
|
||||
@@ -40,9 +40,6 @@ enum {
|
||||
HWC_POWER_MODE_DOZE_SUSPEND = 3,
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -64,6 +64,8 @@ void framebuffer_swap(FramebufferState *s) {
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
bool set_brightness(int brightness) { return true; }
|
||||
|
||||
void touch_init(TouchState *s) {
|
||||
printf("touch_init\n");
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include "nanovg_gl.h"
|
||||
#include "nanovg_gl_utils.h"
|
||||
|
||||
|
||||
#include "common/framebuffer.h"
|
||||
#include "common/touch.h"
|
||||
|
||||
@@ -25,14 +24,6 @@
|
||||
extern const unsigned char _binary_opensans_regular_ttf_start[];
|
||||
extern const unsigned char _binary_opensans_regular_ttf_end[];
|
||||
|
||||
static void set_brightness(int brightness) {
|
||||
FILE *f = fopen("/sys/class/leds/lcd-backlight/brightness", "wb");
|
||||
if (f != NULL) {
|
||||
fprintf(f, "%d", brightness);
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int err;
|
||||
|
||||
|
||||
@@ -17,13 +17,10 @@
|
||||
#include "common/utilpp.h"
|
||||
#include "ui.hpp"
|
||||
|
||||
static int last_brightness = -1;
|
||||
static void set_brightness(UIState *s, int brightness) {
|
||||
static void ui_set_brightness(UIState *s, int brightness) {
|
||||
static int last_brightness = -1;
|
||||
if (last_brightness != brightness && (s->awake || brightness == 0)) {
|
||||
FILE *f = fopen("/sys/class/leds/lcd-backlight/brightness", "wb");
|
||||
if (f != NULL) {
|
||||
fprintf(f, "%d", brightness);
|
||||
fclose(f);
|
||||
if (set_brightness(brightness)) {
|
||||
last_brightness = brightness;
|
||||
}
|
||||
}
|
||||
@@ -56,7 +53,7 @@ static void set_awake(UIState *s, bool awake) {
|
||||
enable_event_processing(true);
|
||||
} else {
|
||||
LOGW("awake off");
|
||||
set_brightness(s, 0);
|
||||
ui_set_brightness(s, 0);
|
||||
framebuffer_set_power(s->fb, HWC_POWER_MODE_OFF);
|
||||
enable_event_processing(false);
|
||||
}
|
||||
@@ -788,7 +785,7 @@ int main(int argc, char* argv[]) {
|
||||
if (clipped_brightness > 512) clipped_brightness = 512;
|
||||
smooth_brightness = clipped_brightness * 0.01 + smooth_brightness * 0.99;
|
||||
if (smooth_brightness > 255) smooth_brightness = 255;
|
||||
set_brightness(s, (int)smooth_brightness);
|
||||
ui_set_brightness(s, (int)smooth_brightness);
|
||||
|
||||
// resize vision for collapsing sidebar
|
||||
const bool hasSidebar = !s->scene.uilayout_sidebarcollapsed;
|
||||
|
||||
Reference in New Issue
Block a user