Source

watches / template / template.c

/** \file
 * Template for an inPulse app
 */
#include <pulse_os.h>
#include <pulse_types.h>
#include <app_resources.h>

static uint32_t not_charging;
static uint8_t shutdown_scheduled;

void
main_app_loop(void)
{
	const uint64_t millis = pulse_get_millis();

        // If the not-charging state has not been toggled in the last
        // 30 seconds, schedule a power down soon.
        if (not_charging && millis - not_charging > 60000)
	{
		if (!shutdown_scheduled)
			pulse_update_power_down_timer(1);
		shutdown_scheduled = 1;
		return;
	}

}


static void
wakeup(void *arg)
{
	pulse_oled_set_brightness(100);
	pulse_blank_canvas();
	not_charging = pulse_get_millis();
	shutdown_scheduled = 0;
	//srand(pulse_get_millis());
}


void
main_app_init(void)
{
	// Register a callback for the woke_from_button event
	pulse_register_callback(
		ACTION_WOKE_FROM_BUTTON,
		&wakeup
	);

	wakeup(0);
}


void
main_app_handle_button_down(void)
{
	last_min = last_sec = -1;
}


void
main_app_handle_button_up(void)
{
}


void
main_app_handle_hardware_update(
	enum PulseHardwareEvent event
)
{
	switch (event)
	{
	case BATTERY_CHARGING:
		// Erase the last non-charging time to avoid flakey power
		not_charging = 0;
		break;

	case BATTERY_NOT_CHARGING:
		// Record the time that the state was toggled.
		not_charging = pulse_get_millis();
		break;

	default:
		break;
	}
}


void
main_app_handle_doz(void)
{
	// Fade out
	for (int i = 100; i >= 0; i -= 6)
	{
		pulse_oled_set_brightness(i);
		pulse_mdelay(60);
	}
}
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.