void in_received_handler(DictionaryIterator *received, void *context) {
	bool somethingChanged = false;
		
	Tuple *dateorder = dict_find(received, CONFIG_KEY_DATEORDER);
	Tuple *weekday = dict_find(received, CONFIG_KEY_WEEKDAY);
	Tuple *lang = dict_find(received, CONFIG_KEY_LANG);
	Tuple *stripes = dict_find(received, CONFIG_KEY_STRIPES);
	
	if (dateorder && weekday && lang && stripes) {
		APP_LOG(APP_LOG_LEVEL_DEBUG, "Received config (dateorder=%d, weekday=%d, lang=%d, stripes=%d)",
				(int)dateorder->value->int32, (int)weekday->value->int32, (int)lang->value->int32,
				(int)stripes->value->int32);
		
		somethingChanged |= checkAndSaveInt(&USDate, dateorder->value->int32, CONFIG_KEY_DATEORDER);
		somethingChanged |= checkAndSaveInt(&showWeekday, weekday->value->int32, CONFIG_KEY_WEEKDAY);
		somethingChanged |= checkAndSaveInt(&curLang, lang->value->int32, CONFIG_KEY_LANG);
		stripedDigitsChanged |= checkAndSaveInt(&stripedDigits, stripes->value->int32, CONFIG_KEY_STRIPES);
				
		if (somethingChanged) {
			applyConfig();
		} else if (stripedDigitsChanged) {
			stripedDigitsChanged = false;
			redrawAllSlots();
		}
	}
}
Esempio n. 2
0
void decodeThemeCode(char *code) {
#ifdef PBL_COLOR
  int i;

  for (i=0; i<6; i++) {
    color[COLOR_THEME_CUSTOM][i] = (GColor8){.argb=(uint8_t)hexStringToByte(code + 2*i)};
  }
#else
  // Do nothing on APLITE
#endif
}

void in_dropped_handler(AppMessageResult reason, void *context) {
}

void in_received_handler(DictionaryIterator *received, void *context) {
  bool somethingChanged = false;
  bool digitShapesHaveToBeSwapped = false;
  bool colorThemeChanged = false;

  Tuple *dateorder = dict_find(received, CONFIG_KEY_DATEORDER);
  Tuple *weekday = dict_find(received, CONFIG_KEY_WEEKDAY);
  Tuple *battery = dict_find(received, CONFIG_KEY_BATTERY);
  Tuple *bluetooth = dict_find(received, CONFIG_KEY_BLUETOOTH);
  Tuple *invert = dict_find(received, CONFIG_KEY_INVERT);
  Tuple *lang = dict_find(received, CONFIG_KEY_LANG);
  Tuple *stripes = dict_find(received, CONFIG_KEY_STRIPES);
  Tuple *corners = dict_find(received, CONFIG_KEY_ROUNDCORNERS);
  Tuple *digits = dict_find(received, CONFIG_KEY_FULLDIGITS);
  Tuple *colorThemeTuple = dict_find(received, CONFIG_KEY_COLORTHEME);
  Tuple *themeCodeTuple = dict_find(received, CONFIG_KEY_THEMECODE);

  if (dateorder && weekday && battery && bluetooth && invert && lang && stripes && corners && digits && colorThemeTuple && themeCodeTuple) {
    somethingChanged |= checkAndSaveInt(&USDate, dateorder->value->int32, CONFIG_KEY_DATEORDER);
    somethingChanged |= checkAndSaveInt(&showWeekday, weekday->value->int32, CONFIG_KEY_WEEKDAY);
    somethingChanged |= checkAndSaveInt(&curLang, lang->value->int32, CONFIG_KEY_LANG);

    checkAndSaveInt(&batteryStatus, battery->value->int32, CONFIG_KEY_BATTERY);
    checkAndSaveInt(&bluetoothStatus, bluetooth->value->int32, CONFIG_KEY_BLUETOOTH);

    digitShapesChanged = false;
    digitShapesChanged |= checkAndSaveInt(&invertStatus, invert->value->int32, CONFIG_KEY_INVERT);

    colorThemeChanged = checkAndSaveString(themeCodeText, themeCodeTuple->value->cstring, CONFIG_KEY_THEMECODE);
    digitShapesChanged |= colorThemeChanged;

    digitShapesChanged |= checkAndSaveInt(&stripedDigits, stripes->value->int32, CONFIG_KEY_STRIPES);
    digitShapesChanged |= checkAndSaveInt(&roundCorners, corners->value->int32, CONFIG_KEY_ROUNDCORNERS);

    digitShapesHaveToBeSwapped = checkAndSaveInt(&fullDigits, digits->value->int32, CONFIG_KEY_FULLDIGITS);
    digitShapesChanged |= digitShapesHaveToBeSwapped;
    digitShapesChanged |= checkAndSaveInt(&colorTheme, colorThemeTuple->value->int32, CONFIG_KEY_COLORTHEME);

    APP_LOG(APP_LOG_LEVEL_DEBUG, "Received config:");
    APP_LOG(APP_LOG_LEVEL_DEBUG, "  dateorder=%d, weekday=%d, battery=%d, BT=%d, invert=%d, lang=%d",
            USDate, showWeekday, batteryStatus, bluetoothStatus, invertStatus, curLang);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "  stripes=%d, corners=%d, digits=%d, colorTheme=%d",
            stripedDigits, roundCorners, fullDigits, colorTheme);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "  themeCodeText=%s", themeCodeText);

    if (colorThemeChanged) {
      decodeThemeCode(themeCodeText);
    }

    if (digitShapesHaveToBeSwapped) {
      swapDigitShapes();
    }

    if (somethingChanged) {
      applyConfig();
    }

    if (digitShapesChanged) {
      digitShapesChanged = false;
      redrawAllSlots();
    }
  }
}