Ejemplo n.º 1
0
void handle_accel(AccelData *data, uint32_t num_samples) {
    static bool watch_outside_range = true;

    if (data->x < X_RANGE_HIGH && data->x > X_RANGE_LOW &&
        data->y > Y_RANGE_LOW && data->y < Y_RANGE_HIGH) {

        if (light_on == false && watch_level_start == 0 && watch_outside_range) {
    	    watch_level_start = time(0L);
    	    watch_outside_range = false;
    	}
    } else if ((data->x > (X_RANGE_HIGH + 50) || data->x < (X_RANGE_LOW - 50)) ||
               (data->y < (Y_RANGE_LOW - 100) || data->y > (Y_RANGE_HIGH + 100))) {

        watch_level_start = 0;
    	watch_outside_range = true;
    }

    if (watch_level_start != 0 && (time(0L) - watch_level_start) > 0) {
    	light_enable(true);
        // light_enable_interaction();
    	light_on = true;
    	app_timer_register(2000, light_callback, NULL);
    	watch_level_start = 0;
    }
}
static void second_tick(void)
{
    elapsedTime++;

    if (appIdle && config_timeout > 0 && config_timeout < elapsedTime && main_noMenu)
    {
        window_stack_pop(true);
        return;
    }

    if (lightOn && elapsedTime >= config_lightTimeout)
    {
        lightOn = false;
        light_enable(false);
    }

    if (periodicVibrationPeriod > 0 &&
        appIdle &&
        elapsedTime > 0 && elapsedTime % periodicVibrationPeriod == 0 &&
        !nw_get_displayed_notification()->inList &&
        canVibrate() &&
        (config_periodicTimeout == 0 || elapsedTime < config_periodicTimeout))
    {
        VibePattern pat = {
                .durations = config_periodicVibrationPattern,
                .num_segments = config_periodicVibrationPatternSize / 2,
        };

        nw_vibrate(&pat, config_periodicVibrationTotalDuration);
    }

    nw_ui_update_statusbar_clock();
}
Ejemplo n.º 3
0
static void window_load(Window *window){
	#ifdef PBL_SDK_2
    	window_set_background_color(window, GColorWhite);
	#endif

    light_enable(true);
    is_light_on = true;
    is_bg_white = true;
}
Ejemplo n.º 4
0
void notify(const char *message,
            GBitmap *icon) {

    bitmap_layer_set_bitmap(warn_layer, (icon == 0 ? tick : icon));
    text_layer_set_text(warn_text_layer, message);
    layer_set_hidden(bitmap_layer_get_layer(warn_layer), false);
    vibes_long_pulse();
    light_enable(true);
    app_timer_register(WARNING_TIMEOUT, clear_warning, 0);
}
Ejemplo n.º 5
0
void toggle_light() {
	if(is_light_on) {
		light_enable(false);
        tick_timer_service_unsubscribe();
        is_light_on = false;
	} else {
		tick_timer_service_subscribe(SECOND_UNIT, tick_handler);
		is_light_on = true;
    }
}
Ejemplo n.º 6
0
void shake_handler(AccelAxisType axis, int32_t direction){
  static AppTimer* timer = NULL;
  int light_time = get_light_time();
  light_enable(true);
  if(timer == NULL){
    timer = app_timer_register(1000*light_time, light_off, NULL);
  }
  else{
    app_timer_cancel(timer);
    timer = app_timer_register(1000*light_time, light_off, NULL);
  }  
  set_text_title("Light!");
}
Ejemplo n.º 7
0
void init_Interrupts(void){

    // Setup Interrupt for Light Sensor
    light_setRange(LIGHT_RANGE_4000); // sensing up to 3892 lux
    light_setIrqInCycles(LIGHT_CYCLE_1);
    light_clearIrqStatus();
    light_enable();

    // Determine initial light conditions
    uint32_t initial_light_value = light_read();
    if (initial_light_value > LIGHTNING_THRESHOLD) {
    	// Initialize interrupt to trigger on falling below threshold
    	aboveThreshold = 1;
    	light_setLoThreshold(LIGHTNING_THRESHOLD);
    	light_setHiThreshold(RANGE_K2-1); // disable high threshold
    } else {
        // Initialize interrupt to trigger on exceeding threshold
    	aboveThreshold = 0;
        light_setHiThreshold(LIGHTNING_THRESHOLD);
        light_setLoThreshold(0); // disable low threshold
    }

    // clear interrupts before enabling
    LPC_GPIOINT->IO2IntClr = 1 << 5;
    LPC_GPIOINT->IO2IntClr = 1 << 10;
    LPC_GPIOINT->IO0IntClr = 1 << 24;
    LPC_GPIOINT->IO0IntClr = 1 << 25;
    LPC_GPIOINT->IO0IntClr = 1 << 17;
    LPC_GPIOINT->IO0IntClr = 1 << 15;
    LPC_GPIOINT->IO0IntClr = 1 << 16;
    LPC_GPIOINT->IO2IntClr = 1 << 3;
    LPC_GPIOINT->IO2IntClr = 1 << 4;

    LPC_GPIOINT->IO2IntEnF |= 1 << 5; // light sensor 3000 lux interrupt (P2.5)
    LPC_GPIOINT->IO2IntEnF |= 1 << 10; // SW3 (P2.10)
    LPC_GPIOINT->IO0IntEnF |= 1 << 24; // rotary switch right
    LPC_GPIOINT->IO0IntEnF |= 1 << 25; // rotary switch left
    // joystick
    LPC_GPIOINT->IO0IntEnF |= 1 << 17; // center
    LPC_GPIOINT->IO0IntEnF |= 1 << 15; // down
    LPC_GPIOINT->IO0IntEnF |= 1 << 16; // right
    LPC_GPIOINT->IO2IntEnF |= 1 << 3; // up
    LPC_GPIOINT->IO2IntEnF |= 1 << 4; // left

	enableTimer(RGB, 1000); // RGB will blink throughout operation at 1000ms interval
	enableTimer(SAMPLING, 2000);
	enableTimer(PCA9532, 250);
}
Ejemplo n.º 8
0
void handle_init(void) {
  my_window = window_create();

  text_layer = text_layer_create(GRect(0, 0, 144, 60));
  Layer *layer = window_get_root_layer(my_window);
  layer_add_child(layer, text_layer_get_layer(text_layer));
  text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
  text_layer_set_background_color(text_layer, GColorClear);
  layer_set_update_proc(layer, layer_on_update);
  
  window_stack_push(my_window, true);
  
  setInitValues();
  
  accel_data_service_subscribe(1, data_handler);
  
  light_enable(true);
}
Ejemplo n.º 9
0
static void handle_init(void) {
    show_friends_window();
    
    //leak 516 B
    #ifndef PBL_PLATFORM_APLITE
    prepare_dictation();
    #endif
    
    app_message_register_inbox_received(in_received_handler);
    app_message_register_inbox_dropped(in_dropped_handler);
    app_message_register_outbox_sent(out_sent_handler);
    app_message_register_outbox_failed(out_failed_handler);
    //leak 740 B
    app_message_open(512, 128);
    
    bluetooth_connection_service_subscribe(bluetooth_connection_callback);
    
    startCheckFriendsTimer();
    
    light_enable(true);
}
Ejemplo n.º 10
0
static void init() {
  setlocale(LC_ALL, "");

  if(FORCE_BACKLIGHT) {
    light_enable(true);
  }

  // init weather system
  Weather_init();

  // init settings
  Settings_init();

  // init the messaging thing
  messaging_init(forceScreenRedraw);

  // Create main Window element and assign to pointer
  mainWindow = window_create();

  // Set handlers to manage the elements inside the Window
  window_set_window_handlers(mainWindow, (WindowHandlers) {
    .load = main_window_load,
    .unload = main_window_unload
  });
Ejemplo n.º 11
0
static void tick_handler(struct tm *t, TimeUnits units_changed){
	light_enable(true);
    handle_battery(battery_state_service_peek());
}
Ejemplo n.º 12
0
static void window_unload(Window *window){
    light_enable(false);
    is_light_on = false;
}
Ejemplo n.º 13
0
void light_off(void* data){
  set_text_title("CleanWeather");
  light_enable(false);
}
Ejemplo n.º 14
0
//lights up the screen briefly
static void lightup() {
  light_enable(TRUE);
  if(!app_timer_reschedule(lighttimer, lightdelay)) {
    lighttimer = app_timer_register(lightdelay, godark, NULL);
  }
}
Ejemplo n.º 15
0
static void handle_window_unload(Window* window) {
  if (get_backlight_on())
    light_enable(false);
  
  destroy_ui();
}
Ejemplo n.º 16
0
static void clear_warning(void *data) {

    light_enable(false);
    layer_set_hidden(bitmap_layer_get_layer(warn_layer), true);
}
Ejemplo n.º 17
0
static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
  // Toggle light
  s_light_on = !s_light_on;
  light_enable(s_light_on);
}
Ejemplo n.º 18
0
void light_callback (void *data) {
    light_on = false;
    light_enable(false);
}
Ejemplo n.º 19
0
static void timeHandler(void *data) {
	static BatteryChargeState charge;
	
	step++;
	switch (step) {
		case 1:
			APP_LOG(APP_LOG_LEVEL_DEBUG, "timeHandler: backlight=%d", backlight);
			
			if (backlight) {
				light_enable(true);
			}

			// Show hour
			clock_copy_time_string(info, 20);
			centerTextLayer(info);
			layer_set_hidden(text_layer_get_layer(textLayer), false);
			app_timer_register(INFO_DURATION, timeHandler, NULL);
			break;

		case 2:
			// Show Date
			centerTextLayer(date);
			app_timer_register(INFO_DURATION, timeHandler, NULL);
			break;
			
		case 3:
			// Show Phone connection status
			if (bluetooth_connection_service_peek()) {
				strcpy(info, "phone ok");
			} else {
				strcpy(info, "phone failed");
			}
			centerTextLayer(info);
			app_timer_register(INFO_DURATION, timeHandler, NULL);
			break;

		case 4:
			// Show battery percentage
			charge = battery_state_service_peek();
			snprintf(info, 10, "batt %d%%", (int)charge.charge_percent);
			centerTextLayer(info);
			app_timer_register(INFO_DURATION, timeHandler, NULL);
			break;
			
		case 5:
			// Hide textLayer, reset it to Date
			if (backlight) {
				light_enable(false);
			}
			layer_set_hidden(text_layer_get_layer(textLayer), true);
			centerTextLayer(date);
			step = 0;
			break;
			
		case 101:
			// Display config saved message
			if (backlight) {
				light_enable(true);
			}
			strcpy(info, "config saved");
			centerTextLayer(info);
			layer_set_hidden(text_layer_get_layer(textLayer), false);
			app_timer_register(INFO_LONG_DURATION, timeHandler, NULL);
			break;
			
		case 102:
			// Hide textLayer, reset it to Date
			if (backlight) {
				light_enable(false);
			}

			layer_set_hidden(text_layer_get_layer(textLayer), true);
			centerTextLayer(date);
			step = 0;
			break;
	}
}
Ejemplo n.º 20
0
void select_single_click_handler(ClickRecognizerRef recognizer, Window *window) {
  (void)recognizer;
  (void)window;
  light = !light;
  light_enable(light);
}
Ejemplo n.º 21
0
static void godark(void* data) {
  light_enable(FALSE);
}