Commits

Trammell Hudson committed eb45f41

Reading sunrise/sunset times works

Comments (0)

Files changed (4)

 
 include ../Makefile.rules
 
+# Generate the sunrise table for NYC
+# There is a bug in generate-sunrise if the sun never sets or rises.
+# This needs to be fixed.
+LON	= -77
+LAT	= 41
+
+resources/sunrise.png:
+	perl ./generate-sunrise $(LON) $(LAT) \
+	| convert \
+		-depth 8 \
+		-size 32x16 \
+		rgb:- \
+		$@
 
 # Convert a lunar.gif image to a "compressed" png with the
 # three luma samples converted into rgb format

lunar/generate-sunrise

 #!/opt/local/bin/perl
 # Generate the set of sunrise times for every day of the year
 # for the given latitude.
+#
+# This should handle the far northern or southern values better.
+# Currently bad data will be generated.  I'm sorry to all of you
+# North Pole users!
+#
 use warnings;
 use strict;
 use Astro::Sunrise;
 #include <string.h>
 #include "main.h"
 #include "draw.h"
+#include "image.h"
 #include "sin_table.h"
 
 
+static uint8_t lunar_mode;
 static uint8_t last_sec;
 static PulseResource image_id;
 
 button_down(void)
 {
 	init();
+	lunar_mode = !lunar_mode;
 	last_sec = 0;
 	image_id = 0;
 }
 #endif
 
 
+static inline uint16_t
+ntohs(
+	uint16_t v
+)
+{
+	return (v >> 8) | (v << 8);
+}
+
+
 void
 draw(
 	uint32_t cur_ms
 		return;
 	last_sec = new_sec;
 
-	if (image_id < IMAGE_M000
-	||  image_id >= IMAGE_M346)
-		image_id = IMAGE_M000;
+	if (lunar_mode)
+	{
+		if (image_id < IMAGE_M000
+		||  image_id >= IMAGE_M346)
+			image_id = IMAGE_M000;
 
-	image_draw_gray(image_id, (SCREEN_WIDTH - 81)/2, 0);
-	image_id++;
-	
+		image_draw_gray(image_id, (SCREEN_WIDTH - 81)/2, 0);
+		image_id++;
+		return;
+	}
+
+	// Not in lunar mode; draw the 24-hour face
+	pulse_blank_canvas();
+	static uint8_t month, day;
+	uint16_t sunrise_times[2];
+	uint32_t offset = image_offset(IMAGE_SUNRISE);
+	spiflash_read(
+		offset + (month * 32 + day) * sizeof(sunrise_times),
+		sunrise_times,
+		sizeof(sunrise_times)
+	);
+	printf("%d %d\n%04x\n%04x\n", month+1, day+1, sunrise_times[0], sunrise_times[1]);
+
+	// Scale the sunrise time to screen height
+	uint32_t sunrise = ntohs(sunrise_times[0]);
+	sunrise = (sunrise * VSCREEN_HEIGHT) / (24 * 60);
+	uint32_t sunset = ntohs(sunrise_times[1]);
+	sunset = (sunset * VSCREEN_HEIGHT) / (24 * 60);
+	fill(
+		COLOR_BLUE,
+		VSCREEN_WIDTH/2,
+		sunrise,
+		VSCREEN_WIDTH/2 + (8 << VSCREEN_SHIFT),
+		sunset
+	);
+
+	if (++day == 32)
+	{
+		day = 0;
+		if (++month == 12)
+			month = 0;
+	}
 
 #if 0
 	const uint16_t sec_angle = ((new_sec * 6 + (ms*6) / 1000) * 32768) / 180;

lunar/resources/fonts.txt

 #
 # Example:
 # good_times.ttf, good_times_10, 10, n, n
-#Clockopia.ttf, clockopia_32, 32, y, n
+Clockopia.ttf, clockopia_32, 32, y, n
 #Clockopia.ttf, clockopia_22, 22, y, n