Commits

Trammell Hudson  committed 24d67db

Started on an accelerometer display

  • Participants
  • Parent commits 9b31d0a

Comments (0)

Files changed (2)

File accel/src/Makefile

+#
+# Accelerometer demo
+#
+
+APP := accel
+
+OBJS += accel.o
+
+include ../../Makefile.pebble

File accel/src/accel.c

+/** \file
+ * Show off the 3D accelerometer data.
+ */
+#include "pebble_os.h"
+#include "pebble_app.h"
+#include "pebble_fonts.h"
+
+PBL_APP_INFO(
+	"Accelerometer",
+	"hudson",
+	1, // Version
+	INVALID_RESOURCE,
+	APP_INFO_WATCH_FACE
+);
+
+
+static Window window;
+static TextLayer time_layer;
+static Layer layer;
+
+static void
+bargraph_layer_update(
+	Layer * const me,
+	GContext * ctx
+)
+{
+/*
+	// Draw a white rectangle across the entire bottom
+	const unsigned w = me->bounds.size.w;
+	const unsigned h = me->bounds.size.h;
+	graphics_context_set_fill_color(ctx, GColorWhite);
+	graphics_fill_rect(ctx, GRect(0, 0, w, h), 0, GCornersAll);
+
+	graphics_context_set_fill_color(ctx, GColorBlack);
+	graphics_fill_rect(ctx, GRect(0, 0, (w * remaining) / 30, h), 4, GCornersRight);
+*/
+}
+
+
+static void
+handle_tick(
+	AppContextRef ctx,
+	PebbleTickEvent * const event
+)
+{
+	(void) ctx;
+	const PblTm * const ptm = event->tick_time;
+	static char time_buffer[16];
+
+	string_format_time(
+		time_buffer,
+		sizeof(time_buffer),
+		"%H:%M:%S",
+		ptm
+	);
+	text_layer_set_text(&time_layer, time_buffer);
+}
+
+
+static void
+handle_init(
+	AppContextRef ctx
+)
+{
+	(void) ctx;
+
+	window_init(&window, "Main");
+	window_stack_push(&window, true);
+
+	text_layer_init(&time_layer, GRect(0,0,144,20));
+	text_layer_set_text(&time_layer, "");
+	text_layer_set_font(&time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
+	layer_add_child(&window.layer, &time_layer.layer);
+
+/*
+	// Bargraph layer is across the bottom
+	const unsigned bargraph_height = 20;
+	layer_init(&bargraph_layer, GRect(0,168-bargraph_height-15,144,bargraph_height));
+	bargraph_layer.update_proc = bargraph_layer_update;
+
+	layer_add_child(&window.layer, &bargraph_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);
+}