<commit_before>#include <pebble.h>

#define CS_BATTERY_LEVEL_KEY 0xFFFF
#define CS_BATTERY_STATUS_KEY 0xFFFE
#define CS_STOCK_TICKER_KEY 0xFFEF
#define CS_STOCK_VALUE_KEY 0xFFEF
#define CS_WEATHER_TEMP_F_KEY 0xFFDF
#define CS_WEATHER_TEMP_C_KEY 0xFFDE
#define CS_WEATHER_COND_KEY 0xFFDD
#define CS_WEATHER_HUMID_KEY 0xFFDC
#define CS_WEATHER_WIND_SPEED_KEY 0xFFDB
#define CS_WEATHER_WIND_DIR_KEY 0xFFDA
#define CS_UPDATE_BATTERY_KEY 0x0FFF
#define CS_UPDATE_STOCK_KEY 0x0FFE
#define CS_UPDATE_WEATHER_KEY 0x0FFD

static Window *s_main_window;
static TextLayer *s_time_layer, *s_weather_layer, *s_date_layer, *s_day_layer;

//static BitmapLayer *s_background_layer;
//static GBitmap *s_background_bitmap;

static BitmapLayer *s_bticon_layer, *s_baticon_layer;
static GBitmap *s_bticon_con_bitmap, *s_bticon_nc_bitmap, *s_baticon_00_bitmap, 
    *s_baticon_10_bitmap, *s_baticon_20_bitmap, *s_baticon_30_bitmap, *s_baticon_40_bitmap,
	*s_baticon_50_bitmap, *s_baticon_60_bitmap, *s_baticon_70_bitmap, *s_baticon_80_bitmap,
	*s_baticon_90_bitmap, *s_baticon_100_bitmap;

static GFont s_time_font, s_weather_font, s_other_font;

static AppTimer *weatherHandle, *stockHandle;

static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  // Store incoming information
  static char temperature_buffer[8];
  static char conditions_buffer[32];
  static char weather_layer_buffer[32];
  static char battery_buffer[8];
  // Read tuples for data
  Tuple *temp_tuple = dict_find(iterator, CS_WEATHER_TEMP_F_KEY);
  Tuple *conditions_tuple = dict_find(iterator, CS_WEATHER_COND_KEY);

  // If all data is available, use it
  if(temp_tuple && conditions_tuple) {
    snprintf(temperature_buffer, sizeof(temperature_buffer), "%d°F", (int)temp_tuple->value->int32);
    snprintf(conditions_buffer, sizeof(conditions_buffer), "%s", conditions_tuple->value->cstring);

    // Assemble full string and display
    snprintf(weather_layer_buffer, sizeof(weather_layer_buffer), "%s, %s", temperature_buffer, conditions_buffer);
    text_layer_set_text(s_weather_layer, weather_layer_buffer);
  }
  
  Tuple *battery_tuple = dict_find(iterator, CS_BATTERY_LEVEL_KEY);
  
  if(battery_tuple) {
  	APP_LOG(APP_LOG_LEVEL_INFO, "Phone Battery Level: %d", (int)battery_tuple->value->int32);
  }	 
}

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 tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  // Get a tm structure
  time_t temp = time(NULL);  
  struct tm *utc_tick = gmtime(&temp);
  
  // Write the current hours and minutes into a buffer
  static char s_time_buffer[12];
  strftime(s_time_buffer, sizeof(s_time_buffer), clock_is_24h_style() ?
                                          "%H:%M:%S" : "%I:%M:%S", tick_time);
  // Display this time on the TextLayer
  text_layer_set_text(s_time_layer, s_time_buffer);
  
  // Write the current date into a buffer
  static char s_date_buffer[12];
  strftime(s_date_buffer, sizeof(s_date_buffer),  "%m/%d/%Y", tick_time);
  // Display this time on the TextLayer
  text_layer_set_text(s_date_layer, s_date_buffer);
  
  static char s_utc_buffer[2];
  strftime(s_utc_buffer, sizeof(s_utc_buffer), "%H", utc_tick);
  
  static char s_day_buffer[12];
  strftime(s_day_buffer, sizeof(s_day_buffer),  "%A", tick_time);
  text_layer_set_text(s_day_layer, s_day_buffer);
  
}

static void sendUpdate(int key) {
    DictionaryIterator *iter;
    dict_write_uint8(iter, key, 0);
    app_message_outbox_begin(&iter);
    app_message_outbox_send();
}

static void updateWeather(void *data) {
	sendUpdate(CS_UPDATE_WEATHER_KEY);
	if (!weatherHandle) {
		weatherHandle = app_timer_register(uint32_t 900000, AppTimerCallback updateWeather(), void);
		APP_LOG(APP_LOG_LEVEL_INFO, "Weather Timer Set");
	} else if (app_timer_reschedule(weatherHandle, uint32_t 900000)) {
		APP_LOG(APP_LOG_LEVEL_INFO, "Weather Timer Reset");
	}
}

static void updateBattery(void *data) {
	sendUpdate(CS_UPDATE_BATTERY_KEY);
}

static void updateStock(void *data) {
	sendUpdate(CS_UPDATE_WEATHER_KEY);
	if (!weatherHandle) {
		stockHandle = app_timer_register(uint32_t 900000, AppTimerCallback updateStock(), void);
		APP_LOG(APP_LOG_LEVEL_INFO, "Stock Timer Set");
	} else if (app_timer_reschedule(stockHandle, uint32_t 900000)) {
		APP_LOG(APP_LOG_LEVEL_INFO, "Stock Timer Reset");
	}
}

static void bt_handler(bool connected) {
  if (connected) {
    APP_LOG(APP_LOG_LEVEL_INFO, "Phone is connected!");
    bitmap_layer_set_bitmap(s_bticon_layer, s_bticon_con_bitmap);
  } else {
    APP_LOG(APP_LOG_LEVEL_INFO, "Phone is not connected!");
    bitmap_layer_set_bitmap(s_bticon_layer, s_bticon_nc_bitmap);
    // Issue a vibrating alert
    vibes_double_pulse();
  }
}

static void battery_handler(BatteryChargeState charge_state) {
    static char level[5];<commit_msg>copy paste mistake in code<commit_after>#include <pebble.h>

#define CS_BATTERY_LEVEL_KEY 0xFFFF
#define CS_BATTERY_STATUS_KEY 0xFFFE
#define CS_STOCK_TICKER_KEY 0xFFEF
#define CS_STOCK_VALUE_KEY 0xFFEF
#define CS_WEATHER_TEMP_F_KEY 0xFFDF
#define CS_WEATHER_TEMP_C_KEY 0xFFDE
#define CS_WEATHER_COND_KEY 0xFFDD
#define CS_WEATHER_HUMID_KEY 0xFFDC
#define CS_WEATHER_WIND_SPEED_KEY 0xFFDB
#define CS_WEATHER_WIND_DIR_KEY 0xFFDA
#define CS_UPDATE_BATTERY_KEY 0x0FFF
#define CS_UPDATE_STOCK_KEY 0x0FFE
#define CS_UPDATE_WEATHER_KEY 0x0FFD

static Window *s_main_window;
static TextLayer *s_time_layer, *s_weather_layer, *s_date_layer, *s_day_layer;

//static BitmapLayer *s_background_layer;
//static GBitmap *s_background_bitmap;

static BitmapLayer *s_bticon_layer, *s_baticon_layer;
static GBitmap *s_bticon_con_bitmap, *s_bticon_nc_bitmap, *s_baticon_00_bitmap, 
    *s_baticon_10_bitmap, *s_baticon_20_bitmap, *s_baticon_30_bitmap, *s_baticon_40_bitmap,
	*s_baticon_50_bitmap, *s_baticon_60_bitmap, *s_baticon_70_bitmap, *s_baticon_80_bitmap,
	*s_baticon_90_bitmap, *s_baticon_100_bitmap;

static GFont s_time_font, s_weather_font, s_other_font;

static AppTimer *weatherHandle, *stockHandle;

static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  // Store incoming information
  static char temperature_buffer[8];
  static char conditions_buffer[32];
  static char weather_layer_buffer[32];
  static char battery_buffer[8];
  // Read tuples for data
  Tuple *temp_tuple = dict_find(iterator, CS_WEATHER_TEMP_F_KEY);
  Tuple *conditions_tuple = dict_find(iterator, CS_WEATHER_COND_KEY);

  // If all data is available, use it
  if(temp_tuple && conditions_tuple) {
    snprintf(temperature_buffer, sizeof(temperature_buffer), "%d°F", (int)temp_tuple->value->int32);
    snprintf(conditions_buffer, sizeof(conditions_buffer), "%s", conditions_tuple->value->cstring);

    // Assemble full string and display
    snprintf(weather_layer_buffer, sizeof(weather_layer_buffer), "%s, %s", temperature_buffer, conditions_buffer);
    text_layer_set_text(s_weather_layer, weather_layer_buffer);
  }
  
  Tuple *battery_tuple = dict_find(iterator, CS_BATTERY_LEVEL_KEY);
  
  if(battery_tuple) {
  	APP_LOG(APP_LOG_LEVEL_INFO, "Phone Battery Level: %d", (int)battery_tuple->value->int32);
  }	 
}

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 tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  // Get a tm structure
  time_t temp = time(NULL);  
  struct tm *utc_tick = gmtime(&temp);
  
  // Write the current hours and minutes into a buffer
  static char s_time_buffer[12];
  strftime(s_time_buffer, sizeof(s_time_buffer), clock_is_24h_style() ?
                                          "%H:%M:%S" : "%I:%M:%S", tick_time);
  // Display this time on the TextLayer
  text_layer_set_text(s_time_layer, s_time_buffer);
  
  // Write the current date into a buffer
  static char s_date_buffer[12];
  strftime(s_date_buffer, sizeof(s_date_buffer),  "%m/%d/%Y", tick_time);
  // Display this time on the TextLayer
  text_layer_set_text(s_date_layer, s_date_buffer);
  
  static char s_utc_buffer[2];
  strftime(s_utc_buffer, sizeof(s_utc_buffer), "%H", utc_tick);
  
  static char s_day_buffer[12];
  strftime(s_day_buffer, sizeof(s_day_buffer),  "%A", tick_time);
  text_layer_set_text(s_day_layer, s_day_buffer);
  
}

static void sendUpdate(int key) {
    DictionaryIterator *iter;
    dict_write_uint8(iter, key, 0);
    app_message_outbox_begin(&iter);
    app_message_outbox_send();
}

static void updateWeather(void *data) {
	sendUpdate(CS_UPDATE_WEATHER_KEY);
	if (!weatherHandle) {
		weatherHandle = app_timer_register(900000, AppTimerCallback updateWeather(), void);
		APP_LOG(APP_LOG_LEVEL_INFO, "Weather Timer Set");
	} else if (app_timer_reschedule(weatherHandle, 900000)) {
		APP_LOG(APP_LOG_LEVEL_INFO, "Weather Timer Reset");
	}
}

static void updateBattery(void *data) {
	sendUpdate(CS_UPDATE_BATTERY_KEY);
}

static void updateStock(void *data) {
	sendUpdate(CS_UPDATE_WEATHER_KEY);
	if (!weatherHandle) {
		stockHandle = app_timer_register(900000, AppTimerCallback updateStock(), void);
		APP_LOG(APP_LOG_LEVEL_INFO, "Stock Timer Set");
	} else if (app_timer_reschedule(stockHandle, 900000)) {
		APP_LOG(APP_LOG_LEVEL_INFO, "Stock Timer Reset");
	}
}

static void bt_handler(bool connected) {
  if (connected) {
    APP_LOG(APP_LOG_LEVEL_INFO, "Phone is connected!");
    bitmap_layer_set_bitmap(s_bticon_layer, s_bticon_con_bitmap);
  } else {
    APP_LOG(APP_LOG_LEVEL_INFO, "Phone is not connected!");
    bitmap_layer_set_bitmap(s_bticon_layer, s_bticon_nc_bitmap);
    // Issue a vibrating alert
    vibes_double_pulse();
  }
}

static void battery_handler(BatteryChargeState charge_state) {
    static char level[5];
{'fraction_non_alphanumeric': 0.09655969933506794, 'fraction_numerical': 0.017153319841958177, 'mean_word_length': 6.211952744961779, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2295144', 'n_tokens_mistral': 3955, 'n_tokens_neox': 3804, 'n_words': 741}