示例#1
0
文件: moo10.c 项目: an-ox/bbc
static void process_tuple(Tuple *t)
{
  // Act upon individual tuples
  switch(t->key)
  {
   case KEY_SECONDS:  // turn second hand off and on
    //if(strcmp(t->value->cstring,"on")==0)
    if(t->value->int32>0) 
    {
      showSeconds=true;
      persist_write_bool(KEY_SECONDS,true);
    }
    else 
    {
      showSeconds=false;
      persist_write_bool(KEY_SECONDS,false);
    }
    app_timer_reschedule(timer,100);
    break;
 case KEY_XCOL:  // turn second hand off and on
    //if(strcmp(t->value->cstring,"on")==0)
    if(t->value->int32>0) 
    {
      exCol=true;
      persist_write_bool(KEY_XCOL,true);
    }
    else 
    {
      exCol=false;
      persist_write_bool(KEY_XCOL,false);
    }
    app_timer_reschedule(timer,100);
    break;    
    case KEY_ERA:  // set style according to approximate BBC era
     if(strcmp(t->value->cstring,"0")==0) displayStyle=STYLE_1970;
     else if(strcmp(t->value->cstring,"1")==0) displayStyle=STYLE_1978;
     else if(strcmp(t->value->cstring,"2")==0) displayStyle=STYLE_1981;
     else if(strcmp(t->value->cstring,"3")==0) displayStyle=STYLE_1953;
     else if(strcmp(t->value->cstring,"4")==0) displayStyle=STYLE_1963;
     else if(strcmp(t->value->cstring,"5")==0) displayStyle=STYLE_1964;
     else if(strcmp(t->value->cstring,"6")==0) displayStyle=STYLE_1966;
     else if(strcmp(t->value->cstring,"7")==0) displayStyle=STYLE_1968;
    else if(strcmp(t->value->cstring,"8")==0) displayStyle=STYLE_1991;
     persist_write_int(KEY_ERA,displayStyle);
     app_timer_reschedule(timer,100);
   break;
  }
}
static void pin_set_handler(ClickRecognizerRef recognizer, void *context) {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Pin set");
  if (hint_layer) {
    text_layer_destroy(hint_layer);
    hint_layer = NULL;
  } 
  else {
    app_timer_reschedule(locationtimer, 1000 * (nextcall + 10));
    strcpy(command, "pin");
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);
    if (iter == NULL) {
      vibes_short_pulse();
      APP_LOG(APP_LOG_LEVEL_WARNING, "Can not send command %s to phone!", command);
      return;
    }
    dict_write_cstring(iter, CMD_KEY, command);
    const uint32_t final_size = dict_write_end(iter);
    app_message_outbox_send();
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Sent command '%s' to phone! (%d bytes)", command, (int) final_size);
    if (!hint_layer) {
      Layer *window_layer = window_get_root_layer(window);
      hint_layer = text_layer_create(hint_layer_size);
      text_layer_set_font(hint_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
      text_layer_set_text_alignment(hint_layer, GTextAlignmentCenter);
      layer_add_child(window_layer, text_layer_get_layer(hint_layer));
    }
    text_layer_set_text(hint_layer, "\nSetting\ntimeline\npin...");
  }
}
static void select_click_callback(MenuLayer *menu_layer, MenuIndex *cell_index, void *callback_context) {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Got a click for row %d", cell_index->row);
  if (hint_layer) {
    text_layer_destroy(hint_layer);
    hint_layer = NULL;
  }
  if (cell_index->row > 0) {
    app_timer_reschedule(locationtimer, 1000 * (nextcall + 10));
    if (cell_index->row == 1) {
      strcpy(command, "set");
    text_layer_set_text(distance_layer, "0");
    } else
      snprintf(command, sizeof(command), "set%d", (cell_index->row)-2);
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);
    if (iter == NULL) {
      vibes_short_pulse();
      APP_LOG(APP_LOG_LEVEL_WARNING, "Can not send command %s to phone!", command);
      return;
    }
    dict_write_cstring(iter, CMD_KEY, command);
    const uint32_t final_size = dict_write_end(iter);
    app_message_outbox_send();
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Sent command '%s' to phone! (%d bytes)", command, (int) final_size);
  }
  window_stack_pop(animated);
}
示例#4
0
static void enable_date(void)
{
  draw_date=true;
  if(!app_timer_reschedule(date_timer,2000))
    date_timer = app_timer_register(2000,disable_date,NULL);
  layer_mark_dirty(window_get_root_layer(window));
}
示例#5
0
/*!
 * Processes the message received from the phone
 *
 * \param iterator the dictionary sent to the pebble
 * \param context unused
 */
void inbox_received_callback(DictionaryIterator *iterator, void *context)
{
    // set the timeout
    if (!(app_timer_reschedule(phone_timer, PHONE_TIMEOUT))) {
        phone_timer = app_timer_register(PHONE_TIMEOUT, phone_timer_callback,
            NULL);
    }

    Tuple* tup = dict_find(iterator, 0);

    if (tup) {
        if (tup->type == TUPLE_UINT) {
            int val = -1;
            switch(tup->length) {
                case 1:
                    val = tup->value->uint8;
                    break;
                case 2:
                    val = tup->value->uint16;
                    break;
                case 4:
                    val = tup->value->uint32;
                    break;
            }
            if (val >= 0 && val < 8) {
                bitmap_layer_set_bitmap(note_layer, notes[val]);
                bitmap_layer_set_alignment(note_layer, GAlignRight);
            } else {
                bitmap_layer_set_bitmap(note_layer, bitmap);
                bitmap_layer_set_alignment(note_layer, GAlignCenter);
            }
        }
    }
}
void select_single_click_handler(ClickRecognizerRef recognizer, void *context) {
	if (game_waiting_for_reaction && game_state == STATE_COUNTDOWN_GO) {
		game_player_reacted = true;
		app_timer_reschedule(game_timer, 1);
	}
	
	if (!game_waiting_for_reaction && game_state <= STATE_COUNTDOWN_GO && game_state > STATE_RESTING) {
		game_state = STATE_COUNTDOWN_GO;
		game_waiting_for_reaction = true;
		game_player_reacted = false;
		app_timer_reschedule(game_timer, 1);
	}
	
	if (game_state == STATE_SPLASH) {
		game_start();
	}
}
示例#7
0
void response_received(){
	if (!timer_load_in_progress_status){
		//app_timer_cancel(timer_response);
		timer_response = app_timer_register(WAIT_RESPONSE, no_message_in_progress, NULL);
		//message_in_progess = -1;
		timer_load_in_progress_status = true;
	}else
		app_timer_reschedule(timer_response, WAIT_RESPONSE);
}
void refresh_temp_click_handler(ClickRecognizerRef recognizer, void* context) {
  
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  // sends a request for the current temperature, using key #0
  Tuplet value = TupletCString(0, "hello?");
  dict_write_tuplet(iter, &value);
  app_message_outbox_send();
 
  // Reschedule the timer to poll for the current temp in 1 second
  app_timer_reschedule(timer, refresh_time);
}
示例#9
0
// Starts or restarts any acive auto-close timer if auto-close is still enabled
static void restart_autoclose_timer() {
  if (s_autoclose_timeout == 0 || s_onoff_mode == MODE_ACTIVE)
    // Stop auto-close if it has been disabled or an alarm is active
    stop_autoclose_timer();
  else {
    // Start or restart auto-close timer (timeout is stored in minutes)
    if (s_autoclose_timer == NULL)
      s_autoclose_timer = app_timer_register(s_autoclose_timeout * 60 * 1000, autoclose_handler, NULL);
    else
      app_timer_reschedule(s_autoclose_timer, s_autoclose_timeout * 60 * 1000); 
  }
}
示例#10
0
文件: main.c 项目: SeaPea/HomeP
// Callback for when the phone JS indicates the status change was sent to the MyQ server
void device_status_change_sent(int device_id) {
  reset_inactivity_timer();
  if (s_device_status_target != DSNone && g_device_id_list[g_device_selected] == device_id) {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Status change sent. Checking for status updates...");
    // Start checking for the status reaching the target 
    // (For garage doors, wait 10 seconds before first check due to how long it take)
    int first_check = (s_device_type == DTLightSwitch) ? 3000 : 10000;
    if (status_change_check_timer != NULL)
      app_timer_reschedule(status_change_check_timer, first_check);
    else
      status_change_check_timer = app_timer_register(first_check, status_change_check, NULL);
  }
}
示例#11
0
文件: main.c 项目: SeaPea/HomeP
// Callback for when user switches between devices
void device_switched() {
  reset_inactivity_timer();
  cancel_status_check();
  cancel_timeout();
  if (status_fetch_delay_timer != NULL) {
    app_timer_cancel(status_fetch_delay_timer);
    status_fetch_delay_timer = NULL;
  }
  // Fetch device details after a brief delay to avoid busy comms error
  if (details_fetch_delay_timer == NULL)
    details_fetch_delay_timer = app_timer_register(500, device_details_fetch_delayed, NULL);
  else
    app_timer_reschedule(details_fetch_delay_timer, 500);
}
示例#12
0
static void initiateScrollTimer(void) {
    bool needToCreateTimer = true;
    nrbyStps_scrollingStillRequired = true;
    nrbyStps_scrollOffset = 0;
    nrbyStps_reloadingToScroll = false;

    if (nrbyStps_scrollTimer) {
        needToCreateTimer = !app_timer_reschedule(nrbyStps_scrollTimer, SCROLL_WAIT);
    }

    if (needToCreateTimer) {
        nrbyStps_scrollTimer = app_timer_register(SCROLL_WAIT, (AppTimerCallback)scroll_menu_callback, NULL);
    }
}
示例#13
0
static void app_timer_battery(void* data) {
    if(battTimer != NULL){
        if(app_timer_reschedule(battTimer, 5000)) {
            app_timer_cancel(battTimer);
        }
        battTimer = NULL;
    }

    char buffer[25];
    memset(buffer, 0, sizeof(buffer));
    snprintf(buffer, sizeof(buffer) - 1, "STRAP_API_BATTERY/%d", battery_state_service_peek().charge_percent);

    strap_log_action(buffer);
    
    battTimer = app_timer_register(curFreq * 5 * 60 * 1000, app_timer_battery,NULL);
}
示例#14
0
文件: main.c 项目: SeaPea/HomeP
// Callback for when device details have been fetched
void device_details_fetched(int device_id, char *location, char *name, DeviceType device_type) {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Details fetched - ID: %d, Location: %s, Name: %s, DeviceType: %d", 
          device_id, location, name, device_type);
  reset_inactivity_timer();
  
  if (g_device_id_list[g_device_selected] == device_id) {
    show_device_details(location, name, device_type);
    s_device_type = device_type;
    s_device_status = DSUpdating;
    show_device_status(DSUpdating, "");
    // Fetch device status after a brief delay to avoid busy comms error
    if (status_fetch_delay_timer == NULL)
      status_fetch_delay_timer = app_timer_register(100, status_fetch_delayed, NULL);
    else
      app_timer_reschedule(status_fetch_delay_timer, 100);
  }
}
示例#15
0
void windowRescheduleTimer(MyWindow *mw, uint32_t update_freq) {
  if (update_freq != (unsigned) -1) {
    time_t sec;
    uint16_t ms;
    time_ms(&sec, &ms);
    uint32_t now = ms + sec * 1000;
    now = now % ms;
    now -= ms;
    // now is now the delay to the next time the timer should go off.
    if (now < MIN_REFRESH_DELAY) {
      now = MIN_REFRESH_DELAY;
    }
    if (mw->appTimer == NULL) {
      mw->appTimer = app_timer_register(now, timer_callback, mw);
    } else {
      app_timer_reschedule(mw->appTimer, now);
    }
  }
}
示例#16
0
static void app_timer_accl_start(void* data) {
    
    if(acclStop != NULL){
        if(app_timer_reschedule(acclStop, 5000)) {
            app_timer_cancel(acclStop);
        }
        acclStop = NULL;
    }
    
    if(acclStart != NULL){
        acclStart = NULL;
    }



    accl_init();
    
    // set timer that will stop reporting accl data after about one minute
    acclStop = app_timer_register(80 * 1000, app_timer_accl_stop,NULL);
}
示例#17
0
static void app_timer_accl_stop(void* data) {

    if(acclStart != NULL){
        if(app_timer_reschedule(acclStart, 5000)) {
            app_timer_cancel(acclStart);
        }
        acclStart = NULL;
    }
    
    if(acclStop != NULL){
        acclStop = NULL;
    }

    // set report flag to false to indicate we want to pause reporting accl data
    report_accl = 0;
    accl_deinit();
    
    // set timer that will start reporting accl data after two minutes
    acclStart = app_timer_register(curFreq * 2 * 60 * 1000, app_timer_accl_start,NULL);
}
示例#18
0
static void level_up() {

  // Up a level

  // Hit the top and had to stop and that's what's bothering me
  if (level == MAX_LEVEL) {
    return;
  }

  // First level - we need a timer to bring us back down
  if (level == 0) {
    level_timer = app_timer_register(LEVEL_WAIT_MS, level_down, NULL);
  } else {
    // If we are already up a level then the timer should be lengthened
    app_timer_reschedule (level_timer, LEVEL_WAIT_MS);
  }

  // Level up
  level++;
  new_timewarp(level);
}
示例#19
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);
  }
}
void in_received_handler(DictionaryIterator *iter, void *context) {
  // incoming message received
  static char unit_text[9];
  static char distance_text[9];
  static char bearing_text[9];
  static char heading_text[9];
  static char speed_text[9];
  static char accuracy_text[12];

  Tuple *bearing_tuple = dict_find(iter, BEARING_KEY);
  if (bearing_tuple) {
    bearing = bearing_tuple->value->int16;
    snprintf(bearing_text, sizeof(bearing_text), "%d", bearing);
    text_layer_set_text(bearing_layer, bearing_text);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Updated bearing to %d", bearing);
    layer_mark_dirty(head_layer);
  }

  Tuple *unit_tuple = dict_find(iter, UNIT_KEY);
  if (unit_tuple) {
    strncpy(unit_text, unit_tuple->value->cstring, sizeof unit_text);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Unit: %s", unit_text);
    text_layer_set_text(unit_layer, unit_text);
  }

  Tuple *distance_tuple = dict_find(iter, DISTANCE_KEY);
  if (distance_tuple) {
    if ((distance_text[0] != '!') && (distance_tuple->value->cstring[0] == '!')) vibes_double_pulse();
    strcpy(distance_text, distance_tuple->value->cstring);
    if (distance_text[0] == '!') {
      text_layer_set_text(distance_layer, &distance_text[1]);
      #ifdef PBL_COLOR
      text_layer_set_text_color(distance_layer, GColorBlue);
      text_layer_set_text_color(unit_layer, GColorBlue);
      #endif
    } else {
      text_layer_set_text(distance_layer, distance_text);
      #ifdef PBL_COLOR
      text_layer_set_text_color(distance_layer, GColorBlack);
      text_layer_set_text_color(unit_layer, GColorBlack);
      #endif
    }
  }
  
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Distance updated: %s %s", distance_text, unit_text);
  
  Tuple *nextcall_tuple = dict_find(iter, NEXTCALL_KEY);
  if (nextcall_tuple) {
    nextcall = nextcall_tuple->value->int32;
    app_timer_reschedule(locationtimer, 1000 * (nextcall + 10));
    APP_LOG(APP_LOG_LEVEL_DEBUG,"Next call is %d.", nextcall);
  }

  Tuple *speed_tuple = dict_find(iter, SPEED_KEY);
  if (speed_tuple) {
    strncpy(speed_text, speed_tuple->value->cstring, sizeof speed_text);
    text_layer_set_text(speed_layer, speed_text);
    APP_LOG(APP_LOG_LEVEL_DEBUG,"Speed is %s.", speed_text);
  }
  
  Tuple *accuracy_tuple = dict_find(iter, ACCURACY_KEY);
  if (accuracy_tuple) {
    strncpy(accuracy_text, accuracy_tuple->value->cstring, sizeof accuracy_text);
    text_layer_set_text(accuracy_layer, accuracy_text);
    APP_LOG(APP_LOG_LEVEL_DEBUG,"Accuracy is %s.", accuracy_text);
  }
  
  Tuple *heading_tuple = dict_find(iter, HEADING_KEY);
  if (heading_tuple) {
    heading = heading_tuple->value->int16;
    if (heading >= 0) {
      snprintf(heading_text, sizeof(heading_text), "%d", heading);
      text_layer_set_text(heading_layer, heading_text);
      if (orientToHeading) {
        text_layer_set_text(star_layer, "^");
        orientation = -TRIG_MAX_ANGLE * heading / 360;
      } else {
        text_layer_set_text(star_layer, "*");
      }
      draw_compass_face();
    } else /* heading <0 (not valid) */ {
      text_layer_set_text(heading_layer, "");
      if (orientToHeading)
        text_layer_set_text(star_layer, "?");
      else
        text_layer_set_text(star_layer, "");
    }
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Updated heading to %d", heading);
  }
  
  Tuple *message_tuple = dict_find(iter, MESSAGE_KEY);
  if (message_tuple && (strlen(message_tuple->value->cstring) > 0)) {    
    if (!hint_layer) {
      Layer *window_layer = window_get_root_layer(window);
      hint_layer = text_layer_create(hint_layer_size);
      text_layer_set_font(hint_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
      text_layer_set_text_alignment(hint_layer, GTextAlignmentCenter);
      layer_add_child(window_layer, text_layer_get_layer(hint_layer));
    }
    strncpy(hint_text, message_tuple->value->cstring, sizeof hint_text);
    text_layer_set_text(hint_layer, hint_text);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Got message: %s", hint_text);
  }

  for (int menuItemNumber=2; menuItemNumber <= MENU_LENGTH; menuItemNumber++) {
    Tuple *location_tuple = dict_find(iter, LOCATION_KEY+menuItemNumber-2);
    APP_LOG(APP_LOG_LEVEL_DEBUG,"Finding location %d.", menuItemNumber);
    if ((location_tuple) && (strlen(location_tuple->value->cstring) > 0)) {
      strncpy(locations[menuItemNumber], location_tuple->value->cstring, sizeof locations[0]);
      last_menu_item = menuItemNumber;
      APP_LOG(APP_LOG_LEVEL_DEBUG,"Got location %d = %s.", menuItemNumber, locations[menuItemNumber]);
    }
  }
#ifdef PBL_SDK_3
  if (pinID_needs_sending)
    pin_action_handler(launch_get_args());
#endif
}
示例#21
0
/*
 * Click a button on a chart and it goes away
 */
static void single_click_handler(ClickRecognizerRef recognizer, void *context) {
  if (chart_showing) {
    app_timer_reschedule(chart_timer, SHORT_RETRY_MS);
  }
}
示例#22
0
文件: main.c 项目: SeaPea/HomeP
// Set/Reset inactivity timer to close app after 2 minutes
void reset_inactivity_timer() {
  if (inactivity_timer == NULL)
    inactivity_timer = app_timer_register(120000, inactivity_timeout, NULL);
  else
    app_timer_reschedule(inactivity_timer, 120000);
}
示例#23
0
void dashboard_update(DictionaryIterator *received){
  Tuple *tuple;
	
	tuple = dict_find(received, CAPTION1_KEY);
	if(tuple) {
    text_layer_set_text(c1_text_layer, tuple->value->cstring);
  }
  else{
    text_layer_set_text(c1_text_layer,"");
  }
  tuple = dict_find(received, VALUE1_KEY);
	if(tuple) {
    text_layer_set_text(v1_text_layer, tuple->value->cstring);
  }
  else{
    text_layer_set_text(v1_text_layer,"");
  }
	tuple = dict_find(received, CAPTION2_KEY);
	if(tuple) {
    text_layer_set_text(c2_text_layer, tuple->value->cstring);
  }
  else{
    text_layer_set_text(c2_text_layer,"");
  }
  tuple = dict_find(received, VALUE2_KEY);
	if(tuple) {
    text_layer_set_text(v2_text_layer, tuple->value->cstring);
  }
  else{
    text_layer_set_text(v2_text_layer,"");
  }
  tuple = dict_find(received, CAPTION3_KEY);
	if(tuple) {
    text_layer_set_text(c3_text_layer, tuple->value->cstring);
  }
  else{
    text_layer_set_text(c3_text_layer,"");
  }
  tuple = dict_find(received, VALUE3_KEY);
	if(tuple) {
    text_layer_set_text(v3_text_layer, tuple->value->cstring);
  }
  else{
    text_layer_set_text(v3_text_layer,"");
  }
  tuple = dict_find(received, MESSAGE_KEY);
	if(tuple && strlen(tuple->value->cstring)>0) {
    text_layer_set_text(m_text_layer, tuple->value->cstring);
    text_layer_set_background_color(m_text_layer,GColorWhite);
    text_layer_set_text_color(m_text_layer,GColorBlack);
  }
  else{
    text_layer_set_text(m_text_layer,"");
    text_layer_set_background_color(m_text_layer,GColorBlack);
  }
  
  if(!app_timer_reschedule(clear_timer,5000)){
    clear_timer = app_timer_register(5000,dashboard_clear,dashboard_window);
  }
  
}