コード例 #1
0
static void getweather_callback(byte status, uint16_t off, uint16_t len) {
#if defined(ARDUINO)
  char *p = (char*)Ethernet::buffer + off;
#else
  char *p = ether_buffer;
#endif
  /* scan the buffer until the first & symbol */
  while(*p && *p!='&') {
    p++;
  }
  if (*p != '&')  return;
  int v;
  if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("sunrise"), true)) {
    v = atoi(tmp_buffer);
    if (v>=0 && v<=1440) {
      os.nvdata.sunrise_time = v;
    }
  }

  if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("sunset"), true)) {
    v = atoi(tmp_buffer);
    if (v>=0 && v<=1440) {
      os.nvdata.sunset_time = v;
    }
  }
  os.nvdata_save(); // save non-volatile memory

  if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("scale"), true)) {
    v = atoi(tmp_buffer);
    if (v>=0 && v<=250 && v != os.options[OPTION_WATER_PERCENTAGE].value) {
      // only save if the value has changed
      os.options[OPTION_WATER_PERCENTAGE].value = v;
      os.options_save();
    }
  }
  
  if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("tz"), true)) {
    v = atoi(tmp_buffer);
    if (v>=0 && v<= 96) {
      if (v != os.options[OPTION_TIMEZONE].value) {
        // if timezone changed, save change and force ntp sync
        os.options[OPTION_TIMEZONE].value = v;
        os.options_save();
      }
    }
  }
  
  if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("eip"), true)) {
    os.external_ip = atol(tmp_buffer);
  }
  os.checkwt_success_lasttime = os.now_tz();
}
コード例 #2
0
ファイル: hashmap.c プロジェクト: kbhaines/hashmap
const void *getValue(HashMap *hm, const char *key) {
    KeyVal *kv = findKeyVal(hm, key);
    if (kv) {
        return kv -> value;
    }
    return NULL;
}
コード例 #3
0
static void getweather_callback(byte status, uint16_t off, uint16_t len) {
#if defined(ARDUINO)
  char *p = (char*)Ethernet::buffer + off;
#else
  char *p = ether_buffer;
#endif
  /* scan the buffer until the first & symbol */
  while(*p && *p!='&') {
    p++;
  }
  if (*p != '&')  return;
  int v;
  if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("sunrise"), true)) {
    v = atoi(tmp_buffer);
    if (v>=0 && v<=1440 && v != os.nvdata.sunrise_time) {
      os.nvdata.sunrise_time = v;
      os.nvdata_save();
      os.weather_update_flag |= WEATHER_UPDATE_SUNRISE;
    }
  }

  if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("sunset"), true)) {
    v = atoi(tmp_buffer);
    if (v>=0 && v<=1440 && v != os.nvdata.sunset_time) {
      os.nvdata.sunset_time = v;
      os.nvdata_save();
      os.weather_update_flag |= WEATHER_UPDATE_SUNSET;      
    }
  }
  
  if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("et0"), true)) {
    v = atoi(tmp_buffer);
    v += os.nvdata.ethist[0];
	if (v != os.nvdata.water_balance[0]) {
		os.nvdata.water_balance[0] = v;
		os.nvdata_save();
		os.weather_update_flag |= WEATHER_UPDATE_ET0
    }
コード例 #4
0
ファイル: hashmap.c プロジェクト: kbhaines/hashmap
const char *putValue(HashMap *hm, const char *key, const void *value) {

    int idx = hm->hashFunc(key);
    if (idx >= MAX_BUCKETS) {
        return NULL;
    }

    KeyVal *updateKv = findKeyVal(hm, key);
    if (updateKv) {
        updateKv -> value = value;
        return key;
    }

    KeyVal *oldHeadKv = hm->buckets[idx];
    KeyVal *newKv = malloc(sizeof(KeyVal));
    newKv->key = strdup(key);
    newKv->value = value;
    newKv->next  = oldHeadKv;
    hm->buckets[idx] = newKv;
    hm->numItems++;
    return key;
}