Commits

Trammell Hudson committed dec6270

it builds, but does not work yet

Comments (0)

Files changed (4)

mario/src/Makefile

 APP := mario
 
 SRCS += anim.c
+SRCS += main.c
 
 include ../../Makefile.pebble
 // MarioChron: Mario Themed Clock Face
 // Initial work based on InvaderChron by Dataman
 // By: techninja (James T) & Super-Awesome Sylvia
+// Ported to Pebble by Trammell Hudson <hudson@osresearch.net>
 //
 // Originally created for Sylvia's Super-Awesome Mini Maker Show Episode S02E03
 // sylviashow.com/monochron
 
 // == EASILY HACKABLE DEFINES ==================================================
+// MonoChron as 128x64, Pebble as 144x168.
+// Initial version does not change anything
 
 #define GROUND_Y 58    // Ground Position
 
 
 // ^^ EASILY HACKABLE DEFINES ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-#include <avr/io.h>      // this contains all the IO port definitions
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/pgmspace.h>
-#include <avr/eeprom.h>
-#include <avr/wdt.h>
+#include <pebble_os.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <math.h>
 
-#include "util.h"
-#include "ratt.h"
-#include "ks0108.h"
-#include "glcd.h"
 #include "font5x7.h"
 
+typedef uint8_t u08;
+#define GLCD_XPIXELS 128
+#define GLCD_YPIXELS 64
+
+static GContext * ctx;
+
+static inline void
+glcdRectangle(
+	int x,
+	int y,
+	int w,
+	int h
+)
+{
+	graphics_context_set_stroke_color(ctx, GColorBlack);
+	graphics_draw_round_rect(ctx, GRect(x,y,w,h), 0);
+}
+
+static inline void
+glcdFillRectangle(
+	int x,
+	int y,
+	int w,
+	int h,
+	int draw_white
+)
+{
+	graphics_context_set_fill_color(ctx, draw_white ? GColorWhite : GColorBlack);
+	graphics_fill_rect(ctx, GRect(x, y, w, h), 0, GCornerNone);
+}
+
+
+static inline void
+glcdClearDot(
+	int x,
+	int y
+)
+{
+	graphics_context_set_fill_color(ctx, GColorWhite);
+	graphics_draw_pixel(ctx, GPoint(x,y));
+}
+
+static inline void
+glcdSetDot(
+	int x,
+	int y
+)
+{
+	graphics_context_set_fill_color(ctx, GColorBlack);
+	graphics_draw_pixel(ctx, GPoint(x,y));
+}
+
 extern volatile uint8_t time_s, time_m, time_h;
 extern volatile uint8_t old_m, old_h;
 extern volatile uint8_t date_m, date_d, date_y;
 uint16_t crand(uint8_t type) {
   if((type==0)||(type>2))
   {
-    wdt_reset();
+    //wdt_reset();
     encipher();
     return (rval[0]^rval[1])&RAND_MAX;
   } else if (type==1) {
     // Default left and right displays
     left_score = time_h;
     right_score = time_m;
-    if((region == REGION_US)||(region == DOW_REGION_US)) {
+    //if((region == REGION_US)||(region == DOW_REGION_US))
+    if (1) {
       left_score2 = date_m;
       right_score2 = date_d;
     } else {
     }
   }
 
+#if 0
   switch(score_mode) {
   	case SCORE_MODE_DOW:
   	  break;
 	      right_score = old_m;
 	    }
       } else {
+#endif
         left_score = time_h;
         right_score = time_m;
+#if 0
       }
       break;
     case SCORE_MODE_DATE:
       right_score2 = alarm_m;
       break;
   }
+
   if (time_format == TIME_12H && left_score>12) {left_score = left_score % 12;}
+#endif
 }
 
 void initanim(void) {
+#if 0
   DEBUG(putstring("screen width: "));
   DEBUG(uart_putw_dec(GLCD_XPIXELS));
   DEBUG(putstring("\n\rscreen height: "));
   DEBUG(uart_putw_dec(GLCD_YPIXELS));
   DEBUG(putstring_nl(""));
+#endif
 }
 
 void initdisplay(uint8_t inverted) {
   last_score_mode = 99; // ???
   setscore();
 
+#if 0
   // Write "WORLD" in the top left corner
   glcdSetAddress(0,0);
   write_font = 77;
     glcdWriteChar('R', inverted);glcdWriteChar('L', inverted);
     glcdWriteChar('D', inverted);
   write_font = 57;
+#endif
 
   // Add the coin and draw the time
   draw_coin(80, 0);
 
   // TODO: Allow for object overlap without unsetting background pixels
 
+#if 0
   _delay_ms(20); // ~16 FPS (not guaranteeable unless animation payload is measured)
+#endif
 }
 
 void animate_mario(void){
 void WriteTime(uint8_t inverted) {
   write_font = 77;
 
+#if 0
   // Draw Date
   glcdSetAddress(1,1);
   WriteDigits(left_score2,inverted);
   glcdWriteChar('x', inverted);
   WriteDigits(left_score,inverted);
   WriteDigits(right_score,inverted);
+#endif
 
   write_font = 57;
 }
 
 void WriteDigits(uint8_t t, uint8_t inverted)
 {
+#if 0
 	glcdWriteChar(48 + (t/10),inverted);
 	glcdWriteChar(48 + (t%10),inverted);
+#endif
 }
 
 
-void draw(uint8_t inverted) {
+void draw(GContext * gctx)
+{
+   ctx = gctx;
+
   // Animation Loop + delay
   animation_loop();
   setscore();
 
+#if 0
   if (redraw_time){
     redraw_time = 0;
     WriteTime(inverted);
   }
+#endif
   return;
 }
 
 
-static unsigned char __attribute__ ((progmem)) MonthText[] = {
+static unsigned char MonthText[] = {
 	0,0,0,
 	'J','A','N',
 	'F','E','B',
 	'D','E','C',
 };
 
-static unsigned char __attribute__ ((progmem)) DOWText[] = {
+static unsigned char DOWText[] = {
 	'S','U','N',
 	'M','O','N',
 	'T','U','E',
     }
     return (day + (2 * month) + (6 * (month+1)/10) + year + (year/4) - (year/100) + (year/400) + 1) % 7;
 }
-
-
-
-
-
-

mario/src/font5x7.h

 
 // standard ascii 5x7 font
 // defines ascii characters 0x20-0x7F (32-127)
-static unsigned char __attribute__ ((progmem)) Font5x7[] = {
+static unsigned char Font5x7[] = {
 	0x00, 0x00, 0x00, 0x00, 0x00,// (space)
 	0x00, 0x00, 0x5F, 0x00, 0x00,// !
 	0x00, 0x07, 0x00, 0x07, 0x00,// "
+/* ***************************************************************************
+// This code is distributed under the GNU Public License
+//		which can be found at http://www.gnu.org/licenses/gpl.txt
+//
+**************************************************************************** */
+
+// MarioChron: Mario Themed Clock Face
+// Initial work based on InvaderChron by Dataman
+// By: techninja (James T) & Super-Awesome Sylvia
+// Ported to Pebble by Trammell Hudson <hudson@osresearch.net>
+//
+// Originally created for Sylvia's Super-Awesome Mini Maker Show Episode S02E03
+// sylviashow.com/monochron
+
+#include <pebble_os.h>
+#include <pebble_app.h>
+#include <pebble_fonts.h>
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <math.h>
+
+PBL_APP_INFO(
+	"MarioChron",
+	"hudson",
+	1, // Version
+	INVALID_RESOURCE,
+	APP_INFO_WATCH_FACE
+);
+
+
+volatile uint8_t time_s, time_m, time_h;
+volatile uint8_t old_m, old_h;
+volatile uint8_t date_m, date_d, date_y;
+volatile uint8_t alarming, alarm_h, alarm_m;
+volatile uint8_t time_format;
+volatile uint8_t region;
+volatile uint8_t score_mode;
+volatile uint8_t write_font;
+
+volatile uint8_t minute_changed, hour_changed;
+
+
+
+static Window window;
+static Layer layer;
+
+static void
+layer_update(
+	Layer * const me,
+	GContext * ctx
+)
+{
+	draw(ctx);
+}
+
+
+static void
+handle_tick(
+	AppContextRef ctx,
+	PebbleTickEvent * const event
+)
+{
+	(void) ctx;
+	const PblTm * const ptm = event->tick_time;
+
+	time_s = ptm->tm_sec;
+	time_m = ptm->tm_min;
+	time_h = ptm->tm_hour;
+	date_m = ptm->tm_mon + 1;
+	date_d = ptm->tm_mday;
+	date_y = ptm->tm_year;
+
+	layer_mark_dirty(&layer);
+}
+
+
+static void
+handle_init(
+	AppContextRef ctx
+)
+{
+	(void) ctx;
+
+	window_init(&window, "MarioChron");
+	window_stack_push(&window, true);
+
+	// Mario Layer
+	layer_init(&layer, GRect(0,0, 128, 64));
+	layer.update_proc = layer_update;
+	layer_add_child(&window.layer, &layer);
+}
+
+
+void
+pbl_main(
+	void * const params
+)
+{
+	PebbleAppHandlers handlers = {
+		.init_handler	= &handle_init,
+		.tick_info	= {
+			.tick_handler = &handle_tick,
+			.tick_units = SECOND_UNIT,
+		},
+	};
+
+	app_event_loop(params, &handlers);
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.