void received_data(DictionaryIterator *received, void *context) {
	uint8_t packetId = dict_find(received, 0)->value->uint8;

	if (packetId == 3)
	{
		received_config(received);
		return;
	}
	else if (!gotConfig)
		return;

	if (packetId == 0 && curWindow > 1)
	{
		switchWindow(1);
	}

	switch (curWindow)
	{
	case 0:
		menu_data_received(packetId, received);
		break;
	case 1:
		notification_received_data(packetId, received);
		break;
	case 2:
		list_data_received(packetId, received);
		break;
	}

	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
}
コード例 #2
0
/*----------------------------------------------------------------------------*/
void accel_tap_callback(AccelAxisType axis, uint32_t direction)
{
  /*
   *  If currently not connected to remote side, then force switch state OFF.
   */
  if (isConnected == false) {
    tapSwitchState = false;
  }
  else {
    tapSwitchState = (tapSwitchState) ? false : true;
  }

  if (tapSwitchState == true) {
    APP_LOG(APP_LOG_LEVEL_INFO, "start sampling");
    vibes_long_pulse();
    app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
    accel_data_service_subscribe( SAMPLING_RATE,
                                  (AccelDataHandler) accel_data_callback );
  }
  else {
    app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
    accel_data_service_unsubscribe();
    vibes_long_pulse();
    APP_LOG(APP_LOG_LEVEL_INFO, "stop sampling");
    APP_LOG(APP_LOG_LEVEL_INFO, "stats: sync_set:    %lu",
            (unsigned long)syncStats.sync_set);
    APP_LOG(APP_LOG_LEVEL_INFO, "stats: sync_vib:    %lu",
            (unsigned long)syncStats.sync_vib);
    APP_LOG(APP_LOG_LEVEL_INFO, "stats: sync_missed: %lu",
            (unsigned long)syncStats.sync_missed);
    syncStats.sync_set = 0;
    syncStats.sync_vib = 0;
    syncStats.sync_missed = 0;
  }
}
コード例 #3
0
void option_picked(int index, void* context)
{
  DictionaryIterator *iterator;
	app_message_outbox_begin(&iterator);	
	
	if(index == 0){
    if (vibrateEnabledStatus == 1){
	    vibrateEnabledStatus = 0;
	  } else {
	    vibrateEnabledStatus = 1;
	  }
	  dict_write_uint8(iterator, 0, 10);
	  dict_write_uint8(iterator, 1, vibrateEnabledStatus);	
	} else if(index == 1){
	  if (inverterEnabledStatus == 1){	  
	    dict_write_uint8(iterator, 0, 11);
	    dict_write_uint8(iterator, 1, 0);	
	  } else {
	    dict_write_uint8(iterator, 0, 11);
	    dict_write_uint8(iterator, 1, 1);	
	  }
	}
	
	app_message_outbox_send();
	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
	
}
コード例 #4
0
void window_load(Window *me) {
	setCurWindow(0);

	show_loading();

	DictionaryIterator *iterator;
	app_message_outbox_begin(&iterator);
	dict_write_uint8(iterator, 0, 0);
	app_message_outbox_send();

	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
}
コード例 #5
0
ファイル: wristmap.c プロジェクト: CSUC-notsudo/wristmap
void reload_map() {
    // HACK: this will result in more consistently fast requests, but poor battery life.
    //       see https://github.com/pebble/pebblekit/issues/31#issuecomment-20963734
    app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
    app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
    
    // invert existing map to let user know it is stale
    for (unsigned i=0; i < 20*rowN; i += 1) imgData[i] ^= 0xFF;
    for (unsigned i=20*rowN; i < sizeof(imgData); i += 1) imgData[i] = 0;
    layer_mark_dirty((Layer*)&map.layer);
    
    rowN = 0;
    next_rows();
}
コード例 #6
0
ファイル: Watchapp.c プロジェクト: jbergler/tfl4london
void timerTriggered(void* context)
{
	if (!gotNotification) {
		DictionaryIterator *iterator;
		app_message_outbox_begin(&iterator);
		dict_write_uint8(iterator, KEY_CMD, CMD_READY);
		app_message_outbox_send();

		app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
		app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);

		app_timer_register(500, timerTriggered, NULL);
	}
}
void received_config(DictionaryIterator *received)
{
	uint8_t* data = dict_find(received, 1)->value->data;

	uint16_t supportedVersion = (data[8] << 8) | (data[9]);
	if (supportedVersion > WATCHAPP_VERSION)
	{
		show_old_watchapp();
		return;
	}
	else if (supportedVersion < WATCHAPP_VERSION)
	{
		show_old_android();
		return;
	}

	config_titleFont = data[0];
	config_subtitleFont = data[1];
	config_bodyFont = data[2];
	config_timeout = (data[3] << 8) | (data[4]);
	config_vibratePeriodically = data[5];
	config_vibrateMode = data[6];
	config_autoSwitchNotifications = (data[7] & 0x01) != 0;
	config_dontClose = (data[7] & 0x02) != 0;
	config_showActive = (data[7] & 0x04) != 0;
	config_lightScreen = (data[7] & 0x10) != 0;
	config_dontVibrateWhenCharging = (data[7] & 0x20) != 0;
	config_dontVibrateWhenCharging = (data[7] & 0x20) != 0;
	config_shakeAction = data[10];

	gotConfig = true;

	bool notificationWaiting = (data[7] & 0x08) != 0;
	if (notificationWaiting || !config_showActive)
	{
		DictionaryIterator *iterator;
		app_message_outbox_begin(&iterator);
		dict_write_uint8(iterator, 0, 10);
		app_message_outbox_send();

		app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
		app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
	}
	else
	{
		show_menu();
	}

}
コード例 #8
0
void menu_picked(int index, void* context)
{
	show_loading();

	DictionaryIterator *iterator;
	app_message_outbox_begin(&iterator);

	dict_write_uint8(iterator, 0, 6);
	dict_write_uint8(iterator, 1, index);

	app_message_outbox_send();

	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
}
コード例 #9
0
ファイル: CheatOnMe.c プロジェクト: JohnHoder/CheatOnMe
void send_requestx(int slot, int command)
{
	AppMessageResult result;
	DictionaryIterator *dict;
	result = app_message_outbox_begin(&dict);

	if (result == APP_MSG_OK)
	{
		dict_write_uint8(dict, slot, command);
		dict_write_end(dict);
		result = app_message_outbox_send();

		if (result == APP_MSG_OK)
		{
			app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
		}
	}
	else
	{
		current_slot = slot;
		current_command = command;
		if (command_timer == NULL)
		{
			command_timer = app_timer_register(250, handle_resend, NULL);
		}
	}
}
コード例 #10
0
int main() {
	app_message_register_outbox_sent(data_delivered);
	app_message_register_inbox_received(received_data);

	app_message_open(124, 50);

	DictionaryIterator *iterator;
	app_message_outbox_begin(&iterator);
	dict_write_uint8(iterator, 0, 0);
	dict_write_uint8(iterator, 1, 0);
	dict_write_uint16(iterator, 2, PROTOCOL_VERSION);
	#ifdef PBL_PLATFORM_APLITE
		dict_write_uint8(iterator, 3, 0);
	#else
		dict_write_uint8(iterator, 3, 1);
	#endif

	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_message_outbox_send();

	switchWindow(0);
	app_event_loop();
	window_stack_pop_all(false);
	return 0;
}
コード例 #11
0
void request_categories(uint8_t pos)
{
	if (pos >= numOfGroups)
	{
		show_menu();
		return;
	}

	DictionaryIterator *iterator;
	app_message_outbox_begin(&iterator);
	dict_write_uint8(iterator, 0, 1);
	dict_write_uint8(iterator, 1, pos);
	app_message_outbox_send();

	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
}
コード例 #12
0
ファイル: PebbleTut1.c プロジェクト: t-unit/pebble
static void setupMessages() {
    app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
    
    app_message_register_inbox_received(message_handler);
    app_message_register_inbox_dropped(message_dropped);
    
    app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
    APP_LOG(APP_LOG_LEVEL_DEBUG, "App Message set up.");
}
コード例 #13
0
void menu_picked(int index, void* context)
{
	DictionaryIterator *iterator;
	app_message_outbox_begin(&iterator);

	dict_write_uint8(iterator, 0, 2);
	dict_write_uint8(iterator, 1, index);

	app_message_outbox_send();

	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);

	int newWindow = index > 0 ? 1 : 4;
	if (index > 1 && skipGroupFiltering)
		newWindow = 2;
	switchWindow(newWindow);
}
コード例 #14
0
void menu_picked(int index, void* context)
{
	show_loading();

	DictionaryIterator *iterator;
	app_message_outbox_begin(&iterator);
  if(isNotificationListenerSupported == 1){
	  dict_write_uint8(iterator, 0, 6);
	  dict_write_uint8(iterator, 1, index);
	} else {
	  dict_write_uint8(iterator, 0, 6);
	  dict_write_uint8(iterator, 1, 1);
	}

	app_message_outbox_send();

	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
}
コード例 #15
0
void received_config(DictionaryIterator *received)
{
	uint8_t* data = dict_find(received, 1)->value->data;

	uint16_t supportedVersion = (data[8] << 8) | (data[9]);
	if (supportedVersion > PROTOCOL_VERSION)
	{
		show_old_watchapp();
		return;
	}
	else if (supportedVersion < PROTOCOL_VERSION)
	{
		show_old_android();
		return;
	}

	config_titleFont = data[0];
	config_subtitleFont = data[1];
	config_bodyFont = data[2];
	config_timeout = (data[3] << 8) | (data[4]);
	config_dontClose = (data[7] & 0x02) != 0;
	config_showActive = (data[7] & 0x04) != 0;
	config_lightScreen = (data[7] & 0x10) != 0;
	config_dontVibrateWhenCharging = (data[7] & 0x20) != 0;
	config_disableNotifications = (data[7] & 0x80) != 0;

	config_shakeAction = data[10];
	config_periodicTimeout  = (data[11] << 8) | (data[12]);

	bool newInvertColors = (data[7] & 0x40) != 0;
	if (newInvertColors != config_invertColors)
	{
		persist_write_bool(0, newInvertColors);
		config_invertColors = newInvertColors;
	}

	gotConfig = true;
	loadingMode = false;

	bool notificationWaiting = (data[7] & 0x08) != 0;
	if (notificationWaiting)
	{
		app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);

		DictionaryIterator *iterator;
		app_message_outbox_begin(&iterator);
		dict_write_uint8(iterator, 0, 10);
		app_message_outbox_send();
	}
	else
	{
		show_menu();
	}

}
コード例 #16
0
ファイル: KeepNote.c プロジェクト: kaushalpkk/PebbleKeepColor
void note_data_received(DictionaryIterator* iterator){
  
  Tuple *t = dict_read_first(iterator);

  // For all items
  while(t != NULL) {
    // Which key was received?
    
      APP_LOG(APP_LOG_LEVEL_ERROR, "Key %d ", (int)t->key);
    
  
    // Look for next item
    t = dict_read_next(iterator);
  }
  uint16_t location = dict_find(iterator, 1)->value->uint16;
  uint16_t segmentLength = dict_find(iterator, 2)->value->uint16;
  memcpy((void *) &fullNote[location], dict_find(iterator, 4)->value->cstring, segmentLength);
  GSize maxSize = graphics_text_layout_get_content_size(fullNote, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD),
                                                        GRect(0, 0, 144, 1000), GTextOverflowModeWordWrap, GTextAlignmentLeft);
  if (maxSize.h < 168 - 16)
    maxSize.h = 168 - 16;

  text_layer_set_size(fullNoteText, maxSize);
  scroll_layer_set_content_size(scroller, maxSize);


  text_layer_set_text(fullNoteText, fullNote);

  if (segmentLength == 75){
    DictionaryIterator *iterator;
    app_message_outbox_begin(&iterator);
    
    dict_write_uint8(iterator, 0, 3);
    dict_write_uint16(iterator, 1, location + 75);
    
    app_message_outbox_send();
    
    app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
    app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
  }

}
コード例 #17
0
void received_data(DictionaryIterator *received, void *context) {
	uint8_t packetId = dict_find(received, 0)->value->uint8;

	if (packetId == 5 && curWindow != 10)
	{
		if (curWindow == 0)
			window_stack_pop(false);

		switchWindow(10);
	}
	else if (packetId == 3 && curWindow != 3)
	{
		switchWindow(3);
	}

	switch (curWindow)
	{
	case 0:
		menu_data_received(packetId, received);
		break;
	case 1:
		filter_data_received(packetId, received);
		break;
	case 2:
		contacts_data_received(packetId, received);
		break;
	case 3:
		np_data_received(packetId, received);
		break;
	case 4:
		cl_data_received(packetId, received);
		break;

	case 10:
		callscreen_received_data(packetId, received);
		break;

	}

	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
}
コード例 #18
0
void accl_init(void) {
	tick_timer_service_subscribe(SECOND_UNIT, handle_second_tick);
	accel_data_service_subscribe(10, &accel_data_handler);
	accel_service_set_sampling_rate(sample_freq); //This is the place that works
	
	app_message_register_outbox_failed(accl_out_failed_handler);
	app_message_register_outbox_sent(accl_out_received_handler);

    timer = app_timer_register(timer_interval, timer_callback, NULL);
	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
}
コード例 #19
0
static void requestNumbers(uint16_t pos)
{
	DictionaryIterator *iterator;
	app_message_outbox_begin(&iterator);
	dict_write_uint8(iterator, 0, 2);
	dict_write_uint8(iterator, 1, 0);
	dict_write_uint16(iterator, 2, pos);

	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_message_outbox_send();
}
コード例 #20
0
void closeApp(void)
{
	DictionaryIterator *iterator;
	app_message_outbox_begin(&iterator);
	dict_write_uint8(iterator, 0, 0);
	dict_write_uint8(iterator, 1, 2);
	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_message_outbox_send();

	closingMode = true;
}
コード例 #21
0
static void send_initial_packet() {
	DictionaryIterator *iterator;
	app_message_outbox_begin(&iterator);
	dict_write_uint8(iterator, 0, 0);
	dict_write_uint8(iterator, 1, 0);
	dict_write_uint16(iterator, 2, PROTOCOL_VERSION);
	dict_write_uint32(iterator, 3, getCapabilities(appmessage_max_size));

	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_message_outbox_send();
}
int main(void) {
	app_message_register_inbox_received(received_data);
	app_message_register_outbox_sent(data_sent);
	app_message_open(124, 50);

	switchWindow(0);

	DictionaryIterator *iterator;
	app_message_outbox_begin(&iterator);
	dict_write_uint8(iterator, 0, 0);
	app_message_outbox_send();

	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);

	app_event_loop();

	window_stack_pop_all(false);
	return 0;
}
コード例 #23
0
ファイル: pebmain.c プロジェクト: dsexton702/PebbleNow
int main(void) {
 s_window = window_create();
  window_set_fullscreen(s_window, true);
    app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
       app_message_open(256, 256);
  init_msg();
  
  
  window_set_window_handlers(s_window, (WindowHandlers) {
     .load = window_load,
    .unload = handle_window_unload,
  });
コード例 #24
0
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);
	}
}
コード例 #25
0
static void init(void) {
  app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
  app_message_register_inbox_received(in_received_handler);
  app_message_register_inbox_dropped(in_dropped_handler);
  app_message_register_outbox_sent(out_sent_handler);
  app_message_register_outbox_failed(out_failed_handler);
  app_message_open(app_message_inbox_size_maximum(), APP_MESSAGE_OUTBOX_SIZE_MINIMUM);

  dataitems = entry_list_init(dataitems_select_callback);  
  	
  main_menu_init();
  main_menu_show();
}
コード例 #26
0
ファイル: Compass.c プロジェクト: AustinTheMidget/CashPointer
static void inbox_received_callback(DictionaryIterator *iter, void *context) 
{
	Tuple *t = dict_read_first(iter);
	while(t != NULL) 
	{
		
			int x = (t->value->int32);
			bering = x/1000;
			layer_mark_dirty(s_path_layer);
			t = dict_read_next(iter);
	}	
	app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
}
コード例 #27
0
static void app_message_init(void) {
  // Reduce the sniff interval for more responsive messaging at the expense of
  // increased energy consumption by the Bluetooth module
  // The sniff interval will be restored by the system after the app has been
  // unloaded
  app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
  // Register message handlers
  app_message_register_inbox_received(in_received_handler);
	app_message_register_inbox_dropped(in_dropped_handler);
	app_message_register_outbox_failed(out_dropped_handler);
	app_message_register_outbox_sent(out_sent_handler);
  // Init buffers
  app_message_open(128, 64);
}
コード例 #28
0
void received_data(DictionaryIterator *received, void *context) {
	gotNotification = true;

	uint8_t packetId = dict_find(received, 0)->value->uint8;
	if(packetId == 3){
	  //Retrieve isNotificationListenerSupported;
	  isNotificationListenerSupported = dict_find(received, 3)->value->uint8;
	}
 
  if ((packetId == 3) || (packetId == 10))
	{
		//Retrieve options when loading main menu or when they are changed
		options_data_received(received);
	}
 
	if (packetId == 0 && curWindow > 1)
	{
		switchWindow(1);
	}
	
	switch (curWindow)
	{
	case 0:
		menu_data_received(packetId, received);
		break;
	case 1:
		notification_received_data(packetId, received);
		break;
	case 2:
		list_data_received(packetId, received);
		break;
	}
	

	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
}
コード例 #29
0
ファイル: pge_ws.c プロジェクト: C-D-Lewis/pge
void pge_ws_begin(char *url, PGEWSConnectedHandler *handler, PGEWSReceivedHandler *recv_handler) {
  if(s_connection_state == PGEWSConnectionStateDisconnected) {
    // Set up callbacks
    s_connection_handler = handler;
    s_recv_handler = recv_handler;
    s_url_ptr = url;

    // Prepare to receive, wait for ready
    if(!s_app_message_open) {
      s_app_message_open = true;
      app_message_register_inbox_received(in_recv_handler);
      app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
      app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
      if(PGE_WS_LOGS) APP_LOG(APP_LOG_LEVEL_DEBUG, "PGE_WS: AppMessage opened");
    }
  } else {
    if(PGE_WS_LOGS) APP_LOG(APP_LOG_LEVEL_INFO, "PGE_WS: Already connected, or connection in progress!");
  }
}
コード例 #30
0
ファイル: nohands.c プロジェクト: mohuddle/NoHands
//
//Window setup sutff
//
static void init() {
#ifndef DISABLE_CONFIG
    readConfig();
    // Register callbacks
    app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
    //app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
    app_message_register_inbox_received(inbox_received_callback);
    app_message_register_inbox_dropped(inbox_dropped_callback);
    app_message_register_outbox_failed(outbox_failed_callback);
    app_message_register_outbox_sent(outbox_sent_callback);
    // Open AppMessage
    app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
#endif

    window = window_create();
    window_set_window_handlers(window, (WindowHandlers) {
        .load = window_load,
        .unload = window_unload,
    });