Esempio n. 1
0
static void get_contact() {
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  dict_write_cstring(iter, DICTATED_NAME_KEY, dictated_name);
  dict_write_int(iter, STATE_KEY, &s_state, 1, 0);
  dict_write_int(iter, ATTEMPT_NUMBER_KEY, &contact_try, 1, 0);
  app_message_outbox_send();
}
Esempio n. 2
0
// Write message to buffer & send 
void send_values(int x, int y, int z){
  
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  dict_write_int(iter,XVALUE_KEY,&x,sizeof(int),true);
  dict_write_int(iter,YVALUE_KEY,&y,sizeof(int),true);
  dict_write_int(iter,ZVALUE_KEY,&z,sizeof(int),true);
  dict_write_end(iter);
  app_message_outbox_send();
  APP_LOG(APP_LOG_LEVEL_DEBUG, "**WATCH**: A message has been sent from pebble to the phone");
}
void pbl_capture_send() {
	struct GContext *gctx = app_get_current_graphics_context();
	unsigned char *ptr = (unsigned char *)(*gctx->ptr);
	int pbl_capture_sentLen = 0;

	DictionaryResult ret;
	DictionaryIterator imgChunk;
	uint8_t buff[MAX_OUT_MESSAGE_SIZE];

	int len = 0;

	for (int y=0; y<168; y++) {
		for (int x=0; x<18; x++) {
			http_capture_frameBuffer[len++] = *ptr++;
		}
		ptr++; ptr++;
	}

	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);

	while (pbl_capture_sentLen < IMAGE_SIZE)
	{
		DictionaryResult res = dict_write_begin(&imgChunk, buff, MAX_OUT_MESSAGE_SIZE);
		if (res != DICT_OK)
		{
			return;
		}
		uint8_t msg =  mMT_SendImage;
		ret = dict_write_int(&imgChunk, KEY_COMMAND, &msg, 1, false);
		if (DICT_OK != ret)
		{
			return;
		}

		uint16_t pos = pbl_capture_sentLen;
		ret = dict_write_int(&imgChunk, KEY_IMG_SIZE, &pos, 2, false);
		if (DICT_OK != ret)
		{
			return;
		}

		ret = dict_write_data(&imgChunk, KEY_IMG_START, http_capture_frameBuffer + pbl_capture_sentLen, BODY_LEN);
		if (DICT_OK != ret)
		{
			return;
		}
		pbl_capture_sentLen += BODY_LEN;

		dict_write_end(&imgChunk);

		mq_post(&imgChunk);
	}
}
Esempio n. 4
0
void checkWeatherUpdate() {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "> checkWeatherUpdate");
  
  char* apiKey = getApiKey();
  if (apiKey == NULL) {
    APP_LOG(APP_LOG_LEVEL_WARNING, "< checkWeatherUpdate - No api key to send.");
    return;
  }
  
  if (!isJsReady()) {
    APP_LOG(APP_LOG_LEVEL_WARNING, "< checkWeatherUpdate - PebbleKit JS is not yet ready.");
    return;    
  }
  
  bool weatherUpdateNecessary = false;
  if (weatherConfigChanged()) {
    weatherUpdateNecessary = true;
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Weather update necessary due to config change.");
  } else {
    unsigned int diff = time(NULL) - getLastWeatherUpdate();
    unsigned int maxDiff = 60 * getUpdateFrequencyInMinutes();
    if (diff >= maxDiff) {
      APP_LOG(APP_LOG_LEVEL_DEBUG, "Last update was %i seconds ago > configured maximum %i. Updating.", diff, maxDiff);
      weatherUpdateNecessary = true;
    }
  }
    
  if (weatherUpdateNecessary) {
    // Begin dictionary
    DictionaryIterator *iter;
    AppMessageResult result = app_message_outbox_begin(&iter);
    if(result == APP_MSG_OK) {
      // Construct the message - add a key-value pair
      APP_LOG(APP_LOG_LEVEL_DEBUG, "Sending api key.");
      dict_write_cstring(iter, MESSAGE_KEY_OWM_APPID, apiKey);
      int value = useCelsius() ? 1 : 0;
      dict_write_int(iter, MESSAGE_KEY_UNIT_TEMP, &value, sizeof(int), true);
      
      int localeValue = getWeatherLocale();
      dict_write_int(iter, MESSAGE_KEY_WEATHER_LOCALE, &localeValue, sizeof(int), true);

      // Send the message!
      app_message_outbox_send();
    } else {
      // The outbox cannot be used right now
      APP_LOG(APP_LOG_LEVEL_ERROR, "Error preparing the outbox: %d", (int)result);
    }      
  }
  APP_LOG(APP_LOG_LEVEL_DEBUG, "< checkWeatherUpdate");
}
Esempio n. 5
0
DictionaryResult dict_write_tuplet(DictionaryIterator *iter, const Tuplet * const tup) {
	const TupletData* const tuplet=(const TupletData* const) tup;
    switch (tuplet->type) {
    case TUPLE_BYTE_ARRAY:
        return dict_write_data(iter, tuplet->key, tuplet->data.bytes.data, tuplet->data.bytes.length);
    case TUPLE_CSTRING:
        return dict_write_cstring(iter, tuplet->key, tuplet->data.cstring.data);
    case TUPLE_INT:
        return dict_write_int(iter, tuplet->key, &(tuplet->data.integer.storage), tuplet->data.integer.width, true);
    case TUPLE_UINT:
        return dict_write_int(iter, tuplet->key, &(tuplet->data.integer.storage), tuplet->data.integer.width, false);
    }

    return DICT_INVALID_ARGS;
}
Esempio n. 6
0
static void updateSunTimes() {
	DictionaryIterator *iter;
	app_message_outbox_begin(&iter);
	int value = 1;
	dict_write_int(iter, KEY_UPDATE_SUNTIMES, &value, sizeof(value), true);
	app_message_outbox_send();
}
void request_from_phone() {
  // Declare the dictionary's iterator
  DictionaryIterator *out_iter;

  // Prepare the outbox buffer for this message
  AppMessageResult result = app_message_outbox_begin(&out_iter);

  if (result == APP_MSG_OK) {
    // A dummy value
    int value = 0;
  
    // Add an item to ask for weather data
    dict_write_int(out_iter, MESSAGE_KEY_phone_battery, &value, sizeof(int), true);
  } else {
    // The outbox cannot be used right now
    APP_LOG(APP_LOG_LEVEL_ERROR, "Error preparing the outbox: %d", (int)result);
  }

  // Send this message
  result = app_message_outbox_send();
  
  // Check the result
  if (result != APP_MSG_OK) {
    APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result);
  }
}
Esempio n. 8
0
static void select_click_callback(MenuLayer *menu_layer, MenuIndex *cell_index, void *callback_context)
{
  switch(cell_index->row){
    case 0:
      finish_init();
      
      DictionaryIterator *iter;
      app_message_outbox_begin(&iter);
      char * phone_num = (char*)malloc(11 * sizeof(char));
      phone_num[0] = cont_num[0];
      phone_num[1] = cont_num[1];
      phone_num[2] = cont_num[2];
      phone_num[3] = cont_num[4];
      phone_num[4] = cont_num[5];
      phone_num[5] = cont_num[6];
      phone_num[6] = cont_num[8];
      phone_num[7] = cont_num[9];
      phone_num[8] = cont_num[10];
      phone_num[9] = cont_num[11];
      phone_num[10] = '\0';
      Tuplet value = TupletCString(1, phone_num);
      dict_write_tuplet(iter, &value);
      int number = (int)(amount * 10);
      dict_write_int(iter, 2, &number, sizeof(int), 0);
      app_message_outbox_send();
      
      break;
    case 1:
      amount = 0;
      was_back = 1;
      show_home();
      break;
  }
}
Esempio n. 9
0
static void ask_hub2watch_to_refresh() {
	// Sends a dumb appMessage to Hub2Watch to force it to refresh
	DictionaryIterator *iter;
	app_message_outbox_begin(&iter);
	int dumbVariable = 111;
	dict_write_int(iter, 1, &dumbVariable, sizeof(dumbVariable), true);
	app_message_outbox_send();
}
Esempio n. 10
0
void battery_handler(BatteryChargeState charge) {
	// Sends an appMessage to Hub2Watch with the new Battery state
	DictionaryIterator *iter;
	app_message_outbox_begin(&iter);
	int percent = charge.charge_percent;
	dict_write_int(iter, 0, &percent, sizeof(int), true);
	app_message_outbox_send();
}
Esempio n. 11
0
static void send(int key, int value) {
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);

  dict_write_int(iter, key, &value, sizeof(int), true);

  app_message_outbox_send();
}
Esempio n. 12
0
static void send_settings_to_phone() {
  if (!JS_ready) return;
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  int dummy_int;
  
  dict_write_cstring(iter, KEY_APP_VERSION, app_version);
  dummy_int=CURRENT_STORAGE_VERSION; dict_write_int(iter, KEY_VERSION, &dummy_int, sizeof(int), true);
  dummy_int=data_timestamp;          dict_write_int(iter, KEY_TIMESTAMP, &dummy_int, sizeof(int), true);
  dummy_int=settings.Show_clock;     dict_write_int(iter, KEY_SHOW_CLOCK, &dummy_int, sizeof(int), true);
  dummy_int=settings.Auto_sort;      dict_write_int(iter, KEY_AUTO_SORT, &dummy_int, sizeof(int), true);
  dummy_int=settings.Hrs_day_x10;    dict_write_int(iter, KEY_HRS_PER_DAY, &dummy_int, sizeof(int), true);
  dummy_int=settings.Last_reset;     dict_write_int(iter, KEY_LAST_RESET, &dummy_int, sizeof(int), true);
  
  if (timer.Active) dict_write_data(iter, KEY_TIMER, (void*) &timer, sizeof(timer));
  jobs_list_write_dict(iter, KEY_JOBS);

  if (export_after_save) {
    dummy_int=true;
    dict_write_int(iter, KEY_EXPORT, &dummy_int, sizeof(int), true);
    export_after_save=false;
  }
  
  dict_write_end(iter);
  LOG("sending outbox...");
  app_message_outbox_send();
}
Esempio n. 13
0
static void send(int key, int message) {
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);

  dict_write_int(iter, key, &message, sizeof(int), true);

  APP_LOG(APP_LOG_LEVEL_INFO, "SEND for KEY %d is %d", key, message);
  app_message_outbox_send();
}
Esempio n. 14
0
void communication_request_weather() {
  int use_celcius = config_get_use_celcius() ? 1 : 0;
  APP_LOG(APP_LOG_LEVEL_INFO, "Sending weather request");
  
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  dict_write_int(iter, KEY_USE_CELCIUS, &use_celcius, sizeof(int), true);
  app_message_outbox_send();
}
Esempio n. 15
0
static void timer_callback(void *data) {
  DictionaryIterator *iter;
  uint8_t value = 1;
  app_message_outbox_begin(&iter);
  dict_write_int(iter, TEMPERATURE_KEY, &value, 1, true);
  dict_write_end(iter);
  app_message_outbox_send();
  
  weather_timer = app_timer_register(getInterval() * 60 * 1000 /* milliseconds */, timer_callback, NULL);
}
Esempio n. 16
0
void netdownload_request(char *url) {
  DictionaryIterator *outbox;
  app_message_outbox_begin(&outbox);
  // Tell the javascript how big we want each chunk of data: max possible size - dictionary overhead with one Tuple in it.
  uint32_t chunk_size = app_message_inbox_size_maximum() - dict_calc_buffer_size(1);
  dict_write_int(outbox, NETDL_CHUNK_SIZE, &chunk_size, sizeof(uint32_t), false);
  // Send the URL
  dict_write_cstring(outbox, NETDL_URL, url);

  app_message_outbox_send();
}
Esempio n. 17
0
static void request_weather(void) {
  DictionaryIterator *iter;
	
  APP_LOG(APP_LOG_LEVEL_INFO, "requesting weather");
  app_message_outbox_begin(&iter);
	if (!iter) return; 		// Error creating outbound message

  int value = 1;
  dict_write_int(iter, 1, &value, sizeof(int), true);
  dict_write_end(iter);
  app_message_outbox_send();
}
Esempio n. 18
0
void imagedownload_request(char *url) {
  DictionaryIterator *outbox;
  app_message_outbox_begin(&outbox);
  // Tell the javascript how big we want each chunk of data:
  // max possible size - dictionary overhead with one zero-byte Tuple in it (since rest of tuple is our data).
  uint32_t chunk_size = app_message_inbox_size_maximum() - dict_calc_buffer_size(1, 0);
  dict_write_int(outbox, MYQR_CHUNK_SIZE, &chunk_size, sizeof(uint32_t), false);
  // Send the URL
  dict_write_cstring(outbox, MYQR_REQUEST_CODE, url);
  
  app_message_outbox_send();
}
Esempio n. 19
0
bool pge_ws_add_int(int key, int value) {
  if(!s_outbox_iter) {
    if(PGE_WS_LOGS) APP_LOG(APP_LOG_LEVEL_ERROR, "pge_ws_packet_begin() has not been called!");
    return false;
  }

  AppMessageResult result = dict_write_int(s_outbox_iter, key, &value, sizeof(int), true);
  if(result != APP_MSG_OK) {
    parse_result(result);
    return false;
  }

  return true;
}
Esempio n. 20
0
/**
* Called when select button is clicked
* Sends the action to the phone and removes the alert
*/
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
  // Get the selected item in the menu
  MenuIndex selected = menu_layer_get_selected_index(action_menu);
  
  // The menu only has section 0 at the moment, if it is not this then we have an erroneous state
  if (selected.section == 0) {
    // Build the message
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);
    
    // Write the message type and hazard ID fields in
    int type = DICT_TYPE_ACTION;
    dict_write_int(iter, DICT_TYPE_KEY, &type, sizeof(int), true);
    dict_write_int(iter, DICT_HAZARD_ID_KEY, &(current_alert->alert_id), sizeof(int), true);
    
    // Determine which action the user has selected
    int action;
    switch (selected.row) {
      case 0:
        action = DICT_ACTION_ACK;
        break;
      case 1:
        action = DICT_ACTION_DIS;
        break;
    }
    dict_write_int(iter, DICT_ACTION_KEY, &action, sizeof(int), true);
    
    // Send the message
    app_message_outbox_send();
    
    // Remove alert from the Pebble and show the notification
    remove_alert_node(current_alert);
    refresh_alert_window();
    show_action_sent_window();
  }
}
Esempio n. 21
0
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
  if(image){
    gbitmap_destroy(image);
    image = NULL;
    bitmap_layer_set_bitmap(image_layer, image);
  }
  text_layer_set_text(text_layer, "Updating image...");

  DictionaryIterator *iter;
  uint8_t value = 1;
  app_message_outbox_begin(&iter);
  dict_write_int(iter, KEY_IMAGE, &value, 1, true);
  dict_write_end(iter);
  app_message_outbox_send();
}
Esempio n. 22
0
static void request_weather(void) {
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);

  if (!iter) {
    // Error creating outbound message
    return;
  }

  int value = 1;
  dict_write_int(iter, 1, &value, sizeof(int), true);
  dict_write_end(iter);

  app_message_outbox_send();
}
Esempio n. 23
0
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {

	if(ErrorExists == 0 && Loading == 0){

		show_details();

	    DictionaryIterator *iter;
	    uint8_t value = 1;
	    app_message_outbox_begin(&iter);
	    dict_write_int(iter, KEY_DETAILS, &value, 1, true);
	    dict_write_end(iter);
	    app_message_outbox_send();
	} else {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Select disabled.");
    }

}
Esempio n. 24
0
static void up_click_handler(ClickRecognizerRef recognizer, void *context) {

    if(Loading == 1){
	    text_layer_set_text(message_text_layer, "PATIENCE!");
        layer_mark_dirty(text_layer_get_layer(message_text_layer));
    } else if(ErrorExists == 0 && Loading == 0){

		load_next();

	    DictionaryIterator *iter;
	    uint8_t value = 1;
	    app_message_outbox_begin(&iter);
	    dict_write_int(iter, KEY_PREVIOUS, &value, 1, true);
	    dict_write_end(iter);
	    app_message_outbox_send();
	} else {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Up disabled.");
    }
}
Esempio n. 25
0
static void send_final_message() {
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  dict_write_cstring(iter, CONTACT_NAME_KEY, contact_name);
  dict_write_cstring(iter, CONTACT_NUMBER_KEY, contact_number);
  // APP_LOG(APP_LOG_LEVEL_INFO, "contact id %s", contact_id);
  dict_write_cstring(iter, CONTACT_ID_KEY, contact_id);
  DictionaryResult res = dict_write_cstring(iter, FINAL_MESSAGE_KEY, dictated_message);
  if (res == DICT_OK) {
    // APP_LOG(APP_LOG_LEVEL_INFO, "added");
  }
  if (res == DICT_NOT_ENOUGH_STORAGE) {
    APP_LOG(APP_LOG_LEVEL_INFO, "not enough storage");
  }
  if (res == DICT_INVALID_ARGS) {
    APP_LOG(APP_LOG_LEVEL_INFO, "invalid args");
  }
  dict_write_int(iter, STATE_KEY, &s_state, 1, 0);
  app_message_outbox_send();
}
Esempio n. 26
0
static void getForecast() {
  if (!isJSRunning)
    return;

  time_t fore_age = (cur_time-temp_fore_age)/3600;

  if (fore_age > 12) { // 12 hours old
    APP_LOG(APP_LOG_LEVEL_INFO, "Forecast data is old, asking for more");
    // Prepare dictionary
    DictionaryIterator *iterator;
    app_message_outbox_begin(&iterator);
    // Write data
    int key = MESSAGE_KEY_REFRESH;
    int value = 2;
    dict_write_int(iterator, key, &value, sizeof(int), true /* signed */);
    // Send the data!
    app_message_outbox_send();
    temp_age = cur_time; // only ask every 60 minutes....  
  }
}
Esempio n. 27
0
void send_request (int value) {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Sending request : %i", value);
    // Declare the dictionary's iterator
    DictionaryIterator* out_iter;

    // Prepare the outbox buffer for this message
    AppMessageResult result = app_message_outbox_begin(&out_iter);
    if (result == APP_MSG_OK) {
        // Add an item to ask for weather data
        dict_write_int(out_iter, MAKE_REQUEST, &value, sizeof(int), false);
        // Send this message
        result = app_message_outbox_send();
        if (result != APP_MSG_OK) {
            APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result);
        }
    } else {
        // The outbox cannot be used right now
        APP_LOG(APP_LOG_LEVEL_ERROR, "Error preparing the outbox: %d", (int)result);
    }
}
Esempio n. 28
0
static void webcam_window_load(Window *window) {
	Layer *window_layer = window_get_root_layer(window);
	GRect bounds = layer_get_bounds(window_layer);

	image_layer = bitmap_layer_create(bounds);
	bitmap_layer_set_alignment(image_layer, GAlignCenter);
	layer_add_child(window_layer, bitmap_layer_get_layer(image_layer));

	webcam_status_text_layer = text_layer_create(GRect(0, bounds.size.h - 16, bounds.size.w, 16));
	text_layer_set_text(webcam_status_text_layer, "Please wait...");
	text_layer_set_font(webcam_status_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	text_layer_set_text_alignment(webcam_status_text_layer, GTextAlignmentCenter);
	text_layer_set_background_color(webcam_status_text_layer, GColorClear);
	layer_add_child(window_layer, text_layer_get_layer(webcam_status_text_layer));


	DictionaryIterator *iter;
	app_message_outbox_begin(&iter);
	dict_write_int(iter, KEY_WEBCAM, &webcam_current_id, sizeof(int), true);
	dict_write_end(iter);
	app_message_outbox_send();  
}
Esempio n. 29
0
DictionaryResult dict_write_int32(DictionaryIterator *iter,
                                   const uint32_t key,
                                   const int32_t value) {

    return dict_write_int(iter, key, &value, 4, true);
}
Esempio n. 30
0
DictionaryResult dict_write_uint16(DictionaryIterator *iter,
                                   const uint32_t key,
                                   const uint16_t value) {

    return dict_write_int(iter, key, &value, 2, false);
}