]> Eric's Git Repo - deskclocky.git/commitdiff
Initial brightness support master
authorEricDWertz <EricDWertz@gmail.com>
Wed, 27 Apr 2016 03:06:48 +0000 (23:06 -0400)
committerEricDWertz <EricDWertz@gmail.com>
Wed, 27 Apr 2016 03:06:48 +0000 (23:06 -0400)
config.h
main.c

index e97babfa83d72006c046bbe9792edab5e0f98017..31f6a61790f9f4414afb8e8065b4425a319a3984 100644 (file)
--- 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 ed769f0cb12b9a0046a6f537504f5db1f6586d41..f88aa0231fd271373867c2eb83f5e56192e65ecf 100644 (file)
--- a/main.c
+++ b/main.c
@@ -4,6 +4,7 @@
 #include <math.h>
 #include <stdint.h>
 #include <string.h>
+#include <stdio.h>
 
 #include <curl/curl.h>
 #include <jansson.h>
@@ -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 )