Exemplo n.º 1
0
void readSettings(){

    if( persist_exists(BLACK_KEY))              black =             persist_read_bool(BLACK_KEY);
    if( persist_exists(GRID_KEY))               grid =              persist_read_bool(GRID_KEY);
    if( persist_exists(INVERT_KEY))             invert =            persist_read_bool(INVERT_KEY);
    if( persist_exists(SHOWTIME_KEY))           showtime =          persist_read_bool(SHOWTIME_KEY);
    if( persist_exists(HIDELASTPREV_KEY))       hidelastprev =      persist_read_bool(HIDELASTPREV_KEY);
    if( persist_exists(HIDEAGENDA_KEY))         hideagenda =        persist_read_bool(HIDEAGENDA_KEY);
    if( persist_exists(NOTINVERTAGENDA_KEY))    notinvertagenda =   persist_read_bool(NOTINVERTAGENDA_KEY);
    if( persist_exists(BOLDEVENTS_KEY))         boldevents =        persist_read_bool(BOLDEVENTS_KEY);
    if( persist_exists(SHOWLABELS_KEY))         showlabels =        persist_read_bool(SHOWLABELS_KEY);
    if( persist_exists(SHOWDATE_KEY))           showdate =          persist_read_bool(SHOWDATE_KEY);
    
    if( persist_exists(START_OF_WEEK_KEY))      start_of_week =     persist_read_int(START_OF_WEEK_KEY);
    if( persist_exists(SHOWWEEKNO_KEY))         showweekno =        persist_read_int(SHOWWEEKNO_KEY);
    if( persist_exists(WEEKSTOSHOW_KEY))        weekstoshow =       persist_read_int(WEEKSTOSHOW_KEY);
    if( persist_exists(AGENDA_TITLE_KEY))       agenda_title_rows = persist_read_int(AGENDA_TITLE_KEY);
    
    if( persist_exists(AGENDALENGTH_KEY))       agendaLength =      persist_read_int(AGENDALENGTH_KEY);
    for(int i = 0; i<MAX_AGENDA_LENGTH;i++ ){
        if( persist_exists(AGENDATITLE_KEY+i)){
            persist_read_data(AGENDATITLE_KEY+i,agendaTitle[i],sizeof(agendaTitle[i]));
            persist_read_data(AGENDADATE_KEY+i, agendaDate[i], sizeof(agendaDate[i]));
            persist_read_data(AGENDATIME_KEY+i, agendaTime[i], sizeof(agendaTime[i]));
        }
    }
}
Exemplo n.º 2
0
void strap_init() {
    if (!persist_read_bool(STRAP_OPT_OUT)) {
        memset(cur_activity, 0, sizeof(cur_activity));
        strap_set_activity("UNKNOWN");
        app_message_register_outbox_sent(strap_out_sent_handler);
        app_message_register_outbox_failed(strap_out_failed_handler);

        // detect if app crashed last time
        if (persist_read_bool(STRAP_CRASH_WATCHER)) {
            strap_log_action("STRAP_CRASH");
        }

        // set persistent boolean that will be removed when app is deinited
        // we will check for existance on init, and if it is true
        persist_write_bool(STRAP_CRASH_WATCHER,true);

        // start sending accl data in 30 seconds
        #ifndef DISABLE_ACCL
            acclStart = app_timer_register(30 * 1000, app_timer_accl_start,NULL);
        #endif
        battTimer = app_timer_register(1 * 10 * 1000, app_timer_battery,NULL);
        //app_timer_register(30 * 1000,log_timer, NULL);
        app_timer_register(1  * 1000,log_action,"STRAP_START");
    } else {
        app_log(APP_LOG_LEVEL_INFO, "log", 0, "USER OPTED OUT OF STRAP METRICS");
    }
}
Exemplo n.º 3
0
void read_configuration(void)
{
  APP_LOG(APP_LOG_LEVEL_DEBUG, "read_configuration");
  
  if (persist_exists(MESSAGE_KEY_HH_IN_BOLD))
  {
    hh_in_bold = persist_read_bool(MESSAGE_KEY_HH_IN_BOLD);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "hh_in_bold = %d", hh_in_bold);
  }
  
  if (persist_exists(MESSAGE_KEY_MM_IN_BOLD))
  {
    mm_in_bold = persist_read_bool(MESSAGE_KEY_MM_IN_BOLD);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "mm_in_bold = %d", mm_in_bold);
  }
  
  if (persist_exists(MESSAGE_KEY_LOCALE))
  {
    locale = persist_read_int(MESSAGE_KEY_LOCALE);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "using config locale (0=en, 1=fr, 2=de, 3=es, 4=it) = %d", locale);
  }
  else {
    // use default / system locale
    char *sys_locale = setlocale(LC_ALL, "");
    
    if (strcmp(sys_locale, "fr_FR") == 0) {
      locale = locale_fr;
    } else if (strcmp(sys_locale, "de_DE") == 0) {
      locale = locale_de;
    } else if (strcmp(sys_locale, "es_ES") == 0) {
      locale = locale_es;
    } else if (strcmp(sys_locale, "it_IT") == 0) {
      locale = locale_it;
    } else {
      locale = locale_en; // default
    }
    
    APP_LOG(APP_LOG_LEVEL_DEBUG, "using default locale = %s -> %d", sys_locale, locale);
  }
  
  if (persist_exists(MESSAGE_KEY_HH_STRIP_ZERO))
  {
    hh_strip_zero = persist_read_bool(MESSAGE_KEY_HH_STRIP_ZERO);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "hh_strip_zero = %d", hh_strip_zero);
  }
  
  if (persist_exists(MESSAGE_KEY_TIME_SEP))
  {
    time_sep = persist_read_int(MESSAGE_KEY_TIME_SEP);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "time_sep = %d", time_sep);
  }
  
  if (persist_exists(MESSAGE_KEY_REPEAT_VIB))
  {
    repeat_vib = persist_read_bool(MESSAGE_KEY_REPEAT_VIB);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "repeat_vib = %d", repeat_vib);
  }
}
Exemplo n.º 4
0
void handle_init(void) {
	// Create a window and text layer
	window = window_create();
	text_layer = text_layer_create(GRect(0, TIME_HEIGHT, 144, 168 - TIME_HEIGHT));

	show_seconds = persist_read_bool(KEY_SHOW_SECONDS);
	invert_face = persist_read_bool(KEY_INVERT);
	metric_units = persist_read_bool(KEY_UNITS);
	
	latitude[0] = 0;
	longitude[0] = 0;
	location[0] = 0;
	weather[0] = 0;
	// Set the text, font, and text alignment
	//text_layer_set_text(text_layer, "");
	// http://www.openweathermap.org/current
	// https://developer.getpebble.com/blog/2013/07/24/Using-Pebble-System-Fonts/
	// https://github.com/JvetS/PebbleSimulator/blob/master/PebbleSimulator/pebble_fonts.h
	text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	// https://developer.getpebble.com/2/api-reference/group___graphics_types.html
	text_layer_set_text_alignment(text_layer, GTextAlignmentLeft);

	// Add the text layer to the window
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_layer));

//	date_layer = text_layer_create(GRect(0, 112, 144, 56));
//	text_layer_set_text_alignment(date_layer, GTextAlignmentCenter);
//	text_layer_set_font(date_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
//	layer_add_child(window_get_root_layer(window), text_layer_get_layer(date_layer));
	time_layer = text_layer_create(GRect(0, 0, 144, TIME_HEIGHT));
	text_layer_set_text_alignment(time_layer, GTextAlignmentCenter);
	text_layer_set_font(time_layer, fonts_get_system_font(FONT_PRO_32));
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer));

	inverter_layer = inverter_layer_create(GRect(0, 0, 144, 168));
	layer_add_child(window_get_root_layer(window), inverter_layer_get_layer(inverter_layer));
	layer_set_hidden(inverter_layer_get_layer(inverter_layer), invert_face);
	
	battery_state_service_subscribe(handle_battery_change);
	handle_battery_change(battery_state_service_peek());

	bluetooth_connection_service_subscribe(handle_bluetooth_change);
	handle_bluetooth_change(bluetooth_connection_service_peek());
	
	app_message_register_inbox_received(in_received_handler);
	app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());

	time_t current_time = time(0);
	handle_timechanges(localtime(&current_time), SECOND_UNIT);
	
	tick_timer_service_subscribe(SECOND_UNIT, handle_timechanges);
	
	// Push the window
	window_stack_push(window, true);

	// App Logging!
	//APP_LOG(APP_LOG_LEVEL_DEBUG, "Hello World from the applogs!");
}
Exemplo n.º 5
0
void processSettings(uint8_t encoded[6]){

    black               = (encoded[0] & (1 << 0)) != 0;
    grid                = (encoded[0] & (1 << 1)) != 0;
    invert              = (encoded[0] & (1 << 2)) != 0;
    showtime            = (encoded[0] & (1 << 3)) != 0;
    hidelastprev        = (encoded[0] & (1 << 4)) != 0;
    boldevents          = (encoded[0] & (1 << 5)) != 0;
    hideagenda          = (encoded[0] & (1 << 6)) != 0;
    notinvertagenda     = (encoded[0] & (1 << 7)) != 0;

    start_of_week       = (int) encoded[1];
    showweekno          = (int) encoded[2];
    weekstoshow         = (int) encoded[3];
    agenda_title_rows   = (int) encoded[4]+1;

    showlabels          = (encoded[5] & (1 << 0)) != 0;
    showdate            = (encoded[5] & (1 << 1)) != 0;
    
    
    int changed = false;
    if( ( ! persist_exists(BLACK_KEY)           ) || persist_read_bool(BLACK_KEY)           != black            ){ persist_write_bool(BLACK_KEY,            black);            changed = true;}
    if( ( ! persist_exists(GRID_KEY)            ) || persist_read_bool(GRID_KEY)            != grid             ){ persist_write_bool(GRID_KEY,             grid);             changed = true;}
    if( ( ! persist_exists(INVERT_KEY)          ) || persist_read_bool(INVERT_KEY)          != invert           ){ persist_write_bool(INVERT_KEY,           invert);           changed = true;}
    if( ( ! persist_exists(SHOWTIME_KEY)        ) || persist_read_bool(SHOWTIME_KEY)        != showtime         ){ persist_write_bool(SHOWTIME_KEY,         showtime);         changed = true;}
    if( ( ! persist_exists(HIDELASTPREV_KEY)    ) || persist_read_bool(HIDELASTPREV_KEY)    != hidelastprev     ){ persist_write_bool(HIDELASTPREV_KEY,     hidelastprev);     changed = true;}
    if( ( ! persist_exists(HIDEAGENDA_KEY)      ) || persist_read_bool(HIDEAGENDA_KEY)      != hideagenda       ){ persist_write_bool(HIDEAGENDA_KEY,       hideagenda);       changed = true;}
    if( ( ! persist_exists(NOTINVERTAGENDA_KEY) ) || persist_read_bool(NOTINVERTAGENDA_KEY) != notinvertagenda  ){ persist_write_bool(NOTINVERTAGENDA_KEY,  notinvertagenda);  changed = true;}
    if( ( ! persist_exists(BOLDEVENTS_KEY)      ) || persist_read_bool(BOLDEVENTS_KEY)      != boldevents       ){ persist_write_bool(BOLDEVENTS_KEY,       boldevents);       changed = true;}
    if( ( ! persist_exists(SHOWLABELS_KEY)      ) || persist_read_bool(SHOWLABELS_KEY)      != showlabels       ){ persist_write_bool(SHOWLABELS_KEY,       showlabels);       changed = true;}
    if( ( ! persist_exists(SHOWDATE_KEY)        ) || persist_read_bool(SHOWDATE_KEY)        != showdate         ){ persist_write_bool(SHOWDATE_KEY,         showdate);         changed = true;}
    if( ( ! persist_exists(START_OF_WEEK_KEY)   ) || persist_read_int (START_OF_WEEK_KEY)   != start_of_week    ){ persist_write_int(START_OF_WEEK_KEY,     start_of_week);    changed = true;}
    if( ( ! persist_exists(SHOWWEEKNO_KEY)      ) || persist_read_int (SHOWWEEKNO_KEY)      != showweekno       ){ persist_write_int(SHOWWEEKNO_KEY,        showweekno);       changed = true;}
    if( ( ! persist_exists(WEEKSTOSHOW_KEY)     ) || persist_read_int (WEEKSTOSHOW_KEY)     != weekstoshow      ){ persist_write_int(WEEKSTOSHOW_KEY,       weekstoshow);      changed = true;}
    if( ( ! persist_exists(AGENDA_TITLE_KEY)    ) || persist_read_int (AGENDA_TITLE_KEY)    != agenda_title_rows){ persist_write_int(AGENDA_TITLE_KEY,      agenda_title_rows);changed = true; agenda_mark_dirty(); }



    if(changed){
    
        if(black)
            window_set_background_color(calendar_window, GColorBlack);
        else
            window_set_background_color(calendar_window, GColorWhite);
        
        
        if(showtime){  
            layer_set_hidden(timeLayer,false);      
            time_t now = time(NULL);
            struct tm *currentTime = localtime(&now);
            updateTime(currentTime);
        }
        else{
            layer_set_hidden(timeLayer,true);
        }
        layer_mark_dirty(days_layer);
    }
}
Exemplo n.º 6
0
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
	if (persist_read_bool(KEY_SHOW_DAY)) {
		update_day(tick_time);
	}
	update_time(tick_time);
	if (persist_read_bool(KEY_SHOW_DATE)) {
		update_date(tick_time);
	}
}
Exemplo n.º 7
0
void update_settings_visuals() {
	if (persist_read_bool(KEY_SHOW_DAY)) {
		text_layer_set_text_color(s_layer_day, s_color_text);
	} else {
		text_layer_set_text_color(s_layer_day, GColorClear);
	}
	if (persist_read_bool(KEY_SHOW_DATE)) {
		text_layer_set_text_color(s_layer_date, s_color_text);
	} else {
		text_layer_set_text_color(s_layer_date, GColorClear);
	}
}
Exemplo n.º 8
0
void stats_print_status()
{
  APP_LOG(APP_LOG_LEVEL_DEBUG, "HAPPINESS:%d", (int)persist_read_int(HAPPINESS_LEVEL_KEY));
  APP_LOG(APP_LOG_LEVEL_DEBUG, "HUNGER:%d", (int)persist_read_int(HUNGER_LEVEL_KEY));
  APP_LOG(APP_LOG_LEVEL_DEBUG, "ENERGY:%d", (int)persist_read_int(ENERGY_LEVEL_KEY));
  APP_LOG(APP_LOG_LEVEL_DEBUG, "ACTIVE:%d", (int)persist_read_int(ACTIVE_LEVEL_KEY));
  APP_LOG(APP_LOG_LEVEL_DEBUG, "HYGIENE:%d", (int)persist_read_int(HYGIENE_LEVEL_KEY));
  APP_LOG(APP_LOG_LEVEL_DEBUG, "SICK:%s", persist_read_bool(SICK_STATUS_KEY) ? "true" : "false");
  APP_LOG(APP_LOG_LEVEL_DEBUG, "SLEEP:%s", persist_read_bool(SLEEP_STATUS_KEY) ? "true" : "false");
  APP_LOG(APP_LOG_LEVEL_DEBUG, "TOTAL STATS:%d", (int)persist_read_int(TOTAL_STATS_KEY));
  APP_LOG(APP_LOG_LEVEL_DEBUG, "TOTAL TICS:%d", (int)persist_read_int(TOTAL_TICS_KEY));
}
Exemplo n.º 9
0
/*
 * Load the saved color settings, or if they don't exist load defaults
 */
void Settings_loadFromStorage() {
  if(persist_exists(SETTING_TIME_COLOR_KEY) && persist_exists(SETTING_TIME_BG_COLOR_KEY) &&
     persist_exists(SETTING_SIDEBAR_COLOR_KEY) && persist_exists(SETTING_SIDEBAR_TEXT_COLOR_KEY)) {

    // if the color data exists, load the colors
    persist_read_data(SETTING_TIME_COLOR_KEY,         &globalSettings.timeColor,        sizeof(GColor));
    persist_read_data(SETTING_TIME_BG_COLOR_KEY,      &globalSettings.timeBgColor,      sizeof(GColor));
    persist_read_data(SETTING_SIDEBAR_COLOR_KEY,      &globalSettings.sidebarColor,     sizeof(GColor));
    persist_read_data(SETTING_SIDEBAR_TEXT_COLOR_KEY, &globalSettings.sidebarTextColor, sizeof(GColor));
  } else {
    // otherwise, load the default colors
    globalSettings.timeBgColor      = GColorBlack;
    globalSettings.sidebarTextColor = GColorBlack;

    #ifdef PBL_COLOR
      globalSettings.timeColor      = GColorOrange;
      globalSettings.sidebarColor   = GColorOrange;
    #else
      globalSettings.timeColor      = GColorWhite;
      globalSettings.sidebarColor   = GColorWhite;
    #endif
  }

  // load widgets
  if(persist_exists(SETTING_SIDEBAR_WIDGET0_KEY)) {
    globalSettings.widgets[0] = persist_read_int(SETTING_SIDEBAR_WIDGET0_KEY);
    globalSettings.widgets[1] = persist_read_int(SETTING_SIDEBAR_WIDGET1_KEY);
    globalSettings.widgets[2] = persist_read_int(SETTING_SIDEBAR_WIDGET2_KEY);
  } else {
    // in the case of a new installation, set the default widgets
    globalSettings.widgets[0] = WEATHER_CURRENT;
    globalSettings.widgets[1] = EMPTY;
    globalSettings.widgets[2] = DATE;
  }

  if(persist_exists(SETTING_ALTCLOCK_NAME_KEY)) {
    persist_read_string(SETTING_ALTCLOCK_NAME_KEY, globalSettings.altclockName, sizeof(globalSettings.altclockName));
  } else {
    strncpy(globalSettings.altclockName, "ALT", sizeof(globalSettings.altclockName));
  }

  // load the rest of the settings, using default settings if none exist
  // all settings except colors automatically return "0" or "false" if
  // they haven't been set yet, so we don't need to check if they exist
  globalSettings.useMetric              = persist_read_bool(SETTING_USE_METRIC_KEY);
  globalSettings.sidebarOnLeft          = persist_read_bool(SETTING_SIDEBAR_LEFT_KEY);
  globalSettings.btVibe                 = persist_read_bool(SETTING_BT_VIBE_KEY);
  globalSettings.languageId             = persist_read_int(SETTING_LANGUAGE_ID_KEY);
  globalSettings.showLeadingZero        = persist_read_int(SETTING_LEADING_ZERO_KEY);
  globalSettings.showBatteryPct         = persist_read_bool(SETTING_SHOW_BATTERY_PCT_KEY);
  globalSettings.disableWeather         = persist_read_bool(SETTING_DISABLE_WEATHER_KEY);
  globalSettings.clockFontId            = persist_read_bool(SETTING_CLOCK_FONT_ID_KEY);
  globalSettings.hourlyVibe             = persist_read_int(SETTING_HOURLY_VIBE_KEY);
  globalSettings.onlyShowBatteryWhenLow = persist_read_bool(SETTING_BATTERY_ONLY_WHEN_LOW_KEY);
  globalSettings.useLargeFonts          = persist_read_bool(SETTING_USE_LARGE_FONTS_KEY);
  globalSettings.altclockOffset         = persist_read_int(SETTING_ALTCLOCK_OFFSET_KEY);

  Settings_updateDynamicSettings();
}
Exemplo n.º 10
0
bool LoadPersistedData(void)
{
	CharacterData *characterData;
	int floor = 0;
	if(!persist_exists(PERSISTED_IS_DATA_SAVED) || !persist_read_bool(PERSISTED_IS_DATA_SAVED))
		return false;
		
	if(!IsPersistedDataCurrent())
	{
		WARNING_LOG("Persisted data does not match current version, clearing.");
		ClearPersistedData();
		return false;
	}

	INFO_LOG("Loading persisted data.");
	characterData = GetCharacter();
	persist_read_data(PERSISTED_CHARACTER_DATA, characterData, sizeof(CharacterData));
	floor = persist_read_int(PERSISTED_CURRENT_FLOOR);
	SetCurrentFloor(floor);
	
	uint8_t * itemsOwned = malloc(sizeof(uint8_t) * ITEM_TYPE_COUNT);
	persist_read_data(PERSISTED_ITEM_DATA, itemsOwned, sizeof(itemsOwned));
	SetItemOwned(itemsOwned);
	free(itemsOwned);
	
	SetStatPointsPurchased(persist_read_int(PERSISTED_STAT_POINTS_PURCHASED));
	SetVibration(persist_read_bool(PERSISTED_VIBRATION));
	SetFastMode(persist_read_bool(PERSISTED_FAST_MODE));
	SetEasyMode(persist_read_bool(PERSISTED_EASY_MODE));
	
	CardSave saves[NB_TYPE_CARDS];
	persist_read_data(PERSISTED_CARD_DECK, saves, sizeof(saves));
	SetCardSave(saves);
	SetEntriesSize(persist_read_int(PERSISTED_ENTRIES_SIZE));	
	
	if(persist_read_bool(PERSISTED_IN_COMBAT))
	{
		persist_read_data(PERSISTED_MONSTER_TYPE, GetCurMonster(), sizeof(MonsterInfo));
		ResumeBattle();
	}
	if(characterData->level == 0)
	{
		// Something bad happened to the data, possible due to a watch crash
		ERROR_LOG("Persisted data was broken somehow, clearing");
		ClearPersistedData();
		return false;
	}
	return true;
}
Exemplo n.º 11
0
static void init(void) {
  //(void)ctx;
	
  app_message_register_inbox_received(in_received_handler);
  app_message_register_inbox_dropped(in_dropped_handler);
  app_message_open(64, 0);

  if(persist_exists(KEY_24H)) SHOW_24H = persist_read_bool(KEY_24H);
  if(persist_exists(KEY_DATE)) SHOW_TEXT_DATE = persist_read_bool(KEY_DATE);
  if(persist_exists(KEY_VIBE)) BT_VIBE = persist_read_bool(KEY_VIBE);
  if(persist_exists(KEY_INVERT)) INVERT = persist_read_bool(KEY_INVERT);
	
  if(INVERT) {
	  BACKGROUND_COLOR = GColorWhite;
	  FOREGROUND_COLOR = GColorBlack;
  }
  else {
	  BACKGROUND_COLOR = GColorBlack;
	  FOREGROUND_COLOR = GColorWhite;		 		 
  }
	
  window = window_create();
  window_set_background_color(window, BACKGROUND_COLOR);
  window_stack_push(window, true);

 
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);
	
  // Init the layer for the minute display
  minute_display_layer = layer_create(bounds);
  layer_set_update_proc(minute_display_layer, minute_display_layer_update_callback);
  layer_add_child(window_layer, minute_display_layer);

  // Init the layer for the hour display
  hour_display_layer = layer_create(bounds);
  layer_set_update_proc(hour_display_layer, hour_display_layer_update_callback);
  layer_add_child(window_layer, hour_display_layer);

  // Init the layer for the battery display
  battery_display_layer = layer_create(bounds);
  layer_set_update_proc(battery_display_layer, battery_display_layer_update_callback);
  layer_add_child(window_layer, battery_display_layer);
  
  setup_time_date_layers();
	
  tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
  bluetooth_connection_service_subscribe(handle_bluetooth_event); 
}
Exemplo n.º 12
0
void bluetoothHandler(bool connected) 
{
  APP_LOG(DebugLevel, "bluetoothHandler: start connected :%s:",connected ? "true" : "false");
  bool prevConnected=false;
  if(persist_exists(BT_STATUS)){
    prevConnected = persist_read_bool(BT_STATUS);
	APP_LOG(DebugLevel, "bluetoothHandler: initial key");
  }
	APP_LOG(DebugLevel, "bluetoothHandler: prevConnected :%s:",prevConnected ? "true" : "false");

  if(connected && prevConnected) {
     bitmap_layer_set_bitmap(GET_LAYER(BLUETOOTH_LAYER), bluetoothImageOn);
	  APP_LOG(DebugLevel, "bluetoothHandler: both true turned on connection");
  }
  if(!connected && !prevConnected) {
     bitmap_layer_set_bitmap(GET_LAYER(BLUETOOTH_LAYER), bluetoothImageOff);
	  APP_LOG(DebugLevel, "bluetoothHandler: both false turned off connection");
  }

  if(connected && !prevConnected) {
     bitmap_layer_set_bitmap(GET_LAYER(BLUETOOTH_LAYER), bluetoothImageOn);
	  APP_LOG(DebugLevel, "bluetoothHandler: turned on connection");
     vibes_short_pulse();
  }

  if(!connected && prevConnected) {
  	  bitmap_layer_set_bitmap(GET_LAYER(BLUETOOTH_LAYER), bluetoothImageOff);
	  APP_LOG(DebugLevel, "bluetoothHandler: turned off connection");
     vibes_long_pulse();
     btBuzzerTimer = app_timer_register(BUZZER_INTERVAL, buzzer2,NULL);
  }
  persist_write_bool(BT_STATUS, connected);
  APP_LOG(DebugLevel, "bluetoothHandler: done saved :%s:",connected ? "true" : "false");
} // bluetoothHandler
Exemplo n.º 13
0
bool read_bool(const uint32_t key, int32_t def_value) {
  if (persist_exists(key)) {
    return persist_read_bool(key);
  } else {
    return def_value;
  }
}
Exemplo n.º 14
0
static void handle_tap(AccelAxisType axis, int32_t direction) {
    persist_write_bool(STYLE_KEY, !persist_read_bool(STYLE_KEY));
    set_style();
    force_update();
    vibes_long_pulse();
    accel_tap_service_unsubscribe();
}
Exemplo n.º 15
0
static void window_load(Window *window)
{
    // Check for saved settings
    mInvertColors = persist_exists(KEY_INVERT) ? persist_read_bool(KEY_INVERT) : false;
    mBackColor = (mInvertColors) ? GColorWhite : GColorBlack;
    mForeColor = (mInvertColors) ? GColorBlack : GColorWhite;

    mStarSpeed = STAR_SPEED_SLOW;//persist_exists(KEY_STAR_SPEED) ? persist_read_int(KEY_STAR_SPEED) : STAR_SPEED_FAST;
    mFramerate = FRAMERATE_SMOOTH;//persist_exists(KEY_FRAMERATE) ? persist_read_int(KEY_FRAMERATE) : FRAMERATE_POWER;

	window_set_background_color(window, mBackColor);
	canvas = layer_create(GRect(0, 0, SCREEN_WIDTH , SCREEN_HEIGHT));
	layer_set_update_proc(canvas, (LayerUpdateProc) render);
	layer_add_child(window_get_root_layer(window), canvas);
    
    mFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_TETRIS_24));
	
	// Set initial time so display isn't blank
    mTimeText = NULL;
	struct tm *t;
	time_t temp;
	temp = time(NULL);
	t = localtime(&temp);
	set_time_display(t);

	start();
}
Exemplo n.º 16
0
static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  s_text_layer = text_layer_create(GRect(0, 50, bounds.size.w, 100));
  text_layer_set_text(s_text_layer, "App configuration choices will be reflected here!");
  text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter);
  text_layer_set_background_color(s_text_layer, GColorClear);
  layer_add_child(window_layer, text_layer_get_layer(s_text_layer));

  // Read saved config 
  if(persist_read_bool(KEY_HIGH_CONTRAST)) {
    // Apply high contrast mode
    window_set_background_color(s_main_window, GColorBlack);
    text_layer_set_text_color(s_text_layer, GColorWhite);
  } else {
#ifdef PBL_SDK_2
    // Not available, use normal colors
#elif PBL_SDK_3
    // Use background color setting
    int red = persist_read_int(KEY_COLOR_RED);
    int green = persist_read_int(KEY_COLOR_GREEN);
    int blue = persist_read_int(KEY_COLOR_BLUE);

    GColor bg_color = GColorFromRGB(red, green, blue);
    window_set_background_color(s_main_window, bg_color);
    text_layer_set_text_color(s_text_layer, gcolor_is_dark(bg_color) ? GColorWhite : GColorBlack);    
#endif
  }
}
Exemplo n.º 17
0
void config_init() {
  // Set defaults
  if(!persist_exists(PERSIST_DEFAULTS_SET)) {
    persist_write_bool(PERSIST_DEFAULTS_SET, true);

    persist_write_bool(PERSIST_KEY_DATE, false);
    persist_write_bool(PERSIST_KEY_STEPS, false);
    persist_write_bool(PERSIST_KEY_CLR_BW, true);
    persist_write_bool(PERSIST_KEY_CLR_ORANGE, false);
    persist_write_bool(PERSIST_KEY_CLR_GREEN, false);
    persist_write_bool(PERSIST_KEY_CLR_BLUE, false);
    persist_write_bool(PERSIST_KEY_WEATHER, false);
    persist_write_bool(PERSIST_KEY_BOLD_TEXT, false);
    persist_write_bool(PERSIST_KEY_BOLD_DOTS, false);
  }

  for(int i = 0; i < NUM_SETTINGS; i++) {
    s_arr[i] = persist_read_bool(i);
  }
  
  if (config_get(PERSIST_KEY_BOLD_DOTS)) {
    s_dotSize = DOT_SIZE_BOLD;
  } else {
    s_dotSize = DOT_SIZE_DEFAULT;
  }
}
Exemplo n.º 18
0
void strap_deinit() {
    if (!persist_read_bool(STRAP_OPT_OUT)) {
        persist_delete(STRAP_CRASH_WATCHER);
        strap_log_action("STRAP_FINISH");
        accl_deinit();
    }

}
Exemplo n.º 19
0
//! Test whether or not the persistent storage is working, by writing
//! and reading a value.
//! @return status code of write, negative values are bad.
StatusCode test_persist(void) {
  StatusCode write_status = persist_write_bool(STORAGE_TEST, true);
  bool test_bool = persist_read_bool(STORAGE_TEST);
  if (true != test_bool) {
    return -100;
  }
  return write_status;
}
Exemplo n.º 20
0
void options_init() {
	if(persist_exists(OPTION_LARGE_FONT))
		large_font = persist_read_bool(OPTION_LARGE_FONT);
	if(persist_exists(OPTION_TASK_ACTIONS_POSITION))
		task_actions_position = persist_read_int(OPTION_TASK_ACTIONS_POSITION);
	LOG("lg font? %d", large_font);
	LOG("act pos? %d", task_actions_position);
}
Exemplo n.º 21
0
// Load existing config from persistent storage
void load_config() {
  if (persist_exists(MESSAGE_KEY_INVERT)) {
    config_invert = persist_read_bool(MESSAGE_KEY_INVERT);
  }
  if (persist_exists(MESSAGE_KEY_DATE_FORMAT)) {
    config_date_format = persist_read_int(MESSAGE_KEY_DATE_FORMAT);
  }
}
Exemplo n.º 22
0
void bt_handler(bool connected) {
	if (!connected) {
		if (persist_read_bool(KEY_VIBE_BT)) {
			vibes_short_pulse();
		}
		
		//show_message(COLOR_FALLBACK(GColorBlueMoon, GColorWhite), 5000, "BT lost");
	}
}
Exemplo n.º 23
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  APP_LOG(APP_LOG_LEVEL_INFO, "message received");

  Tuple *start_immediately = dict_find(iterator, KEY_START_IMMEDIATELY);
  if (start_immediately) {
    APP_LOG(APP_LOG_LEVEL_INFO, "remember KEY_START_IMMEDIATELY=%d", start_immediately->value->uint8);
    persist_write_bool(KEY_START_IMMEDIATELY, start_immediately->value->uint8);
  }

  Tuple *enable_confirmation_dialog = dict_find(iterator, KEY_ENABLE_CONFIRMATION_DIALOG);
  if (enable_confirmation_dialog) {
    APP_LOG(APP_LOG_LEVEL_INFO, "remember KEY_ENABLE_CONFIRMATION_DIALOG=%d", enable_confirmation_dialog->value->uint8);
    persist_write_bool(KEY_ENABLE_CONFIRMATION_DIALOG, enable_confirmation_dialog->value->uint8);
    dictation_session_enable_confirmation(s_dictation_session, persist_read_bool(KEY_ENABLE_CONFIRMATION_DIALOG));
  }

  Tuple *enable_error_dialog = dict_find(iterator, KEY_ENABLE_ERROR_DIALOG);
  if (enable_error_dialog) {
    APP_LOG(APP_LOG_LEVEL_INFO, "remember KEY_ENABLE_ERROR_DIALOG=%d", enable_error_dialog->value->uint8);
    persist_write_bool(KEY_ENABLE_ERROR_DIALOG, enable_error_dialog->value->uint8);
    dictation_session_enable_error_dialogs(s_dictation_session, persist_read_bool(KEY_ENABLE_ERROR_DIALOG));
  }

  Tuple *status = dict_find(iterator, KEY_STATUS);
  Tuple *text = dict_find(iterator, KEY_TEXT);
  if (status) {
    if (status->value->uint8 == 255) { // configuration was opened, disable auto exit
      auto_exit_enable = false;
    } else if (status->value->uint8 == 0) {
      if (text) {
        show_text(text->value->cstring, GColorFromHEX(0x000000), GColorFromHEX(0x00ff00));
      } else {
        show_text("OK", GColorFromHEX(0x000000), GColorFromHEX(0x00ff00));
      }
    } else {
      if (text) {
        show_text(text->value->cstring, GColorFromHEX(0xffffff), GColorFromHEX(0xff0000));
      } else {
        show_text("ERROR", GColorFromHEX(0xffffff), GColorFromHEX(0xff0000));
      }
    }
    timeout_timer = app_timer_register(EXIT_TIMEOUT, exit_timeout, NULL);
  }
}
Exemplo n.º 24
0
static void window_load(Window *window) {
	Layer *window_layer = window_get_root_layer(window);
	
	font_last_price_small = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIAVLO_MEDIUM_39));
	font_last_price_large = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIAVLO_MEDIUM_39));
  font_hash_large = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIAVLO_MEDIUM_39));
	
	text_five_layer = text_layer_create(GRect(0, 0, 144-0, 168-0));
	text_layer_set_text_color(text_five_layer, GColorWhite);
	text_layer_set_background_color(text_five_layer, GColorClear);
	text_layer_set_font(text_five_layer, font_last_price_large);
	text_layer_set_text_alignment(text_five_layer, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(text_five_layer));
  
  text_hash_layer = text_layer_create(GRect(0, 64, 144-0, 168-40));
	text_layer_set_text_color(text_hash_layer, GColorWhite);
	text_layer_set_background_color(text_hash_layer, GColorClear);
	text_layer_set_font(text_hash_layer, fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21));
	text_layer_set_text_alignment(text_hash_layer, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(text_hash_layer));
  

	
	
	text_date_layer = text_layer_create(GRect(8, 96, 144-8, 168-96));
	text_layer_set_text_color(text_date_layer, GColorWhite);
	text_layer_set_background_color(text_date_layer, GColorClear);
	text_layer_set_font(text_date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIAVLO_15)));
	layer_add_child(window_layer, text_layer_get_layer(text_date_layer));
	
	text_time_layer = text_layer_create(GRect(7, 114, 144-7, 168-114));
	text_layer_set_text_color(text_time_layer, GColorWhite);
	text_layer_set_background_color(text_time_layer, GColorClear);
	text_layer_set_font(text_time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIAVLO_HEAVY_44)));
	layer_add_child(window_layer, text_layer_get_layer(text_time_layer));
	
	tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
	
	time_t now = time(NULL);
	struct tm *t = localtime(&now);
	update_time(t);
	
	Tuplet initial_values[] = {
		TupletCString(FIVE_HASH, "---"),
    //TupletCString(FIVE_HASH, "---"),
//		TupletCString(HOUR_HASH, "---"),
		TupletInteger(INVERT_COLOR_KEY, persist_read_bool(INVERT_COLOR_KEY)),
	};
	
	app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values),
				  sync_tuple_changed_callback, sync_error_callback, NULL);
	
	//send_cmd();last_price
	timer = app_timer_register(2000, timer_callback, NULL);
	//set_timer();
}
Exemplo n.º 25
0
void handle_init() {
  keyIndex = (persist_exists(KEY_INDEX_KEY) ? persist_read_int(KEY_INDEX_KEY) : 0);

  unsigned char offset = '0';
  unsigned char rawDST = 'N';
  unsigned char rawCount = '1';

  resource_load_byte_range(resource_get_handle(RESOURCE_ID_GMT_OFFSET), 0, &offset, 1);

  timeZoneIndex = (persist_exists(TIME_ZONE_KEY) ? persist_read_int(TIME_ZONE_KEY) : (offset - '0'));

  resource_load_byte_range(resource_get_handle(RESOURCE_ID_IS_DST), 0, &rawDST, 1);

  isDST = (persist_exists(IS_DST_KEY) ? persist_read_bool(IS_DST_KEY) : (rawDST == 'Y'));

  resource_load_byte_range(resource_get_handle(RESOURCE_ID_SECRET_COUNT), 0, &rawCount, 1);

  keyCount = rawCount - '0';
  
  window = window_create();
  window_stack_push(window, true /* Animated */);

  //Great for debugging the layout.
  //window_set_background_color(&window, GColorBlack);

  Layer* rootLayer = window_get_root_layer(window);
  GRect rootLayerRect = layer_get_bounds(rootLayer);
  barLayer = layer_create(GRect(0,70,rootLayerRect.size.w,5));
  layer_set_update_proc(barLayer, bar_layer_update);
  layer_add_child(rootLayer, barLayer);

  currentKey = text_layer_create(GRect(0,0,rootLayerRect.size.w,22));
  text_layer_set_font(currentKey, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  text_layer_set_text_alignment(currentKey, GTextAlignmentCenter);
  layer_add_child(rootLayer, text_layer_get_layer(currentKey));

  currentCode = text_layer_create(GRect(0,32,rootLayerRect.size.w,36));
  text_layer_set_font(currentCode, fonts_get_system_font(FONT_KEY_BITHAM_34_MEDIUM_NUMBERS));
  text_layer_set_text_alignment(currentCode, GTextAlignmentCenter);
  layer_add_child(rootLayer, text_layer_get_layer(currentCode));

  currentTime = text_layer_create(GRect(0,rootLayerRect.size.h-(15+22),(rootLayerRect.size.w/3)*2,22));
  text_layer_set_font(currentTime, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  text_layer_set_text_alignment(currentTime, GTextAlignmentLeft);
  layer_add_child(rootLayer, text_layer_get_layer(currentTime));

  currentOffset = text_layer_create(GRect((rootLayerRect.size.w/3)*2,rootLayerRect.size.h-(15+22),rootLayerRect.size.w/3,22));
  text_layer_set_font(currentOffset, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  text_layer_set_text_alignment(currentOffset, GTextAlignmentRight);
  layer_add_child(rootLayer, text_layer_get_layer(currentOffset));

  // Attach our desired button functionality
  window_set_click_config_provider(window, (ClickConfigProvider) click_config_provider);

  reload();
}
Exemplo n.º 26
0
void vlc_init(Player p) {
	player = p;

	controlling_volume = persist_exists(KEY_VLC_CONTROLLING_VOLUME) ? persist_read_bool(KEY_VLC_CONTROLLING_VOLUME) : true;

	window = window_create();
	window_set_window_handlers(window, (WindowHandlers) {
		.load = window_load,
		.unload = window_unload,
	});
Exemplo n.º 27
0
bool LoadPersistedData(void)
{
	CharacterData *characterData;
	int floor = 0;
	bool useWorkerApp = false;
	if(!persist_exists(PERSISTED_IS_DATA_SAVED) || !persist_read_bool(PERSISTED_IS_DATA_SAVED))
		return false;
		
	if(!IsPersistedDataCurrent())
	{
		WARNING_LOG("Persisted data does not match current version, clearing.");
		ClearPersistedData();
		return false;
	}

	ProfileLogStart("LoadPersistedData");
	INFO_LOG("Loading persisted data.");
	characterData = GetCharacter();
	persist_read_data(PERSISTED_CHARACTER_DATA, characterData, sizeof(CharacterData));
	floor = persist_read_int(PERSISTED_CURRENT_FLOOR);
	SetCurrentFloor(floor);
	persist_read_data(PERSISTED_ITEM_DATA, GetItemsOwned(), GetSizeOfItemsOwned());
	SetStatPointsPurchased(persist_read_int(PERSISTED_STAT_POINTS_PURCHASED));
	SetVibration(persist_read_bool(PERSISTED_VIBRATION));
	SetFastMode(persist_read_bool(PERSISTED_FAST_MODE));
	if(persist_exists(PERSISTED_USE_OLD_ASSETS))
		SetUseOldAssets(persist_read_bool(PERSISTED_USE_OLD_ASSETS));
	useWorkerApp = persist_read_bool(PERSISTED_WORKER_APP);
	if(useWorkerApp)
	{
		AttemptToLaunchWorkerApp();
	}
	else
	{
		// If the user has launched the worker app outside of MiniDungeon,
		// they want it on.
		if(WorkerIsRunning())
			SetWorkerApp(true);
	}
	SetWorkerCanLaunch(persist_read_bool(PERSISTED_WORKER_CAN_LAUNCH));

	if(persist_read_bool(PERSISTED_IN_COMBAT))
	{
		int currentMonster = persist_read_int(PERSISTED_MONSTER_TYPE);
		int currentMonsterHealth = persist_read_int(PERSISTED_MONSTER_HEALTH);
		ResumeBattle(currentMonster, currentMonsterHealth);
	}
	ProfileLogStop("LoadPersistedData");
	if(characterData->level == 0)
	{
		// Something bad happened to the data, possible due to a watch crash
		ERROR_LOG("Persisted data was broken somehow, clearing");
		ClearPersistedData();
		return false;
	}
	return true;
}
Exemplo n.º 28
0
static void set_style(void) {
    bool inverse = persist_read_bool(STYLE_KEY);
    
    GColor background_color  = inverse ? GColorWhite : GColorBlack;
    
    window_set_background_color(window, background_color);

    simplebig_set_style(inverse);
    status_set_style(inverse);
    termo_set_style(inverse);
}
Exemplo n.º 29
0
bool IsPersistedDataCurrent(void)
{
	bool dataSaved = persist_read_bool(PERSISTED_IS_DATA_SAVED);
	int savedVersion;
	if(!dataSaved)
		return true;
	
	savedVersion = persist_read_int(PERSISTED_CURRENT_DATA_VERSION);
	
	return savedVersion == CURRENT_DATA_VERSION;
}
Exemplo n.º 30
0
static void init() {  
  // read in initial settings values (note these return false if key is not set)
  use_12h_time = persist_read_bool(KEY_12H_TIME);
  hide_battery = persist_read_bool(KEY_HIDE_BATTERY);
  hide_date = persist_read_bool(KEY_HIDE_DATE);
  
  // listen for appmessage updates (currently, only settings updates)
  app_message_register_inbox_received(handle_inbox_received);
  app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
  
  // init array for storing date string
  date_string = malloc(DATE_STRING_LEN * sizeof(char));
  
  // create main Window (black background), associate handlers, and display
  s_main_window = window_create();
  window_set_background_color(s_main_window, GColorBlack);
  window_set_window_handlers(s_main_window, (WindowHandlers) {
    .load = main_window_load,
    .unload = main_window_unload
  });