Esempio n. 1
0
static struct tm build_prayer_time_next(int year, int month, int day, DictionaryIterator *iterator) {  
  Tuple *hour_tuple = dict_read_next(iterator);
  Tuple *minute_tuple = dict_read_next(iterator);
  time_t temp = time(NULL);  
  struct tm *prayer_time = localtime(&temp);    
  prayer_time->tm_year = year;
  prayer_time->tm_mon = month;
  prayer_time->tm_mday = day;  
  prayer_time->tm_hour = (int)hour_tuple->value->int32;
  prayer_time->tm_min = (int)minute_tuple->value->int32;
  prayer_time->tm_sec = 0;  
  return *prayer_time;
}
Esempio n. 2
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {

  APP_LOG(APP_LOG_LEVEL_INFO, "Received info from JS");
  
  // date components
  Tuple *date_year_tuple = dict_read_first(iterator);  
  Tuple *date_month_tuple = dict_read_next(iterator);
  Tuple *date_day_tuple = dict_read_next(iterator);
  
  int year = (int)date_year_tuple->value->int32;
  int month = (int)date_month_tuple->value->int32;
  int day = (int)date_day_tuple->value->int32;
    
  char str_ymd[32];
  snprintf(str_ymd, sizeof(str_ymd), "h-m-hs -- %i:%i:%i", year, month, day); 
  APP_LOG(APP_LOG_LEVEL_DEBUG, str_ymd);  
  
  s_fajr = build_prayer_time_next(year, month, day, iterator);  
  s_shurooq = build_prayer_time_next(year, month, day, iterator);
  s_dhuhr = build_prayer_time_next(year, month, day, iterator);
  s_asr = build_prayer_time_next(year, month, day, iterator);  
  s_maghrib = build_prayer_time_next(year, month, day, iterator);
  s_isha = build_prayer_time_next(year, month, day, iterator);  
  
  s_has_prayer_times = 1;  

  strftime(str_fajr, sizeof(str_fajr), "%H:%M", &s_fajr);  
  APP_LOG(APP_LOG_LEVEL_DEBUG, str_fajr);
  text_layer_set_text(s_fajr_layer, str_fajr);

  strftime(str_shurooq, sizeof(str_shurooq), "%H:%M", &s_shurooq); 
  APP_LOG(APP_LOG_LEVEL_DEBUG, str_shurooq);
  text_layer_set_text(s_shurooq_layer, str_shurooq);  
  
  strftime(str_dhuhr, sizeof(str_dhuhr), "%H:%M", &s_dhuhr); 
  APP_LOG(APP_LOG_LEVEL_DEBUG, str_dhuhr);  
  text_layer_set_text(s_dhuhr_layer, str_dhuhr);
  
  strftime(str_asr, sizeof(str_asr), "%H:%M", &s_asr); 
  APP_LOG(APP_LOG_LEVEL_DEBUG, str_asr);
  text_layer_set_text(s_asr_layer, str_asr);  

  strftime(str_maghrib, sizeof(str_maghrib), "%H:%M", &s_maghrib); 
  APP_LOG(APP_LOG_LEVEL_DEBUG, str_maghrib); 
  text_layer_set_text(s_maghrib_layer, str_maghrib);     
  
  strftime(str_isha, sizeof(str_isha), "%H:%M", &s_isha);  
  APP_LOG(APP_LOG_LEVEL_DEBUG, str_isha);
  text_layer_set_text(s_isha_layer, str_isha);  
}
Esempio n. 3
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);
}
Esempio n. 4
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);
    }
}
Esempio n. 5
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);
}
Esempio n. 6
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;
}
Esempio n. 7
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));
}
Esempio n. 8
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 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);
}
Esempio n. 10
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);
  }
}
Esempio n. 11
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);
  }
}
Esempio n. 12
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);
    }
}
Esempio n. 13
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);
    }	
}
Esempio n. 14
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);
  }
}
Esempio n. 15
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);  
}
Esempio n. 16
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);
}
Esempio n. 17
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);
  }
}
Esempio n. 18
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);
  }
}
Esempio n. 19
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();
}
Esempio n. 20
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);
  }
}
Esempio n. 21
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);
  
}
Esempio n. 22
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);
  }
}
Esempio n. 23
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));
}
Esempio n. 24
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();
}                
Esempio 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);
}
Esempio n. 26
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);
  }
}
Esempio n. 27
0
static void appMessageInboxReceived(DictionaryIterator *iterator, void *context) {
  Tuple *completeTuple = dict_find(iterator, MESSAGE_KEY_complete);
  Tuple *countTuple = dict_find(iterator, MESSAGE_KEY_count);

  if (completeTuple){
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Completed receiving stories, time to display them.");
  } else if (countTuple) {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Allocating stories array[%d]", countTuple->value->uint8);
    stories = malloc(countTuple->value->uint8 * sizeof(struct Story *));
  } else {
    if (stories == NULL) {
      APP_LOG(APP_LOG_LEVEL_ERROR, "Received a story without first receiving the count!");
      return;
    }
    Tuple *tuple;
    // int id;
    // int state;
    // int type;
    // char* name;

    while((tuple = dict_read_next(iterator))) {
      if (tuple->key == MESSAGE_KEY_id) {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Received an ID %d", tuple->value->uint8);
        // id = tuple->value->uint8;
      } else if (tuple->key == MESSAGE_KEY_name) {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Received a name %s", tuple->value->cstring);
      } else if (tuple->key == MESSAGE_KEY_state) {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Received a state %d", tuple->value->uint8);
      } else if (tuple->key == MESSAGE_KEY_type) {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Received a type %d", tuple->value->uint8);
      }
    }
  }
}
Esempio n. 28
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));
 }
Esempio n. 29
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);
}
Esempio n. 30
0
Tuple *dict_find(const DictionaryIterator *iter, const uint32_t key) {
    Tuple* tuple = dict_read_first((DictionaryIterator*)iter);
    while (tuple) {
        if (tuple->key == key)
            return tuple;

        tuple = dict_read_next((DictionaryIterator*)iter);
    }
    return tuple;
}