Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <pebble.h>
- Window* window;
- TextLayer* text;
- char *itoa(int num)
- {
- if (num == 0)
- return "0";
- static char buff[20] = {};
- int i = 0, temp_num = num, length = 0;
- char *string = buff;
- if(num >= 0) {
- // count how many characters in the number
- while(temp_num) {
- temp_num /= 10;
- length++;
- }
- // assign the number to the buffer starting at the end of the
- // number and going to the begining since we are doing the
- // integer to character conversion on the last number in the
- // sequence
- for(i = 0; i < length; i++) {
- buff[(length-1)-i] = '0' + (num % 10);
- num /= 10;
- }
- buff[i] = '\0'; // can't forget the null byte to properly end our string
- }
- else
- return "ER";
- return string;
- }
- void received_data(DictionaryIterator *received, void *context) {
- int counter = dict_find(received, 0)->value->uint8;
- text_layer_set_text(text, itoa(counter));
- DictionaryIterator* dictionary;
- app_message_outbox_begin(&dictionary);
- dict_write_uint8(dictionary, 0, counter);
- dict_write_uint32(dictionary, 1, dict_find(received, 1)->value->uint32);
- app_message_outbox_send();
- light_enable_interaction();
- }
- void button_clicked()
- {
- app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
- app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
- DictionaryIterator* dictionary;
- app_message_outbox_begin(&dictionary);
- dict_write_uint8(dictionary, 0, 0);
- dict_write_uint32(dictionary, 1, 0);
- app_message_outbox_send();
- app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
- }
- void click_config_provider(void* context) {
- window_single_click_subscribe(BUTTON_ID_SELECT, button_clicked);
- }
- int main() {
- app_message_register_inbox_received(received_data);
- app_message_open(124, 50);
- window = window_create();
- Layer* topLayer = window_get_root_layer(window);
- text = text_layer_create(GRect(5,5,100,100));
- text_layer_set_font(text, fonts_get_system_font(FONT_KEY_DROID_SERIF_28_BOLD));
- layer_add_child(topLayer, (Layer*) text);
- window_set_click_config_provider(window, (ClickConfigProvider) click_config_provider);
- window_stack_push(window, true /* Animated */);
- app_event_loop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement