Exemplo n.º 1
0
static void app_message_read_card_payload(DictionaryIterator *dict, int32_t card_index) {
    Tuple *tuple = dict_read_first(dict);
    if (!tuple) {
        APP_LOG(APP_LOG_LEVEL_ERROR, "[CARD %ld] dict_read_first -> NULL", card_index);
        return;
    }

    while (tuple) {
        uint32_t cstr_key = 0;
        uint32_t data_key = 0;
        switch (tuple->key) {
            case KEY_CARD_BALANCE:
                cstr_key = STORAGE_CARD_VALUE(BALANCE, card_index);
                break;
            case KEY_CARD_BARCODE_DATA:
                data_key = STORAGE_CARD_VALUE(BARCODE_DATA, card_index);
                break;
            case KEY_CARD_NAME:
                cstr_key = STORAGE_CARD_VALUE(NAME, card_index);
                break;
        }

        if (cstr_key) {
            persist_write_string(cstr_key, tuple->value->cstring);
        } else if (data_key) {
            persist_write_data(data_key, tuple->value->data, tuple->length);
        }

        tuple = dict_read_next(dict);
    }
}
Exemplo n.º 2
0
static void Process_Received_Data(DictionaryIterator *iter, void *context){
	Tuple *t = dict_read_first(iter);
	 while(t != NULL){
		APP_LOG(APP_LOG_LEVEL_INFO, "something received");
		int key = t->key;
        int value = t->value->int32;
		char string_value[32];
		strcpy(string_value, t->value->cstring);	
		switch (key){
			case WEATHER_TEMPERATURE:
				APP_LOG(APP_LOG_LEVEL_INFO, string_value);
				snprintf(Weather_Buffer, sizeof(Weather_Buffer), "%s", string_value);
				text_layer_set_text(Weather_Text, Weather_Buffer);
				break;
			
			case WEATHER_CONDITIONS:
				gbitmap_destroy(Weather_Bitmap); 
				Weather_Bitmap = gbitmap_create_with_resource(Weather_icons[value]); 
				bitmap_layer_set_bitmap(Weather_Layer, Weather_Bitmap); 
				break;
			
			case SETTINGS_HOURLY_VIBE:
				Settings.Vibe_Hourly = value;
				break;
			
			case SETTINGS_BT_VIBE:
				Settings.Vibe_BT = value;
		}
		 
		 
        t = dict_read_next(iter);
    }	
}
Exemplo n.º 3
0
static void inbox_received_handler(DictionaryIterator *iterator, void *context) {
  // Get the first pair
  Tuple *t = dict_read_first(iterator);

  int key = (int)(t->key / 256);
  int menu_item_section = (int)((t->key % 256) / 16);
  int menu_item = (t->key % 16);
  // Process all pairs present
  while(t != NULL) {
    // Process this pair's key
    switch(key) {
      case KEY_STATUS:
      APP_LOG(APP_LOG_LEVEL_INFO, "STATUS for KEY %d is %d", key, (int)t->value->int32);
        menu_item_statuses[menu_item_section][menu_item] = get_status_text((int)t->value->int32);
        menu_layer_reload_data(s_menu_layer);
        break;
      case KEY_VIBRATE:
        // Trigger vibration
//         text_layer_set_text(s_text_layer, "Vibrate!");
        APP_LOG(APP_LOG_LEVEL_INFO, "Vibrate!");
        vibes_short_pulse();
        break;
      default:
        APP_LOG(APP_LOG_LEVEL_INFO, "Unknown key: %d", (int)t->key);
        break;
    }

    // Get next pair, if any
    t = dict_read_next(iterator);
  }
}
Exemplo n.º 4
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
	
  // Read first item
  Tuple *t = dict_read_first(iterator);

  text_layer_set_text( title_layer, title );
	
  // For all items
  while(t != NULL) {
    // Which key was received?
		APP_LOG(APP_LOG_LEVEL_DEBUG, "Loop index now %s", t->value->cstring);
    switch(t->key) {
    case KEY_ABSTRACT:
          snprintf(abstract, sizeof(abstract), "%s", t->value->cstring);			
      break;
    case KEY_TITLE:
          snprintf(title, sizeof(title), "%s", t->value->cstring);
      break;
    default:
      snprintf( title, sizeof(abstract), "%s", t->value->cstring );
      break;
    }
		text_layer_set_text( word_layer, abstract );// Look for next item
    app_timer_register( (200+10*( strlen(abstract) )), (AppTimerCallback) refresh, NULL);
    
		psleep(500);
    t = dict_read_next(iterator);
  }
  window_stack_pop(true);  
}
Exemplo n.º 5
0
static void in_recv_handler(DictionaryIterator *iterator, void *context)
{
  //Get Tuple
  Tuple *t = dict_read_first(iterator);
  while (t)
  {
    switch(t->key) {
    case KEY_INVERT:
      //It's the KEY_INVERT key
      inverted = (strcmp(t->value->cstring, "si") == 0);
      layer_set_hidden((Layer *)ILFondo, inverted);
 	  persist_write_bool(KEY_INVERT, inverted);
      break;
	  
	case KEY_IDIOMA:
      //It's the KEY_INVERT key
      if(strcmp(t->value->cstring, "1")==0)
      {
        //Set and save as inverted
		idioma=1;  
        persist_write_int(KEY_IDIOMA, 1);
      }
      else if(strcmp(t->value->cstring, "0")==0)
      {
        //Set and save as not inverted
		idioma = 0;
        persist_write_int(KEY_IDIOMA, 0);
      }
      break;
    }
	t = dict_read_next(iterator);
  }
}
Exemplo n.º 6
0
void in_received_handler(DictionaryIterator *iter, void *context) {
    /* get data */
    Tuple *t = dict_read_first(iter);
    while (t) {
        int key = t->key;
        
        char tmp[BUFSIZE] = "";
        strncpy(tmp, t->value->cstring, BUFSIZE);
        
        switch (key) {
            case STR_CHANGE_UP:
                strncpy(str_drink_up, tmp, BUFSIZE);
                text_layer_set_text(text_layer_top, str_drink_up);
                break;
            case STR_CHANGE_SELECT:
                strncpy(str_drink_select, tmp, BUFSIZE);
                text_layer_set_text(text_layer_center, str_drink_select);
                break;
            case STR_CHANGE_DOWN:
                strncpy(str_drink_down, tmp, BUFSIZE);
                text_layer_set_text(text_layer_bottom, str_drink_down);
                break;
        }
        
        /* get even more data */
        t = dict_read_next(iter);
    }
}
Exemplo n.º 7
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
    // Read first item
  Tuple *t = dict_read_first(iterator);
  
  // For all items
  while(t != NULL) {
    // Which key was received?
    switch(t->key) {
    case KEY_LONGITUDE:
      currentlong = TRIG_MAX_ANGLE / 4 + TRIG_MAX_ANGLE * t->value->int32 / 360;
      break;
    case KEY_LATITUDE:
      currentlat = TRIG_MAX_ANGLE / 2 - (TRIG_MAX_ANGLE / 4 - TRIG_MAX_ANGLE  * t->value->int32 / 360);
      break;
    case KEY_TIMEZONE:
      timezone_offset = t->value->int32;
      APP_LOG(APP_LOG_LEVEL_ERROR, "Timezone offset received %d", (int)timezone_offset);
      break;
    default:
      APP_LOG(APP_LOG_LEVEL_ERROR, "Key %d not recognized!", (int)t->key);
      break;
    }

    // Look for next item
    t = dict_read_next(iterator);
  }
}
Exemplo n.º 8
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  // Store incoming information
  static char speed_buffer[8];
  
  // Read first item
  Tuple *t = dict_read_first(iterator);

  // For all items
  while(t != NULL) {
    // Which key was received?
    switch(t->key) {
    case KEY_SPEED:
      snprintf(speed_buffer, sizeof(speed_buffer), "%d", (int)t->value->int32);
      APP_LOG(APP_LOG_LEVEL_INFO, "Speed parsed");
      break;
    default:
      APP_LOG(APP_LOG_LEVEL_ERROR, "Key %d not recognized!", (int)t->key);
      break;
    }

    // Look for next item
    t = dict_read_next(iterator);
  }
  
  APP_LOG(APP_LOG_LEVEL_DEBUG, "%s", speed_buffer);
  //text_layer_set_text(speed_layer, speed_buffer);
  //Window *curWindow = window_stack_get_top_window();
  //TextLayer *speedLayer = text_layer_get_layer(speed_layer);
  
}
Exemplo n.º 9
0
void handle_appmessage_receive(DictionaryIterator *received, void *context) {
  Tuple *tuple = dict_read_first(received);
  while (tuple) {
    switch (tuple->key) {
      case SECONDS_MODE:
        seconds_mode = tuple->value->int32;
        break;
      case BATTERY_MODE:
        battery_mode = tuple->value->int32;
        break;
      case DATE_MODE:
        date_mode = tuple->value->int32;
        break;
      case BLUETOOTH_MODE:
        bluetooth_mode = tuple->value->int32;
        break;
      case GRAPHICS_MODE:
        graphics_mode = tuple->value->int32;
        break;
      case CONNLOST_MODE:
        connlost_mode = tuple->value->int32;
        break;
    }
    tuple = dict_read_next(received);
  }
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Received config");
  has_config = true;
  handle_battery(battery_state_service_peek());
  handle_bluetooth(bluetooth_connection_service_peek());
  handle_inverter();
}
Exemplo n.º 10
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  APP_LOG(APP_LOG_LEVEL_INFO, "Message received!");
  Tuple *t = dict_read_first(iterator);

  // Process all pairs present
  while(t != NULL) {
    // Process this pair's key
    switch (t->key) {
      case KEY_PHONE:
        persist_write_string(PERSIST_KEY_PHONE_NUMBER, t->value->cstring);
        break;
      case KEY_NAME:
        persist_write_string(PERSIST_KEY_NAME, t->value->cstring);
        break;
      case KEY_TIMER:
        persist_write_int(PERSIST_KEY_INTERVAL_TIME, t->value->int32);
        break;
      case KEY_VIBRATE:
        persist_write_int(PERSIST_KEY_BUZZ_TIME, t->value->int32);
        break;
    }

    // Get next pair, if any
    t = dict_read_next(iterator);
  }
}
Exemplo n.º 11
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  // Get the first pair
  Tuple *t = dict_read_first(iterator);

  // Process all pairs present
  while (t != NULL) {
    // Long lived buffer
//     static char s_buffer[64];

    // Process this pair's key
    switch (t->key) {
      case 1:
        // Copy value and display8
//         snprintf(s_buffer, sizeof(s_buffer), "Received '%s'", t->value->cstring);
      circle_layer1 = layer_create(GRect(0, 0, 144, 50));
      
//         text_layer_set_text(s_output_layer, s_buffer);
          layer_set_update_proc(circle_layer1, draw_circle1_update_proc);
           layer_add_child(window_layer, circle_layer1);
        break;
      case 2:
      circle_layer2 = layer_create(GRect(0, 0, 144, 50));
          layer_set_update_proc(circle_layer2, draw_circle2_update_proc); 
          layer_add_child(window_layer, circle_layer2);
      break;
    }

    // Get next pair, if any
    t = dict_read_next(iterator);
  }
}
Exemplo n.º 12
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  Tuple *t = dict_read_first(iterator);
  
  while(t != NULL) {
    switch (t->key) {
      case NUM_MENU_ITEMS:
        s_num_menu_items = t->value->uint16;
        break;
      case POSTS:
      {
        ProcessingState *state = data_processor_create(t->value->cstring, '|');
        uint8_t num_strings = data_processor_count(state);
        s_strings = malloc(sizeof(char*) * num_strings);
        for (uint8_t n = 0; n < num_strings; n += 1) {
          s_strings[n] = data_processor_get_string(state);
        }
        data_processor_destroy(state);
        break;
      }
      case COMMENTS:
        break;
    }
    // Get next pair, if any
    t = dict_read_next(iterator);
  }
  
  layer_mark_dirty(menu_layer_get_layer(s_menu_layer));
}
Exemplo n.º 13
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  static char temperture_buffer[8];
  static char conditions_buffer[32];
  static char weather_layer_buffer[32];
  // First item
  Tuple *t = dict_read_first(iterator);
  
  // Is the latest key NULL after latest iteration?
  while (t != NULL) {
    switch (t->key) {
      case KEY_TEMPERATURE:
      // write outputted format to sized buffer
      snprintf(temperture_buffer, sizeof(temperture_buffer), "%dF", (int)t->value->int32);
      break;
      
      case KEY_CONDITIONS:
      snprintf(conditions_buffer, sizeof(conditions_buffer), "%s", t->value->cstring);
      break;
      
      default:
      APP_LOG(APP_LOG_LEVEL_ERROR, "Unexpected key:%d", (int)t->key);
    }
    
    // Move onto to the next key
    t = dict_read_next(iterator);
  }
  snprintf(weather_layer_buffer, sizeof(weather_layer_buffer), "%s %s", temperture_buffer, conditions_buffer);
  text_layer_set_text(s_weather_layer, weather_layer_buffer);
}
Exemplo n.º 14
0
static void in_recv_handler(DictionaryIterator *iterator, void *context)
{
  //Get Tuple
  Tuple *t = dict_read_first(iterator);
  if(t)
  {
    switch(t->key)
    {
    case KEY_SPEED:
      //It's the KEY_INVERT key
      if(strcmp(t->value->cstring, "on") == 0)
      {
        //Set and save as inverted
        text_layer_set_text_color(text_layer, GColorWhite);
        text_layer_set_background_color(text_layer, GColorBlack);
        text_layer_set_text(text_layer, "Inverted!");
 
        persist_write_bool( KEY_SPEED, true);
      }
      else if(strcmp(t->value->cstring, "off") == 0)
      {
        //Set and save as not inverted
        text_layer_set_text_color(text_layer, GColorBlack);
        text_layer_set_background_color(text_layer, GColorWhite);
        text_layer_set_text(text_layer, "Not inverted!");
 
        persist_write_bool( KEY_SPEED, false);
      }
      break;
    }
  }
}
Exemplo n.º 15
0
static void in_received_handler(DictionaryIterator *iter, void *context) {
  Tuple *tuple = dict_read_first(iter);
  while (tuple) {   
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Pebble received message with key %u", (unsigned)tuple->key);
    switch (tuple->key) {
      case 3:
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Pebble received message requesting value update");
        sendDefaultsToJS();
        return; // don't save values on request  
      case 0:
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Pebble received message with new background value");
        backgroundBlack = tuple->value->int8;
        break;
      case 1:
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Pebble received message with new show day value");
        showDay = tuple->value->int8;
        break;
    }
    tuple = dict_read_next(iter);
  }
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Pebble received message: background=%d, showDay=%d", backgroundBlack, showDay);
  
  // If not MSG_KEY_REQ_VALUES, then really expect both other keys to be present
  setupBackground();
  drawCurrentTime();
  savePersistentValues();
}                
Exemplo n.º 16
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  // Store incoming information
  static char temperature_buffer[8];
  static char conditions_buffer[32];
  static char weather_layer_buffer[32];
  
  // Read first item
  Tuple *t = dict_read_first(iterator);
  
  // For all items
  while(t != NULL) {
    switch(t->key) {
      case KEY_TEMPERATURE:
        snprintf(temperature_buffer, sizeof(temperature_buffer), "%dC", (int)t->value->int32);
        break;
      case KEY_CONDITIONS:
        snprintf(conditions_buffer, sizeof(conditions_buffer), "%s", t->value->cstring);
        break;
      default:
        APP_LOG(APP_LOG_LEVEL_ERROR, "KEY %d not recognized!", (int)t->key);
        break;
    }
    
    // Look for next item
    t = dict_read_next(iterator);
  }
  
  // Assemble the full string and display
  snprintf(weather_layer_buffer, sizeof(weather_layer_buffer), "%s, %s", temperature_buffer, conditions_buffer);
  text_layer_set_text(s_weather_layer, weather_layer_buffer);
}
Exemplo n.º 17
0
/*
static void send(int key, int msg) 
{
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  dict_write_int(iter, key, &msg, sizeof(int), true);
  app_message_outbox_send();
}
*/
static void inbox_received_handler(DictionaryIterator *iterator, void *context) {
  // Get the first pair
  Tuple *t = dict_read_first(iterator);

  // Process all pairs present
  while(t != NULL) {
    // Process this pair's key
    switch(t->key) {
      case KEY_VIBRATE:
        // Trigger vibration
        text_layer_set_text(s_text_layer, "Vibrate!");
        vibes_short_pulse();
        break;
       case KEY_DISTANCE:
        // When distance recieved set text to distance
        text_layer_set_text(s_text_layer,"Distance: ");
        break;
       case KEY_ETA:
        text_layer_set_text(s_text_layer,"ETA:");
        break;
      default:
        APP_LOG(APP_LOG_LEVEL_INFO, "Unknown key: %d", (int)t->key);
        break;
    }

    // Get next pair, if any
    t = dict_read_next(iterator);
  }
}
Exemplo n.º 18
0
bool read_state_data(DictionaryIterator* received, struct Data* d){
	(void)d;
	bool has_data = false;
	Tuple* tuple = dict_read_first(received);
	if(!tuple) return false;
	do {
		switch(tuple->key) {
	  		case TUPLE_MISSED_CALLS:
				d->missed = tuple->value->uint8;
				
				static char temp_calls[5];
				memcpy(temp_calls, itoa(tuple->value->uint8), 4);
				text_layer_set_text(&calls_layer, temp_calls);
				
				has_data = true;
				break;
			case TUPLE_UNREAD_SMS:
				d->unread = tuple->value->uint8;
			
				static char temp_sms[5];
				memcpy(temp_sms, itoa(tuple->value->uint8), 4);
				text_layer_set_text(&sms_layer, temp_sms);
			
				has_data = true;
				break;
		}
	}
	while((tuple = dict_read_next(received)));
	return has_data;
}
Exemplo n.º 19
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  uint32_t *layer_data;
  
  Tuple *t = dict_read_first(iterator);
  while(t != NULL) {
    switch(t->key) {
      case MSG_KEY_TITLE: 
        strncpy(s_title, t->value->cstring, sizeof(s_title));
        text_layer_set_text(s_txt_title, s_title);
        break;
      case MSG_KEY_ARTIST: 
        strncpy(s_artist, t->value->cstring, sizeof(s_artist));
        text_layer_set_text(s_txt_artist, s_artist);
        break;
      case MSG_KEY_VOLUME: 
        layer_data = (uint32_t *)layer_get_data(s_lyr_volume);
    	  *layer_data = t->value->int32;
        layer_mark_dirty(s_lyr_volume);
        break;
      case MSG_KEY_PLAY_STATE: 
        if (t->value->int32 > 0) {
          action_bar_layer_set_icon(s_action_bar, BUTTON_ID_SELECT, s_icon_pause);
        } else {
          action_bar_layer_set_icon(s_action_bar, BUTTON_ID_SELECT, s_icon_play);
        }
        break;
    }

    t = dict_read_next(iterator);
  }
}
Exemplo n.º 20
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  
  APP_LOG(APP_LOG_LEVEL_INFO, "inbox callback success!");
  
  // Read first item
  Tuple *t = dict_read_first(iterator);
 
  // For all items
  while(t != NULL) {
    
    // Get string
    char colorString[strlen(t->value->cstring)+1];
    strcpy(colorString, t->value->cstring);
    const char s[2] = ",";
    char *token;
    int idx;
    
    /* get the first token */
    token = myStrtok(colorString, s);
    
    /* walk through other tokens */
    int count = 0;
    while( token != NULL ) 
    {
      idx = atoi( token );
      settings.colorIdx[count++] = idx;
      token = myStrtok(NULL, s);
    }
 
      // Look for next item
      t = dict_read_next(iterator);
    }
    window_set_background_color(s_main_window, (GColor8)allColors[settings.colorIdx[10]]);
    layer_mark_dirty(window_get_root_layer(s_main_window));
}
Exemplo n.º 21
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context){
  static char temperature_buffer[8];
  static char conditions_buffer[32];
  static char weather_layer_buffer[32];
  
  Tuple *t = dict_read_first(iterator);
  
  while (t != NULL) {
    switch(t->key) {
      case KEY_TEMPERATURE:
        snprintf(temperature_buffer, sizeof(temperature_buffer), "%dC", (int)t->value->int32);
        break;
      case KEY_CONDITIONS:
        snprintf(conditions_buffer, sizeof(conditions_buffer), "%s", t->value->cstring);
        break;
      default:
        APP_LOG(APP_LOG_LEVEL_ERROR, "Key %d not recognised!", (int)t->key);
        break;
    }
    
    t = dict_read_next(iterator);
  }
  
  snprintf(weather_layer_buffer, sizeof(weather_layer_buffer), "%s, %s", temperature_buffer, conditions_buffer);
  text_layer_set_text(s_weather_layer, weather_layer_buffer);
}
static void in_recv_handler(DictionaryIterator *iterator, void *context){
  //Get Tuple
  Tuple *t = dict_read_first(iterator);
  if(t)
  {
    switch(t->key)
    {
    case KEY_BG:
      //strcmp compares binary value of two strings, 0 means the two strings are equal
      if(strcmp(t->value->cstring, "dog") == 0){
        bitmap_layer_set_bitmap(s_bitmap_layer, s_dog_bg);
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Dog selected");
        persist_write_string(KEY_BG, "dog");
      }
      else if(strcmp(t->value->cstring, "cat") == 0){
        bitmap_layer_set_bitmap(s_bitmap_layer, s_cat_bg);
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Cat selected");
        persist_write_string(KEY_BG, "cat");
      }
      else if(strcmp(t->value->cstring, "bird") == 0){
        bitmap_layer_set_bitmap(s_bitmap_layer, s_bird_bg);
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Bird selected");
        persist_write_string(KEY_BG, "bird");
      }
      else{
        APP_LOG(APP_LOG_LEVEL_DEBUG, "You shouldn't see this in the app log. Something went wrong.");
      }
    }
  }
}
Exemplo n.º 23
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
    static bool vibe = true;
    APP_LOG(APP_LOG_LEVEL_INFO, "Message received!");
    // Get the first pair
    Tuple *t = dict_read_first(iterator);

    static char text_buffer[MAX_MESSAGE_LENGTH];
    static char time_buffer[MAX_MESSAGE_LENGTH];
    static char message_buffer[MAX_MESSAGE_LENGTH];
    // Process all pairs present
    while(t != NULL) {
        // Process this pair's key
        switch (t->key) {
            case MESSAGE_TEXT_KEY:
                snprintf(text_buffer, sizeof(text_buffer), "%s", t->value->cstring);
                break;
            case MESSAGE_TIME_KEY:
                snprintf(time_buffer, sizeof(time_buffer), "%s", t->value->cstring);
                break;
        }

        // Get next pair, if any
        t = dict_read_next(iterator);
    }
    schedule(0, text_buffer);
    snprintf(message_buffer, sizeof(message_buffer), "Scheduled '%s' every day @%s ", text_buffer, time_buffer);
    notify(message_buffer, vibe);
}
Exemplo n.º 24
0
void inbox(DictionaryIterator *iter, void *context){
  Tuple *t = dict_read_first(iter);
  if(t) process_tuple(t);
  while(t != NULL){
	t = dict_read_next(iter);
	if(t) process_tuple(t);
  }
	
  if(current == INIT){
	  current = SPLASH;
  }
  else if(current == SPLASH){
	current = HOME;
	window_stack_push(home_window, true);
	window_stack_remove(splash_window, false);
  }
  else if(current == LOADING){
	push_appropriate_window();
  }
  else if(current == MATCHUP){
	//APP_LOG(APP_LOG_LEVEL_INFO, "Old Ally: %d, Old Enemy: %d. Ally: %d, Enemy: %d.", old_matchup_ally_score_int,old_matchup_enemy_score_int,matchup_ally_score_int,matchup_enemy_score_int);
	if( (old_matchup_ally_score_int > old_matchup_enemy_score_int && matchup_ally_score_int < matchup_enemy_score_int)
	 || (old_matchup_ally_score_int < old_matchup_enemy_score_int && matchup_ally_score_int > matchup_enemy_score_int)
	 || (old_matchup_ally_score_int == 0 && old_matchup_enemy_score_int == 0 && (matchup_ally_score_int != 0 || matchup_enemy_score_int != 0)))
	{
		vibes_short_pulse();
	}
	old_matchup_ally_score_int = matchup_ally_score_int;
	old_matchup_enemy_score_int = matchup_enemy_score_int;
	   	  
	layer_mark_dirty(matchup_custom_layer);
  }
}
Exemplo n.º 25
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  static char temperature_buffer[8];
  static char dewpoint_buffer[8];
  static char temperature_layer_buffer[8];
  static char dewpoint_layer_buffer[8];
  Tuple *t = dict_read_first(iterator);
  while (t != NULL) {
    switch (t->key) {
      case KEY_TEMPERATURE:
        snprintf(temperature_buffer, sizeof(temperature_buffer), "%dC", (int)t->value->int32);
        break;
      case KEY_DEWPOINT:
        snprintf(dewpoint_buffer, sizeof(dewpoint_buffer), "%dC", (int)t->value->int32);
        break;
      default:
        APP_LOG(APP_LOG_LEVEL_ERROR, "Key %d not recognised!", (int)t->key);
        break;
    }
    t = dict_read_next(iterator);
  }
  // construct full string, display string
  snprintf(temperature_layer_buffer, sizeof(temperature_layer_buffer), "%s", temperature_buffer);
  text_layer_set_text(temperature_layer, temperature_layer_buffer);
  snprintf(dewpoint_layer_buffer, sizeof(dewpoint_layer_buffer), "%s", dewpoint_buffer);
  text_layer_set_text(dewpoint_layer, dewpoint_layer_buffer);
}
Exemplo n.º 26
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
   //store incoming information
  static char temperature_buffer[8];
  static char conditions_buffer[32];
  
  //read first item
  Tuple *t = dict_read_first(iterator);

  //for all items
  while(t != NULL) {
    // which key was received?
    switch(t->key) {
    case KEY_TEMP:
      snprintf(temperature_buffer, sizeof(temperature_buffer), "%dC", (int)t->value->int32);
      break;
    case KEY_COND:
      snprintf(conditions_buffer, sizeof(conditions_buffer), "%s", t->value->cstring);
      break;
    default:
      APP_LOG(APP_LOG_LEVEL_ERROR, "Key %d not recognized!", (int)t->key);
      break;
    }

    //look for next item
    t = dict_read_next(iterator);
  }
  
  //assemble full string and display
  snprintf(weather_layer_buffer, sizeof(weather_layer_buffer), "%s  %s", temperature_buffer, conditions_buffer);
}
Exemplo n.º 27
0
static void in_recv_handler(DictionaryIterator *iterator, void *context)
{
  //Get Tuple
  Tuple *t = dict_read_first(iterator);
  if(t)
  {
    switch(t->key)
    {
    case KEY_LANG:
      if(strcmp(t->value->cstring, "ru") == 0)
      {
        dow[0]="ВС";
        dow[1]="ПН";
        dow[2]="ВТ";
        dow[3]="СР";
        dow[4]="ЧТ";
        dow[5]="ПТ";
        dow[6]="СБ";
        persist_write_bool(KEY_LANG, true);
      }
      else if(strcmp(t->value->cstring, "en") == 0)
      {
        dow[0]="SU";
        dow[1]="MO";
        dow[2]="TU";
        dow[3]="WE";
        dow[4]="TH";
        dow[5]="FR";
        dow[6]="SA"; 
        persist_write_bool(KEY_LANG, false);
      }
      break;
    }
  }
}
Exemplo n.º 28
0
void netdownload_receive(DictionaryIterator *iter, void *context) {
  NetDownloadContext *ctx = (NetDownloadContext*) context;

  Tuple *tuple = dict_read_first(iter);
  if (!tuple) {
    APP_LOG(APP_LOG_LEVEL_ERROR, "Got a message with no first key! Size of message: %li", (uint32_t)iter->end - (uint32_t)iter->dictionary);
    return;
  }
  switch (tuple->key) {
    case NETDL_DATA:
      if (ctx->index + tuple->length <= ctx->length) {
        memcpy(ctx->data + ctx->index, tuple->value->data, tuple->length);
        ctx->index += tuple->length;
      }
      else {
        APP_LOG(APP_LOG_LEVEL_WARNING, "Not overriding rx buffer. Bufsize=%li BufIndex=%li DataLen=%i",
          ctx->length, ctx->index, tuple->length);
      }
      break;
    case NETDL_BEGIN:
      APP_LOG(APP_LOG_LEVEL_DEBUG, "Start transmission. Size=%lu", tuple->value->uint32);
      if (ctx->data != NULL) {
        free(ctx->data);
      }
      ctx->data = malloc(tuple->value->uint32);
      if (ctx->data != NULL) {
        ctx->length = tuple->value->uint32;
        ctx->index = 0;
      }
      else {
        APP_LOG(APP_LOG_LEVEL_WARNING, "Unable to allocate memory to receive image.");
        ctx->length = 0;
        ctx->index = 0;
      }
      break;
    case NETDL_END:
      if (ctx->data && ctx->length > 0 && ctx->index > 0) {
        NetDownload *image = malloc(sizeof(NetDownload));
        image->data = ctx->data;
        image->length = ctx->length;

        printf("Received file of size=%lu and address=%p", ctx->length, ctx->data);
        ctx->callback(image);

        // We have transfered ownership of this memory to the app. Make sure we dont free it.
        // (see netdownload_destroy for cleanup)
        ctx->data = NULL;
        ctx->index = ctx->length = 0;
      }
      else {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Got End message but we have no image...");
      }
      break;
    default:
      APP_LOG(APP_LOG_LEVEL_WARNING, "Unknown key in dict: %lu", tuple->key);
      break;
  }
}
Exemplo n.º 29
0
 void in_received_handler(DictionaryIterator *received, void *context) {
	int count = 0;
	Tuple *tuple = dict_read_first(received);
	static char* section_title = "Menu title";
	while(tuple){
			count ++;
			if (tuple->key == 0) {
				menu_action = tuple->value->cstring;
			}
			tuple = dict_read_next(received);
	}
	int number_of_entries = count - 1;
	list_menu_items = malloc(number_of_entries * sizeof(SimpleMenuItem));
	int i = 0;
	tuple = dict_read_first(received);
	while (tuple) {
			if(tuple->key != 0){
					list_menu_items[i] = (SimpleMenuItem){
							.title = tuple->value->cstring,
							.callback = select_menu_callback
					};
					i++;
			}
			tuple = dict_read_next(received);
	}
	if  (strcmp(menu_action, "c") == 0) {
			section_title = "Clients";
	} else if(strcmp(menu_action, "t") == 0) {
			section_title = "Tasks";
	} else if (strcmp(menu_action, "p") == 0) {
			section_title = "Projects";
	} else {
			section_title = "Select";
	}
	list_menu_sections[0] = (SimpleMenuSection){
			.title = section_title,
			.num_items = number_of_entries,
			.items = list_menu_items
	};
	window_stack_push(menu_window, true);

	Layer *window_layer = window_get_root_layer(menu_window);
	menu_list_layer = simple_menu_layer_create(GRect(0, 5, 144, 163), menu_window, list_menu_sections, 1, NULL);
	layer_add_child(window_layer, simple_menu_layer_get_layer(menu_list_layer));
 }
Exemplo n.º 30
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  // Read first item
  Tuple *t = dict_read_first(iterator);

	int day = 0;
  int month = 0;
  int year = 0;
  int hour = 0;
  int minutes = 0;

  // For all items
  while(t != NULL) {
    // Which key was received?
    switch(t->key) {
      case KEY_TEMPERATURE:
        snprintf(temperature_buffer, sizeof(temperature_buffer), "%d°C", (int)t->value->int32);
        break;
      case KEY_CONDITIONS:
        snprintf(conditions_buffer, sizeof(conditions_buffer), "%s", t->value->cstring);
        break;
      case KEY_EVENT_NAME:
    		snprintf(event_name_buffer, sizeof(event_name_buffer), "%s", t->value->cstring);
    		text_layer_set_text(s_textlayer_event_title, event_name_buffer);
        break;
      case KEY_EVENT_DAY:
        //12-6-2015 23:55 
     	  day = (int)t->value->int32;
        break;
      case KEY_EVENT_MONTH:
        month = (int)t->value->int32;
        break;
      case KEY_EVENT_YEAR:
        year = (int)t->value->int32;
        break;
      case KEY_EVENT_HOUR:
        hour = (int)t->value->int32;
        break;
      case KEY_EVENT_MINUTE:
        minutes = (int)t->value->int32;
        break;

      default:
        APP_LOG(APP_LOG_LEVEL_ERROR, "Key %d not recognized!", (int)t->key);
        break;
    }

    // Look for next item
    t = dict_read_next(iterator);
  }
  // Assemble full string and display
  snprintf(weather_layer_buffer, sizeof(weather_layer_buffer), "%s, %s", conditions_buffer, temperature_buffer);
  text_layer_set_text(s_weather_layer, weather_layer_buffer);


  handle_event_time(day, month, year, hour, minutes);
}