<commit_before>#include <pebble.h>

#define KEY_TEMPERATURE 0
#define KEY_CONDITIONS 1
  
static Window *s_main_window; 
static TextLayer *s_time_layer;
AppTimer *face_timer;
AppTimer *shake_timer;
static int shake_counter = 0;

// Making this global
static char temperature_buffer[8];
static char conditions_buffer[32]; 

static void update_time() {
  // Setup arrays for text time
  char *minute_text[12];
    minute_text[0] = "";
    minute_text[1] = "\nFive\npast\n";
    minute_text[2] = "\nTen\npast\n";
    minute_text[3] = "\nQuarter\npast\n";
    minute_text[4] = "\nTwenty\npast\n";
    minute_text[5] = "\nTwenty\nfive\npast\n";
    minute_text[6] = "\nHalf\npast\n";
    minute_text[7] = "\nTwenty\nfive\nto\n";
    minute_text[8] = "\nTwenty\nto\n";
    minute_text[9] = "\nQuarter\nto\n";
    minute_text[10] = "\nTen\nto\n";
    minute_text[11] = "\nFive\nto\n";
  
  char *hour_text[12];
    hour_text[0] = "Twelve";
    hour_text[1] = "One";
    hour_text[2] = "Two";
    hour_text[3] = "Three";
    hour_text[4] = "Four";
    hour_text[5] = "Five";
    hour_text[6] = "Six";
    hour_text[7] = "Seven";
    hour_text[8] = "Eight";
    hour_text[9] = "Nine";
    hour_text[10] = "Ten";
    hour_text[11] = "Eleven";
 
  // Get a tm structure
  time_t temp = time(NULL); 
  
  // We want minutes to the nearest 5 minute interval
  int minutes = localtime(&temp)->tm_min;
  int remainder = ( minutes % 5 );
  minutes = (minutes - remainder);
  if ( remainder > 2 ) {
    minutes = minutes + 5;
  }

  int hours = localtime(&temp)->tm_hour;
  // 12 Hour Time
  if (hours > 11) { hours = hours - 12; }
  // Inrease hour if we are counting toward
  if (minutes > 30) { hours = hours + 1; }
  // 11 is the new 12, better run that again
  if (hours > 11) { hours = hours - 12; }
  // 60 passed the hour looks a little borked
  if (minutes > 55) { minutes = 0; }
  
  // Create a long-lived buffer
  static char buffer[25] = "";
  if ((minutes / 5) == 0) {
    snprintf(buffer, 25, "\n\n%s o\'clock", hour_text[hours]);
  } else {
    snprintf(buffer, 25, "%s%s", minute_text[minutes / 5], hour_text[hours]);
  }
  
  // Display this time on the TextLayer
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentLeft);
  text_layer_set_text(s_time_layer, buffer);
} 

static void update_date(){
  
  char *mon_text[12];
    mon_text[0] = "\n\nJan ";
    mon_text[1] = "\n\nFeb ";
    mon_text[2] = "\n\nMar ";
    mon_text[3] = "\n\nApr ";
    mon_text[4] = "\n\nMay ";
    mon_text[5] = "\n\nJun ";
    mon_text[6] = "\n\nJul ";
    mon_text[7] = "\n\nAug ";
    mon_text[8] = "\n\nSep ";
    mon_text[9] = "\n\nOct ";
    mon_text[10] = "\n\nNov ";
    mon_text[11] = "\n\nDec ";
  // We're going to say it's midnight at 11:58, so we might as well lie about the date as well
  // Simplified this. Easiest to think that we just run 3 minutes early all the time.
  time_t temp = time(NULL) + 180;
  
  int mday = localtime(&temp)->tm_mday;
  int mon = localtime(&temp)->tm_mon;

  static char buffer[25]= "";
  snprintf(buffer, 25, "%s%i", mon_text[mon], mday);
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentRight);
  text_layer_set_text(s_time_layer, buffer); 
}

static void update_weather(){
  static char buffer[25]= "";
  snprintf(buffer, 25, "\n\n%s\u00B0\n%s", temperature_buffer, conditions_buffer);
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentLeft);
  text_layer_set_text(s_time_layer, buffer); 
}

static void face_timer_callback(void *data) {
  shake_counter = 0;
  update_time();
  app_timer_cancel(face_timer);
}

static void shake_timer_callback(void *date) {
  shake_counter = 0;
  app_timer_cancel(shake_timer);
}

static void tap_handler(AccelAxisType axis, int32_t direction) {
  switch(shake_counter){
  case 0: 
    // Lets assume the first shake was for the back light
    shake_timer = app_timer_register(10000, (AppTimerCallback) shake_timer_callback, NULL);
    break;
  case 1:
    update_date();
    // register a timer to replace date with time after 4 seconds
    face_timer = app_timer_register(4000, (AppTimerCallback) face_timer_callback, NULL);
    // increment the counter
    break;
  case 2:
    update_weather();
    // register a timer to replace date with time after 4 seconds
    app_timer_reschedule(face_timer, 4000);
    // increment the counter
    break;
  }
  shake_counter = shake_counter + 1;
}

static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  update_time();
  
  // Get weather update every 30 minutes
  if(tick_time->tm_min % 30 == 0){
    // Begin dictionary
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);

    // Add a key-value pair
    dict_write_uint8(iter, 0, 0);

    // Send the message!
    app_message_outbox_send();

  }

}

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_TEMPERATURE:
      snprintf(temperature_buffer, sizeof(temperature_buffer), "%d", (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);
  }
}

static void inbox_dropped_callback(AppMessageResult reason, void *context) {
  APP_LOG(APP_LOG_LEVEL_ERROR, "Message dropped!");
}

static void outbox_failed_callback(DictionaryIterator *iterator, AppMessageResult reason, void *context) {
  APP_LOG(APP_LOG_LEVEL_ERROR, "Outbox send failed!");
}

static void outbox_sent_callback(DictionaryIterator *iterator, void *context) {
  APP_LOG(APP_LOG_LEVEL_INFO, "Outbox send success!");
} 

static void main_window_load(Window *window) {
  // Create time TextLayer
  s_time_layer = text_layer_create(GRect(0, 6, 144, 156));
  text_layer_set_background_color(s_time_layer, GColorBlack);
  text_layer_set_text_color(s_time_layer, GColorWhite);

  // Improve the layout to be more like a watchface
  text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK));
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentLeft);

  // Add it as a child layer to the Window's root layer
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));

}

static void main_window_unload(Window *window) {
  // Destroy TextLayer
  text_layer_destroy(s_time_layer);
} 

static void init () {
  // Register callbacks
  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());
  
  // Create main Window element and assign to pointer
  s_main_window = window_create();
  
  window_set_background_color(s_main_window, GColorBlack); 

  // Set handlers to manage the elements inside the Window
  window_set_window_handlers(s_main_window, (WindowHandlers) {
    .load = main_window_load,
    .unload = main_window_unload
  });

  // Show the Window on the watch, with animated=true
  window_stack_push(s_main_window, true);
  
  // Make sure the time is displayed from the start
  update_time();
  
  // Register with TickTimerService
  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
  
  // Register with  AccelTimeService
  // A time will show to date
  accel_tap_service_subscribe(tap_handler); 

}

static void deinit () {
  // Destroy Window
  window_destroy(s_main_window);
}

int main(void) {
  init();
  app_event_loop();
  deinit();
}<commit_msg>Reduced and simplified the timer logic<commit_after>#include <pebble.h>

#define KEY_TEMPERATURE 0
#define KEY_CONDITIONS 1
  
static Window *s_main_window; 
static TextLayer *s_time_layer;
AppTimer *shake_timer;
static int shake_counter = 0;

// Making this global
static char temperature_buffer[8];
static char conditions_buffer[32]; 

static void update_time() {
  // Setup arrays for text time
  char *minute_text[12];
    minute_text[0] = "";
    minute_text[1] = "\nFive\npast\n";
    minute_text[2] = "\nTen\npast\n";
    minute_text[3] = "\nQuarter\npast\n";
    minute_text[4] = "\nTwenty\npast\n";
    minute_text[5] = "\nTwenty\nfive\npast\n";
    minute_text[6] = "\nHalf\npast\n";
    minute_text[7] = "\nTwenty\nfive\nto\n";
    minute_text[8] = "\nTwenty\nto\n";
    minute_text[9] = "\nQuarter\nto\n";
    minute_text[10] = "\nTen\nto\n";
    minute_text[11] = "\nFive\nto\n";
  
  char *hour_text[12];
    hour_text[0] = "Twelve";
    hour_text[1] = "One";
    hour_text[2] = "Two";
    hour_text[3] = "Three";
    hour_text[4] = "Four";
    hour_text[5] = "Five";
    hour_text[6] = "Six";
    hour_text[7] = "Seven";
    hour_text[8] = "Eight";
    hour_text[9] = "Nine";
    hour_text[10] = "Ten";
    hour_text[11] = "Eleven";
 
  // Get a tm structure
  time_t temp = time(NULL); 
  
  // We want minutes to the nearest 5 minute interval
  int minutes = localtime(&temp)->tm_min;
  int remainder = ( minutes % 5 );
  minutes = (minutes - remainder);
  if ( remainder > 2 ) {
    minutes = minutes + 5;
  }

  int hours = localtime(&temp)->tm_hour;
  // 12 Hour Time
  if (hours > 11) { hours = hours - 12; }
  // Inrease hour if we are counting toward
  if (minutes > 30) { hours = hours + 1; }
  // 11 is the new 12, better run that again
  if (hours > 11) { hours = hours - 12; }
  // 60 passed the hour looks a little borked
  if (minutes > 55) { minutes = 0; }
  
  // Create a long-lived buffer
  static char buffer[25] = "";
  if ((minutes / 5) == 0) {
    snprintf(buffer, 25, "\n\n%s o\'clock", hour_text[hours]);
  } else {
    snprintf(buffer, 25, "%s%s", minute_text[minutes / 5], hour_text[hours]);
  }
  
  // Display this time on the TextLayer
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentLeft);
  text_layer_set_text(s_time_layer, buffer);
} 

static void update_date(){
  
  char *mon_text[12];
    mon_text[0] = "\n\nJan ";
    mon_text[1] = "\n\nFeb ";
    mon_text[2] = "\n\nMar ";
    mon_text[3] = "\n\nApr ";
    mon_text[4] = "\n\nMay ";
    mon_text[5] = "\n\nJun ";
    mon_text[6] = "\n\nJul ";
    mon_text[7] = "\n\nAug ";
    mon_text[8] = "\n\nSep ";
    mon_text[9] = "\n\nOct ";
    mon_text[10] = "\n\nNov ";
    mon_text[11] = "\n\nDec ";
  // We're going to say it's midnight at 11:58, so we might as well lie about the date as well
  // Simplified this. Easiest to think that we just run 3 minutes early all the time.
  time_t temp = time(NULL) + 180;
  
  int mday = localtime(&temp)->tm_mday;
  int mon = localtime(&temp)->tm_mon;

  static char buffer[25]= "";
  snprintf(buffer, 25, "%s%i", mon_text[mon], mday);
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentRight);
  text_layer_set_text(s_time_layer, buffer); 
}

static void update_weather(){
  static char buffer[25]= "";
  snprintf(buffer, 25, "\n\n%s\u00B0\n%s", temperature_buffer, conditions_buffer);
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentLeft);
  text_layer_set_text(s_time_layer, buffer); 
}

static void shake_timer_callback(void *date) {
  shake_counter = 0;
  app_timer_cancel(shake_timer);
  update_time();
}

static void tap_handler(AccelAxisType axis, int32_t direction) {
  switch(shake_counter){
  case 0: 
    // Lets assume the first shake was for the back light
    shake_timer = app_timer_register(10000, (AppTimerCallback) shake_timer_callback, NULL);
    break;
  case 1:
    update_date();
    // reset the time to replace date with time after 4 seconds
    app_timer_reschedule(shake_timer, 4000);
    break;
  case 2:
    update_weather();
    // reset the timer to replace date with time after 4 seconds
    app_timer_reschedule(shake_timer, 4000);
    break;
  }
  shake_counter = shake_counter + 1;
}

static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  update_time();
  
  // Get weather update every 30 minutes
  if(tick_time->tm_min % 30 == 0){
    // Begin dictionary
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);

    // Add a key-value pair
    dict_write_uint8(iter, 0, 0);

    // Send the message!
    app_message_outbox_send();

  }

}

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_TEMPERATURE:
      snprintf(temperature_buffer, sizeof(temperature_buffer), "%d", (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);
  }
}

static void inbox_dropped_callback(AppMessageResult reason, void *context) {
  APP_LOG(APP_LOG_LEVEL_ERROR, "Message dropped!");
}

static void outbox_failed_callback(DictionaryIterator *iterator, AppMessageResult reason, void *context) {
  APP_LOG(APP_LOG_LEVEL_ERROR, "Outbox send failed!");
}

static void outbox_sent_callback(DictionaryIterator *iterator, void *context) {
  APP_LOG(APP_LOG_LEVEL_INFO, "Outbox send success!");
} 

static void main_window_load(Window *window) {
  // Create time TextLayer
  s_time_layer = text_layer_create(GRect(0, 6, 144, 156));
  text_layer_set_background_color(s_time_layer, GColorBlack);
  text_layer_set_text_color(s_time_layer, GColorWhite);

  // Improve the layout to be more like a watchface
  text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK));
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentLeft);

  // Add it as a child layer to the Window's root layer
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));

}

static void main_window_unload(Window *window) {
  // Destroy TextLayer
  text_layer_destroy(s_time_layer);
} 

static void init () {
  // Register callbacks
  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());
  
  // Create main Window element and assign to pointer
  s_main_window = window_create();
  
  window_set_background_color(s_main_window, GColorBlack); 

  // Set handlers to manage the elements inside the Window
  window_set_window_handlers(s_main_window, (WindowHandlers) {
    .load = main_window_load,
    .unload = main_window_unload
  });

  // Show the Window on the watch, with animated=true
  window_stack_push(s_main_window, true);
  
  // Make sure the time is displayed from the start
  update_time();
  
  // Register with TickTimerService
  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
  
  // Register with  AccelTimeService
  // A time will show to date
  accel_tap_service_subscribe(tap_handler); 

}

static void deinit () {
  // Destroy Window
  window_destroy(s_main_window);
}

int main(void) {
  init();
  app_event_loop();
  deinit();
}
{'fraction_non_alphanumeric': 0.122150150921585, 'fraction_numerical': 0.01933080726992486, 'mean_word_length': 3.8891679748822607, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1937713', 'n_tokens_mistral': 5818, 'n_tokens_neox': 5469, 'n_words': 1273}