Improve update logic
This commit is contained in:
parent
5f3f911a1a
commit
22bde518ba
@ -73,12 +73,11 @@ void plex::update(){
|
|||||||
|
|
||||||
//fetch updates
|
//fetch updates
|
||||||
//CURL object has been setup in the constructor
|
//CURL object has been setup in the constructor
|
||||||
CURLcode res = curl_easy_perform(api_curl);
|
curl_easy_perform(api_curl);
|
||||||
|
|
||||||
//parse the result
|
//parse the result
|
||||||
json_doc.Parse(json_string.c_str());
|
json_doc.Parse(json_string.c_str());
|
||||||
|
entries.clear();
|
||||||
std::cerr << json_string << "\n";
|
|
||||||
|
|
||||||
//update internal state
|
//update internal state
|
||||||
rapidjson::Value& curr_entry = json_doc["response"]["data"]["data"];
|
rapidjson::Value& curr_entry = json_doc["response"]["data"]["data"];
|
||||||
@ -101,6 +100,7 @@ void plex::update(){
|
|||||||
std::cerr << entries[i].state << "\n";
|
std::cerr << entries[i].state << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
json_string.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
@ -130,6 +130,7 @@ void plex::update_texture(){
|
|||||||
constexpr int GAP_SIZE = 10;
|
constexpr int GAP_SIZE = 10;
|
||||||
|
|
||||||
//draw the outline rectangles
|
//draw the outline rectangles
|
||||||
|
{
|
||||||
tgt.x = GAP_SIZE;
|
tgt.x = GAP_SIZE;
|
||||||
tgt.y = DEF_OVERLAY_BAR_HEIGHT + GAP_SIZE;
|
tgt.y = DEF_OVERLAY_BAR_HEIGHT + GAP_SIZE;
|
||||||
tgt.w = (SCREEN_WIDTH / 3) - (2*GAP_SIZE);
|
tgt.w = (SCREEN_WIDTH / 3) - (2*GAP_SIZE);
|
||||||
@ -159,6 +160,7 @@ void plex::update_texture(){
|
|||||||
tgt.w = (SCREEN_WIDTH / 3) - (2*GAP_SIZE);
|
tgt.w = (SCREEN_WIDTH / 3) - (2*GAP_SIZE);
|
||||||
tgt.h = (SCREEN_HEIGHT) - (2*DEF_OVERLAY_BAR_HEIGHT) - (2*GAP_SIZE);
|
tgt.h = (SCREEN_HEIGHT) - (2*DEF_OVERLAY_BAR_HEIGHT) - (2*GAP_SIZE);
|
||||||
SDL_RenderFillRect(board::getRenderer(), &tgt);
|
SDL_RenderFillRect(board::getRenderer(), &tgt);
|
||||||
|
}
|
||||||
|
|
||||||
//draw info for first box
|
//draw info for first box
|
||||||
{
|
{
|
||||||
|
@ -90,6 +90,11 @@ void weather::draw(){
|
|||||||
void weather::update() {
|
void weather::update() {
|
||||||
std::cerr << "WEATHER::UPDATE\n";
|
std::cerr << "WEATHER::UPDATE\n";
|
||||||
_last_update = std::chrono::high_resolution_clock::now();
|
_last_update = std::chrono::high_resolution_clock::now();
|
||||||
|
temp_today = 0; temp_tommorow = 0; temp_day_after = 0;
|
||||||
|
weather_today = nullptr;
|
||||||
|
weather_tommorow = nullptr;
|
||||||
|
weather_day_after = nullptr;
|
||||||
|
|
||||||
|
|
||||||
//fetch updates
|
//fetch updates
|
||||||
//do curl setup and cleanup
|
//do curl setup and cleanup
|
||||||
@ -102,16 +107,18 @@ void weather::update() {
|
|||||||
curl_easy_setopt(api_curl, CURLOPT_WRITEFUNCTION,
|
curl_easy_setopt(api_curl, CURLOPT_WRITEFUNCTION,
|
||||||
dashboard::panel::weather::curl_callback);
|
dashboard::panel::weather::curl_callback);
|
||||||
curl_easy_setopt(api_curl, CURLOPT_WRITEDATA, &json_string);
|
curl_easy_setopt(api_curl, CURLOPT_WRITEDATA, &json_string);
|
||||||
CURLcode res = curl_easy_perform(api_curl);
|
curl_easy_perform(api_curl);
|
||||||
curl_easy_cleanup(api_curl);
|
curl_easy_cleanup(api_curl);
|
||||||
api_curl = nullptr;
|
api_curl = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//prase the response
|
//parse the response
|
||||||
json_doc.Parse(json_string.c_str());
|
//We clean it up at then end because its wasting space if we dont
|
||||||
|
json_doc = new rapidjson::Document();
|
||||||
|
json_doc->Parse(json_string.c_str());
|
||||||
|
|
||||||
//update internal state
|
//update internal state
|
||||||
const rapidjson::Value& curr_entry = json_doc["dataseries"];
|
const rapidjson::Value& curr_entry = (*json_doc)["dataseries"];
|
||||||
//get all entries
|
//get all entries
|
||||||
weather_today = &weather_string.at(curr_entry[0]["weather"].GetString());
|
weather_today = &weather_string.at(curr_entry[0]["weather"].GetString());
|
||||||
weather_tommorow = &weather_string.at(curr_entry[7]["weather"].GetString());
|
weather_tommorow = &weather_string.at(curr_entry[7]["weather"].GetString());
|
||||||
@ -127,6 +134,9 @@ void weather::update() {
|
|||||||
temp_tommorow = (temp_tommorow * 1.8) + 32;
|
temp_tommorow = (temp_tommorow * 1.8) + 32;
|
||||||
temp_day_after = (temp_day_after * 1.8) + 32;
|
temp_day_after = (temp_day_after * 1.8) + 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
json_string.clear();
|
||||||
|
delete json_doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
@ -176,7 +186,6 @@ void weather::update_texture(){
|
|||||||
{ "Roboto_Mono/RobotoMono-Medium.ttf", 50 }), NULL, &tgt);
|
{ "Roboto_Mono/RobotoMono-Medium.ttf", 50 }), NULL, &tgt);
|
||||||
|
|
||||||
//icon
|
//icon
|
||||||
std::cerr << weather_today->second << "\n";
|
|
||||||
tgt.w = (SCREEN_WIDTH / 3) - 50;
|
tgt.w = (SCREEN_WIDTH / 3) - 50;
|
||||||
tgt.h = tgt.w;
|
tgt.h = tgt.w;
|
||||||
tgt.y = DEF_OVERLAY_BAR_HEIGHT + 25;
|
tgt.y = DEF_OVERLAY_BAR_HEIGHT + 25;
|
||||||
|
@ -51,7 +51,7 @@ namespace dashboard::panel {
|
|||||||
|
|
||||||
CURL* api_curl;
|
CURL* api_curl;
|
||||||
std::string json_string;
|
std::string json_string;
|
||||||
rapidjson::Document json_doc;
|
rapidjson::Document* json_doc;
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::high_resolution_clock> _last_update;
|
std::chrono::time_point<std::chrono::high_resolution_clock> _last_update;
|
||||||
std::chrono::milliseconds _update_interval;
|
std::chrono::milliseconds _update_interval;
|
||||||
|
Loading…
Reference in New Issue
Block a user