Advertisement
matejdro

SpeedTest app source

Jul 29th, 2014
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.16 KB | None | 0 0
  1. #include <pebble.h>
  2.  
  3. Window* window;
  4. TextLayer* text;
  5.  
  6. char *itoa(int num)
  7. {
  8.     if (num == 0)
  9.         return "0";
  10.     static char buff[20] = {};
  11.     int i = 0, temp_num = num, length = 0;
  12.     char *string = buff;
  13.     if(num >= 0) {
  14.         // count how many characters in the number
  15.         while(temp_num) {
  16.             temp_num /= 10;
  17.             length++;
  18.         }
  19.         // assign the number to the buffer starting at the end of the
  20.         // number and going to the begining since we are doing the
  21.         // integer to character conversion on the last number in the
  22.         // sequence
  23.         for(i = 0; i < length; i++) {
  24.             buff[(length-1)-i] = '0' + (num % 10);
  25.             num /= 10;
  26.         }
  27.         buff[i] = '\0'; // can't forget the null byte to properly end our string
  28.     }
  29.     else
  30.         return "ER";
  31.     return string;
  32. }
  33.  
  34. void received_data(DictionaryIterator *received, void *context) {
  35.  
  36.     int counter = dict_find(received, 0)->value->uint8;
  37.  
  38.     text_layer_set_text(text, itoa(counter));
  39.  
  40.     DictionaryIterator* dictionary;
  41.     app_message_outbox_begin(&dictionary);
  42.     dict_write_uint8(dictionary, 0, counter);
  43.     dict_write_uint32(dictionary, 1, dict_find(received, 1)->value->uint32);
  44.     app_message_outbox_send();
  45.  
  46.     light_enable_interaction();
  47. }
  48.  
  49. void button_clicked()
  50. {
  51.     app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
  52.     app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
  53.  
  54.     DictionaryIterator* dictionary;
  55.     app_message_outbox_begin(&dictionary);
  56.     dict_write_uint8(dictionary, 0, 0);
  57.     dict_write_uint32(dictionary, 1, 0);
  58.     app_message_outbox_send();
  59.  
  60.     app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
  61. }
  62.  
  63. void click_config_provider(void* context) {
  64.     window_single_click_subscribe(BUTTON_ID_SELECT, button_clicked);
  65. }
  66.  
  67.  
  68.  
  69. int main() {
  70.     app_message_register_inbox_received(received_data);
  71.     app_message_open(124, 50);
  72.  
  73.     window = window_create();
  74.  
  75.     Layer* topLayer = window_get_root_layer(window);
  76.  
  77.     text = text_layer_create(GRect(5,5,100,100));
  78.     text_layer_set_font(text, fonts_get_system_font(FONT_KEY_DROID_SERIF_28_BOLD));
  79.     layer_add_child(topLayer, (Layer*) text);
  80.  
  81.     window_set_click_config_provider(window, (ClickConfigProvider) click_config_provider);
  82.  
  83.     window_stack_push(window, true /* Animated */);
  84.  
  85.     app_event_loop();
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement