void WeatherPlugin::element_start(const char *el, const char **attr) { m_bData = false; if (!strcmp(el, "cc")){ m_bCC = true; return; } if (!strcmp(el, "bar")){ m_bBar = true; return; } if (!strcmp(el, "wind")){ m_bWind = true; return; } if (!strcmp(el, "uv")) { m_bUv = true; return; } if (!strcmp(el, "moon")) { m_bMoon = true; return; } if (!strcmp(el, "day")){ string wday; string day; for (const char **p = attr; *p;){ string key = *(p++); string value = *(p++); if (key == "d"){ m_day = strtol(value.c_str(),NULL,10); continue; } if (key == "dt"){ day = value; continue; } if (key == "t"){ wday = value; continue; } if (m_day > getForecast()){ m_day = 0; continue; } } m_day++; setDay(m_day, day.c_str()); setWDay(m_day, wday.c_str()); return; } for (const char **p = tags; *p; p++){ if (!strcmp(*p, el)){ m_bData = true; m_data = ""; return; } } }
void WeatherPlugin::timeout() { if (!getSocketFactory()->isActive() || !isDone() || (*getID() == 0)) return; time_t now = time(NULL); if ((unsigned)now < getTime() + CHECK1_INTERVAL) return; m_bForecast = false; if ((unsigned)now >= getForecastTime() + CHECK2_INTERVAL) m_bForecast = true; string url = "http://xoap.weather.com/weather/local/"; url += getID(); url += "?cc=*&prod=xoap&par=1004517364&key=a29796f587f206b2&unit="; url += getUnits() ? "s" : "m"; if (m_bForecast && getForecast()){ url += "&dayf="; url += number(getForecast()); } fetch(url.c_str()); }
void WeatherPlugin::updateButton() { if ((getTime() == 0) || (m_bar == NULL)) return; const char **xpm = xpms[getIcon()]; if (xpm){ IconDef icon; icon.name = "weather"; icon.xpm = xpm; Event eIcon(EventAddIcon, &icon); eIcon.process(); } QString text = unquoteText(getButtonText()); QString tip = getTipText(); QString ftip = getForecastText(); text = replace(text); tip = replace(tip); if (getForecast()) tip = QString("<table><tr><td>") + tip + "</td><td>"; unsigned n = (getForecast() + 1) / 2; if (n < 3) n = getForecast(); for (m_day = 1; m_day <= getForecast(); m_day++){ tip += forecastReplace(ftip); const char **xpm = xpms[atol(getDayIcon(m_day))]; if (xpm){ string url = "weather"; url += number(m_day); IconDef icon; icon.name = url.c_str(); icon.xpm = xpm; Event eIcon(EventAddIcon, &icon); eIcon.process(); } if (--n == 0){ tip += "</td><td>"; n = (getForecast() + 1) / 2; } } if (getForecast()) tip += "</td></tr></table>"; tip += "<br>\nWeather data provided by weather.com"; tip += QChar((unsigned short)176); Command cmd; cmd->id = CmdWeather; cmd->param = m_bar; Event e(EventCommandWidget, cmd); CToolButton *btn = (CToolButton*)e.process(); if (btn == NULL) return; btn->setTextLabel(text); btn->repaint(); QToolTip::add(btn, tip); }
void WeatherPlugin::init() { addAuthor( QT_TRANSLATE_NOOP( "Author", "Nikita Belov" ), QT_TRANSLATE_NOOP( "Task", "Developer" ), QLatin1String("*****@*****.**") ); setInfo( QT_TRANSLATE_NOOP("Plugin", "Weather plugin"), QT_TRANSLATE_NOOP("Plugin", "Plugin shows a current weather in your city."), PLUGIN_VERSION( 0, 0, 1, 0 ), ExtensionIcon( QIcon( ":/icons/weather.png" ) ) ); setCapabilities(Loadable); ActionGenerator *gen = new ActionGenerator(QIcon(":/icons/weather.png"), QT_TRANSLATE_NOOP("Weather", "Get weather"), SLOT(getWeather())); MenuController::addAction<WContact>(gen); gen = new ActionGenerator(QIcon(":/icons/weather.png"), QT_TRANSLATE_NOOP("Weather", "Get weather forecast"), SLOT(getForecast())); MenuController::addAction<WContact>(gen); }
void WeatherPlugin::updateButton() { if ((getTime() == 0) || (m_bar == NULL)) return; weather_icon = "weather"; weather_icon += number(getIcon()); Command cmd; cmd->id = CmdWeather; cmd->text = I18N_NOOP("Not connected"); cmd->icon = weather_icon.c_str(); cmd->bar_id = BarWeather; cmd->bar_grp = 0x1000; cmd->flags = BTN_PICT | BTN_DIV; Event eCmd(EventCommandChange, cmd); eCmd.process(); QString text = unquoteText(getButtonText()); QString tip = getTipText(); QString ftip = getForecastText(); text = replace(text); tip = replace(tip); if (getForecast()) tip = QString("<table><tr><td>") + tip + "</td><td>"; unsigned n = (getForecast() + 1) / 2; if (n < 3) n = getForecast(); for (m_day = 1; m_day <= getForecast(); m_day++){ tip += forecastReplace(ftip); if (--n == 0){ tip += "</td><td>"; n = (getForecast() + 1) / 2; } } if (getForecast()) tip += "</td></tr></table>"; tip += "<br>\nWeather data provided by weather.com"; tip += QChar((unsigned short)174); Command cmdw; cmdw->id = CmdWeather; cmdw->param = m_bar; Event e(EventCommandWidget, cmdw); CToolButton *btn = (CToolButton*)e.process(); if (btn == NULL) return; btn->setTextLabel(text); btn->repaint(); QToolTip::add(btn, tip); }
static void canvas_update_proc(Layer *this_layer, GContext *ctx) { GRect bounds = layer_get_bounds(this_layer); uint16_t ms_start = time_ms(NULL, NULL); graphics_context_set_antialiased(ctx, true); if (!isBtConnected) { graphics_context_set_fill_color(ctx, GColorDukeBlue); graphics_fill_rect(ctx, bounds, 0, GCornerNone); } else { graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, bounds, 0, GCornerNone); } graphics_context_set_fill_color(ctx, GColorBlack); uint16_t ms_fill = time_ms(NULL, NULL); graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorRed, GColorWhite)); #if defined(PBL_PLATFORM_APLITE) || defined(PBL_PLATFORM_DIORITE) graphics_context_set_stroke_width(ctx, 1); #else graphics_context_set_stroke_width(ctx, 3); #endif graphics_draw_line(ctx, GPoint(bounds.size.w/2, 0), GPoint(bounds.size.w/2, bounds.size.h)); graphics_context_set_stroke_color(ctx, GColorWhite); int hour_loc = bounds.size.h/2; if(ctick_time->tm_min < 20) draw_hour(this_layer, ctx, -1, tz2, hour_loc, FONT_KEY_ROBOTO_BOLD_SUBSET_49, 49); draw_hour(this_layer, ctx, 0, tz2, hour_loc, FONT_KEY_ROBOTO_BOLD_SUBSET_49, 49); draw_hour(this_layer, ctx, 1, tz2, hour_loc, FONT_KEY_ROBOTO_BOLD_SUBSET_49, 49); if(ctick_time->tm_min > 50) draw_hour(this_layer, ctx, 2, tz2, hour_loc, FONT_KEY_ROBOTO_BOLD_SUBSET_49, 49); graphics_context_set_stroke_width(ctx, 1); uint16_t ms_hour = time_ms(NULL, NULL); draw_minutes(this_layer, ctx, bounds.size.h/2+49/2+5); uint16_t ms_day = time_ms(NULL, NULL); int day_loc = bounds.size.h/2-49/2-12; draw_day(this_layer, ctx, -1, day_loc); draw_day(this_layer, ctx, 0, day_loc); draw_day(this_layer, ctx, 1, day_loc); draw_day(this_layer, ctx, 2, day_loc); draw_day_ticks(this_layer, ctx, bounds.size.h/2-49/2-12); if (temp != INVALID_TEMP) { draw_temp(this_layer, ctx, bounds.size.h/2+75); } getWeather(); getForecast(); uint16_t ms_end = time_ms(NULL, NULL); draw_bat(this_layer, ctx, 0); #if defined(PBL_HEALTH) // Check step data is available HealthServiceAccessibilityMask mask = health_service_metric_accessible(HealthMetricStepCount, time_start_of_today(), cur_time); if(mask & HealthServiceAccessibilityMaskAvailable) { // Data is available! int total_steps = (int)health_service_sum_today(HealthMetricStepCount); draw_step(this_layer, ctx, 22, total_steps); } time_t end_time = time(NULL); time_t start_time = end_time - 600; HealthServiceAccessibilityMask hr = health_service_metric_accessible(HealthMetricHeartRateBPM, start_time, end_time); if (hr & HealthServiceAccessibilityMaskAvailable) { uint32_t bpm = health_service_peek_current_value(HealthMetricHeartRateBPM); APP_LOG(APP_LOG_LEVEL_INFO, "HR: %d", (int)bpm); draw_bpm(this_layer, ctx, 9, bpm); } #endif static int repaints = 0; ++repaints; ms_fill = ms_fill < ms_start ? ms_fill + 1000 : ms_fill; ms_hour = ms_hour < ms_start ? ms_hour + 1000 : ms_hour; ms_day = ms_day < ms_start ? ms_day + 1000 : ms_day; ms_end = ms_end < ms_start ? ms_end + 1000 : ms_end; static uint16_t tt_max = 0; if ((ms_end-ms_start) > tt_max) tt_max = ms_end-ms_start; }
static void inbox_received_callback(DictionaryIterator *iterator, void *context) { // Get the first pair Tuple *data = dict_read_first(iterator); while (data) { APP_LOG(APP_LOG_LEVEL_INFO, "Key received: %d", (int)data->key); if (data->key == MESSAGE_KEY_AppKeyReady) { isJSRunning = true; getWeather(); getForecast(); } else if (data->key == MESSAGE_KEY_TEMP) { temp = data->value->int32; temp_age = cur_time; persist_write_int(MESSAGE_KEY_TEMP, temp); persist_write_int(MESSAGE_KEY_CONFIG_TEMP_AGE, cur_time); APP_LOG(APP_LOG_LEVEL_INFO, "Temp received: %d", temp); } else if (data->key == MESSAGE_KEY_TEMP_FORE_MIN) { temp_fore_min = data->value->int32; persist_write_int(MESSAGE_KEY_TEMP_FORE_MIN, temp_fore_min); persist_write_int(MESSAGE_KEY_CONFIG_FORE_AGE, cur_time); temp_fore_age = cur_time; APP_LOG(APP_LOG_LEVEL_INFO, "Temp min received: %d", temp_fore_min); } else if (data->key == MESSAGE_KEY_TEMP_FORE_MAX) { temp_fore_max = data->value->int32; persist_write_int(MESSAGE_KEY_TEMP_FORE_MAX, temp_fore_max); persist_write_int(MESSAGE_KEY_CONFIG_FORE_AGE, cur_time); temp_fore_age = cur_time; APP_LOG(APP_LOG_LEVEL_INFO, "Temp max received: %d", temp_fore_max); } else if (data->key == MESSAGE_KEY_CONFIG_TZ_OFFSET) { switch (data->type) { case TUPLE_BYTE_ARRAY: APP_LOG(APP_LOG_LEVEL_INFO, "tz2 can't handle a byte array"); break; case TUPLE_CSTRING: { char *str = data->value->cstring; bool neg = false; if (str[0] == '-') { neg = true; str += 1; } else if(str[0] == '+') { str += 1; } tz2 = atoi(str); if (neg) { tz2 *= -1; } break; } case TUPLE_INT: case TUPLE_UINT: tz2 = data->value->int32; break; } persist_write_int(MESSAGE_KEY_CONFIG_TZ_OFFSET, tz2); APP_LOG(APP_LOG_LEVEL_INFO, "Tz2: %d type: %d", tz2, data->type); } else if(data->key == MESSAGE_KEY_CONFIG_METRIC) { metric = data->value->int8; persist_write_int(MESSAGE_KEY_CONFIG_METRIC, metric); APP_LOG(APP_LOG_LEVEL_INFO, "Metric: %d %ld %d %d", metric, data->value->int32, data->value->int16, data->type); } else if(data->key == MESSAGE_KEY_CONFIG_BUZZ) { buzz = data->value->int8; persist_write_int(MESSAGE_KEY_CONFIG_BUZZ, buzz); APP_LOG(APP_LOG_LEVEL_INFO, "Buzz: %d", buzz); } else if(data->key == MESSAGE_KEY_CONFIG_BUZZ_MUTE) { buzz_mute = data->value->int8; persist_write_int(MESSAGE_KEY_CONFIG_BUZZ_MUTE, buzz_mute); APP_LOG(APP_LOG_LEVEL_INFO, "Buzz Mute: %d", buzz_mute); } data = dict_read_next(iterator); } layer_mark_dirty(s_layer); }