Commits

Trammell Hudson committed c293e11

Better spacing on the fonts, fill in the background and only draw the main screen once

Comments (0)

Files changed (4)

 	color24_t color,
 	PulseResource font_name,
 	int width,
+	int height,
 	const char * s
 )
 {
 
 	while ((buf[0] = *s++))
 	{
+		if (height != 0)
+			fill(
+				COLOR_BLACK,
+				box.left,
+				box.top,
+				box.left + width - 1,
+				box.top + height - 1
+			);
+
 		pulse_render_text(&box, &font);
 		box.left += width;
 	}
 	color24_t color,
 	PulseResource font,
 	int width,
+	int height, // 0 for no fill, otherwise height to fill in
 	const char * s
 );
 
 #include "sin_table.h"
 
 
-static uint8_t lunar_mode;
 static uint8_t last_sec;
 static PulseResource image_id;
+const uint32_t cx = SCREEN_WIDTH/2;
+const uint32_t cy = 81/2 + 8;
 
-void
-init(void)
-{
-}
+
+// Inspired by http://www.colourlovers.com/palette/1391455/lunar_eclipse
+static const color24_t night_color = { 42, 35, 53 };
+// static const color24_t day_color = { 183, 64, 50 };
+static const color24_t day_color = { 99, 45, 59 };
+static const color24_t date_color = { 65, 34, 52 };
+static const color24_t time_color = { 248, 90, 64 };
 
 
 void
 button_down(void)
 {
 	init();
-	lunar_mode = !lunar_mode;
-	last_sec = 0;
+	last_sec = -1;
 	image_id = 0;
 }
 
 
 
 void
-draw(
-	uint32_t cur_ms
-)
+init(void)
 {
 	struct pulse_time_tm now;
 	pulse_get_time_date(&now);
 
-	if (last_sec == now.tm_sec)
-		return;
-	last_sec = now.tm_sec;
-
-	// Inspired by http://www.colourlovers.com/palette/1391455/lunar_eclipse
-	color24_t night_color = { 42, 35, 53 };
-	//color24_t day_color = { 183, 64, 50 };
-	color24_t day_color = { 99, 45, 59 };
-	color24_t date_color = { 99, 45, 59 };
-	color24_t time_color = { 248, 90, 64 };
-
-	char buf[16];
-	sprintf(buf, "%04d/%02d/%02d",
-		now.tm_year,
-		now.tm_mon,
-		now.tm_mday
-	);
-	draw_monostring(0, SCREEN_HEIGHT - 35,
-		date_color,
-		FONT_CLOCKOPIA_14,
-		9,
-		buf
-	);
-
-	sprintf(buf, "%02d:%02d:%02d",
-		now.tm_hour,
-		now.tm_min,
-		now.tm_sec
-	);
-
-	draw_monostring(0, SCREEN_HEIGHT - 21,
-		time_color,
-		FONT_CLOCKOPIA_20,
-		12,
-		buf
-	);
-
-	static uint8_t day, month;
-
 	//uint32_t phase = moon_phase(now.tm_year, now.tm_mon, now.tm_mday);
-	uint32_t phase = moon_phase(now.tm_year, month, day);
+	uint32_t phase = moon_phase(now.tm_year, now.tm_mon, now.tm_mday);
 	image_id = IMAGE_M000 + phase;
 
-	const uint32_t cx = SCREEN_WIDTH/2;
-	const uint32_t cy = 81/2 + 8;
 	image_draw_gray(image_id, cx - 81/2, cy - 81/2);
 
 	uint16_t sunrise_times[2];
-	uint32_t offset = image_offset(IMAGE_SUNRISE);
+
+	// tm_mon goes from 0 to 11
+	// tm_mday goes from 1 to 31
+	// sunrise times are stored 32/month
+	uint32_t offset = image_offset(IMAGE_SUNRISE)
+		+ (now.tm_mon * 32 + now.tm_mday - 1) * sizeof(sunrise_times);
+
 	spiflash_read(
-		offset + (month * 32 + day) * sizeof(sunrise_times),
+		offset,
 		sunrise_times,
 		sizeof(sunrise_times)
 	);
 		sunset,
 		sunrise + 65536
 	);
+
 	draw_arc(
 		day_color,
 		cx,
 		sunset
 	);
 
-	if (++day == 32)
+	// Draw hours?
+	for (int hour = 0 ; hour < 23 ; hour++)
 	{
-		day = 0;
-		if (++month == 12)
-			month = 0;
 	}
+}
+
+
+void
+draw(
+	uint32_t cur_ms
+)
+{
+	struct pulse_time_tm now;
+	pulse_get_time_date(&now);
+
+	if (last_sec == now.tm_sec)
+		return;
+
+	// Every night at midnight redraw it all
+	// or every time they hit the button
+	if (last_sec == -1
+	||  (now.tm_hour == 0 && now.tm_min == 0 && now.tm_sec == 0))
+		init();
+		
+	last_sec = now.tm_sec;
+
+	// This seems inconsistent sometimes it is full year,
+	// other times it is Unix year.
+	if (now.tm_year < 1900)
+		now.tm_year += 1900;
+
+	char buf[16];
+	sprintf(buf, "%02d", now.tm_hour);
+	draw_monostring(
+		4,
+		SCREEN_HEIGHT - 23,
+		time_color,
+		FONT_CLOCKOPIA_22,
+		12,
+		22,
+		buf
+	);
+
+	sprintf(buf, "%02d", now.tm_min);
+	draw_monostring(
+		36,
+		SCREEN_HEIGHT - 23,
+		time_color,
+		FONT_CLOCKOPIA_22,
+		12,
+		22,
+		buf
+	);
+
+	sprintf(buf, "%02d", now.tm_sec);
+	draw_monostring(
+		68,
+		SCREEN_HEIGHT - 22,
+		time_color,
+		FONT_CLOCKOPIA_22,
+		12,
+		22,
+		buf
+	);
+
+	sprintf(buf, "%04d/%02d/%02d",
+		now.tm_year,
+		now.tm_mon + 1,
+		now.tm_mday
+	);
+	draw_monostring(
+		4,
+		SCREEN_HEIGHT - 36,
+		date_color,
+		FONT_CLOCKOPIA_14,
+		9,
+		14,
+		buf
+	);
 
 }

lunar/resources/fonts.txt

 #
 # Example:
 # good_times.ttf, good_times_10, 10, n, n
-Clockopia.ttf, clockopia_20, 20, y, n
+Clockopia.ttf, clockopia_22, 22, y, n
 Clockopia.ttf, clockopia_14, 14, y, n
+Clockopia.ttf, clockopia_8, 8, y, n