From df7349759247e5929341d77836983580a736eb26 Mon Sep 17 00:00:00 2001 From: EricDWertz Date: Tue, 26 Apr 2016 23:06:48 -0400 Subject: [PATCH] Initial brightness support --- config.h | 3 +++ main.c | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/config.h b/config.h index e97babf..31f6a61 100644 --- a/config.h +++ b/config.h @@ -15,6 +15,9 @@ #define WEATHER_REFRESH_TIMEOUT 600 #define DEBUG_TIMESCALE 0 +#define DEBUG_BRIGHTNESS 1 + +#define LIGHTSENSOR_FILE "/sys/buf/i2c/drivers//al3010/2-001c/show_revised_lux" char* weekday_names[7] = { diff --git a/main.c b/main.c index ed769f0..f88aa02 100644 --- a/main.c +++ b/main.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -22,6 +23,8 @@ int tick = 0; time_t time_start; +double brightness; + struct write_result { char* data; @@ -57,6 +60,24 @@ struct tm * timeinfo_previous; int timer_update_astronomy = 0; int timer_update_weather = 1; +void update_brightness() +{ + if( DEBUG_BRIGHTNESS ) + { + brightness = fabs( sin( timeinfo->tm_sec / 10.0 ) ); + } + else + { + char buffer[16]; + FILE* f = fopen( LIGHTSENSOR_FILE, "r" ); + fgets( buffer, 16, f ); + fclose( f ); + + brightness = atof( buffer ) / 120; + brightness = fmin( brightness, 1.0 ); + } +} + static size_t write_curl_response( void* ptr, size_t size, size_t nmemb, void* stream ) { struct write_result *result = (struct write_result *)stream; @@ -640,6 +661,8 @@ void draw_timestring( cairo_t* cr ) double text_x, text_y; double time_width = 0; + cairo_set_source_rgba( cr, 0.0, 0.0, 0.0, (1.0 - brightness) * 0.95 ); + cairo_paint( cr ); cairo_t* tempcr = cairo_create( temp_surface ); cairo_set_operator( tempcr, CAIRO_OPERATOR_SOURCE ); @@ -651,6 +674,7 @@ void draw_timestring( cairo_t* cr ) cairo_set_source_surface( cr, temp_surface, 0, 0 ); cairo_paint( cr ); + /* * This part draws the background rectangles * TODO: make it so the shade rectangles are drawn on their own surface then overlayed on the background pixbuf @@ -757,6 +781,7 @@ gboolean refresh_clock(gpointer data) else timer_update_astronomy = 0; + update_brightness(); weather_update_timer--; if( weather_update_timer < 0 ) -- 2.47.0