summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e4dfbed)
raw | patch | inline | side by side (parent: e4dfbed)
| author | EricDWertz <EricDWertz@gmail.com> | |
| Wed, 27 Apr 2016 03:06:48 +0000 (23:06 -0400) | ||
| committer | EricDWertz <EricDWertz@gmail.com> | |
| Wed, 27 Apr 2016 03:06:48 +0000 (23:06 -0400) | 
| config.h | patch | blob | history | |
| main.c | patch | blob | history | 
diff --git a/config.h b/config.h
index e97babfa83d72006c046bbe9792edab5e0f98017..31f6a61790f9f4414afb8e8065b4425a319a3984 100644 (file)
--- a/config.h
+++ b/config.h
 #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] =
 {
index ed769f0cb12b9a0046a6f537504f5db1f6586d41..f88aa0231fd271373867c2eb83f5e56192e65ecf 100644 (file)
--- a/main.c
+++ b/main.c
 #include <math.h>
 #include <stdint.h>
 #include <string.h>
+#include <stdio.h>
 #include <curl/curl.h>
 #include <jansson.h>
 time_t time_start;
+double brightness;
+
 struct write_result
 {
     char* data;
 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;
     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 );
     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
     else
         timer_update_astronomy = 0;
+    update_brightness();
     weather_update_timer--;
     if( weather_update_timer < 0 )
