2021-01-27 20:37:12 +01:00
|
|
|
|
/* Copyright (C) 2019-2021 Logaev Maxim (turbocat2001), GPLv2 */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Info: App uses api from openweathermap.org.
|
|
|
|
|
The standard configuration uses my token and the city of Moscow.
|
|
|
|
|
You can always change it in the weather.json file.
|
2021-02-02 18:17:20 +01:00
|
|
|
|
weather.json configuration example:
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"Celsius": false, // Enabled fahrenheit (Optional)
|
2021-05-23 19:21:26 +02:00
|
|
|
|
"Location": "Berlin", // city Berlin
|
2021-02-02 18:17:20 +01:00
|
|
|
|
"Token": "19ffa14b3dc0e238175829461d1788b8", // OpenWeatherMap token
|
|
|
|
|
"Lang": "ru", // Language (Optional)
|
|
|
|
|
"AutoUpdate": 5 // In minutes. 0 - disabled (Optional)
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 20:37:12 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
2021-02-02 18:17:20 +01:00
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <stdbool.h>
|
2021-01-27 20:37:12 +01:00
|
|
|
|
#include "json/json.h"
|
2021-05-23 19:21:26 +02:00
|
|
|
|
#include <sys/ksys.h>
|
2021-01-27 20:37:12 +01:00
|
|
|
|
#include <clayer/http.h>
|
|
|
|
|
#include <clayer/libimg.h>
|
|
|
|
|
|
2021-05-23 19:21:26 +02:00
|
|
|
|
#define VERSION "Weather 1.6e"
|
2021-01-27 20:37:12 +01:00
|
|
|
|
|
|
|
|
|
enum BUTTONS{
|
|
|
|
|
BTN_QUIT = 1,
|
|
|
|
|
BTN_UPDATE = 2
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-29 10:40:07 +01:00
|
|
|
|
#define START_YPOS 34
|
2021-01-28 00:59:58 +01:00
|
|
|
|
#define UTF8_W 8
|
|
|
|
|
#define CP866_W 6
|
2021-01-28 23:47:41 +01:00
|
|
|
|
#define JSON_OBJ(X) value->u.object.values[X]
|
|
|
|
|
#define OK 200
|
2021-01-28 00:59:58 +01:00
|
|
|
|
|
2021-01-29 10:40:07 +01:00
|
|
|
|
unsigned WINDOW_W = 230;
|
2021-01-28 23:47:41 +01:00
|
|
|
|
|
|
|
|
|
#define API "api.openweathermap.org/data/2.5/weather?q=%s&appid=%s&units=%s&lang=%s"
|
|
|
|
|
#define IMAGE_URL "openweathermap.org/img/w/%s.png"
|
2021-01-29 10:40:07 +01:00
|
|
|
|
|
2021-02-02 18:17:20 +01:00
|
|
|
|
Image *blend=NULL;
|
2021-02-10 21:35:30 +01:00
|
|
|
|
const char *config_name = "/sys/Settings/weather.json";
|
2021-01-29 10:40:07 +01:00
|
|
|
|
|
2021-01-28 23:47:41 +01:00
|
|
|
|
unsigned char char_size=1;
|
2021-05-23 19:21:26 +02:00
|
|
|
|
uint64_t auto_update_time = 0;
|
2021-01-28 00:59:58 +01:00
|
|
|
|
|
2021-01-29 10:40:07 +01:00
|
|
|
|
char *wind_speed_str, *pressure_str, *visibility_str, *humidity_str, *update_str, *wind_deg_str;
|
2021-01-28 23:47:41 +01:00
|
|
|
|
|
|
|
|
|
char lang[3]="en";
|
|
|
|
|
char format_temp_str[6];
|
2021-01-28 00:59:58 +01:00
|
|
|
|
char full_url[512];
|
2021-01-27 20:37:12 +01:00
|
|
|
|
char full_url_image[256];
|
2021-01-28 23:47:41 +01:00
|
|
|
|
|
|
|
|
|
char temp_char='K';
|
|
|
|
|
|
2021-05-23 19:21:26 +02:00
|
|
|
|
ksys_colors_table_t sys_color_table;
|
2021-01-27 20:37:12 +01:00
|
|
|
|
|
2021-05-23 19:21:26 +02:00
|
|
|
|
ksys_pos_t win_pos;
|
2021-01-28 00:59:58 +01:00
|
|
|
|
|
2021-01-27 20:37:12 +01:00
|
|
|
|
#pragma pack(push,1)
|
2021-01-28 23:47:41 +01:00
|
|
|
|
struct open_weather_data{
|
2021-05-23 19:21:26 +02:00
|
|
|
|
char city[100];
|
2021-01-28 23:47:41 +01:00
|
|
|
|
int wind_speed;
|
|
|
|
|
int wind_deg;
|
|
|
|
|
int pressure;
|
|
|
|
|
int humidity;
|
|
|
|
|
char weath_desc[100];
|
|
|
|
|
int visibility;
|
|
|
|
|
int timezone;
|
|
|
|
|
char image_code[4];
|
|
|
|
|
int temp;
|
|
|
|
|
}myw;
|
2021-01-27 20:37:12 +01:00
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
2021-05-23 19:21:26 +02:00
|
|
|
|
void notify_show(char *text){
|
|
|
|
|
_ksys_exec("/sys/@notify", text);
|
2021-01-27 20:37:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-28 23:47:41 +01:00
|
|
|
|
void* safe_malloc(size_t size)
|
2021-01-27 20:37:12 +01:00
|
|
|
|
{
|
2021-02-02 18:17:20 +01:00
|
|
|
|
void *p=malloc(size);
|
2021-01-27 20:37:12 +01:00
|
|
|
|
if(p==NULL){
|
|
|
|
|
notify_show("'Memory allocation error!' -E");
|
|
|
|
|
exit(0);
|
|
|
|
|
}else{
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-23 19:21:26 +02:00
|
|
|
|
void draw_format_text_sys(int x, int y, ksys_color_t color, const char *format_str, ... ) // Форматированный вывод в окно
|
2021-01-27 20:37:12 +01:00
|
|
|
|
{
|
2021-02-02 18:17:20 +01:00
|
|
|
|
char tmp_buff[100];
|
2021-01-27 20:37:12 +01:00
|
|
|
|
va_list ap;
|
|
|
|
|
va_start (ap, format_str);
|
|
|
|
|
vsnprintf(tmp_buff, sizeof tmp_buff ,format_str, ap);
|
|
|
|
|
va_end(ap);
|
2021-05-23 19:21:26 +02:00
|
|
|
|
_ksys_draw_text(tmp_buff, x, y , 0, color);
|
2021-01-27 20:37:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-02 18:17:20 +01:00
|
|
|
|
void find_and_set(json_value *value, struct open_weather_data* weather) // Ищем значения в json и заполняем структуру "myw"
|
2021-01-27 20:37:12 +01:00
|
|
|
|
{
|
|
|
|
|
for(int i=0; i<value->u.object.length; i++){
|
|
|
|
|
if(!strcmp(JSON_OBJ(i).name, "main")){
|
2021-01-28 00:59:58 +01:00
|
|
|
|
if(JSON_OBJ(i).value->u.object.values[0].value->type==json_double)
|
|
|
|
|
{
|
|
|
|
|
weather->temp = (int)JSON_OBJ(i).value->u.object.values[0].value->u.dbl;
|
|
|
|
|
}else{
|
|
|
|
|
weather->temp = JSON_OBJ(i).value->u.object.values[0].value->u.integer;
|
|
|
|
|
}
|
2021-01-27 20:37:12 +01:00
|
|
|
|
weather->pressure = JSON_OBJ(i).value->u.object.values[4].value->u.integer;
|
|
|
|
|
weather->humidity = JSON_OBJ(i).value->u.object.values[5].value->u.integer;
|
|
|
|
|
}
|
|
|
|
|
if(!strcmp(JSON_OBJ(i).name, "name")){
|
2021-02-02 18:17:20 +01:00
|
|
|
|
if(!strcmp(&JSON_OBJ(i).value->u.string.ptr[JSON_OBJ(i).value->u.string.length-3], "’")){
|
2021-05-23 19:21:26 +02:00
|
|
|
|
strncpy(weather->city, JSON_OBJ(i).value->u.string.ptr, JSON_OBJ(i).value->u.string.length-3);
|
2021-02-02 18:17:20 +01:00
|
|
|
|
}else{
|
2021-05-23 19:21:26 +02:00
|
|
|
|
strcpy(weather->city, JSON_OBJ(i).value->u.string.ptr);
|
2021-02-02 18:17:20 +01:00
|
|
|
|
}
|
2021-01-27 20:37:12 +01:00
|
|
|
|
}
|
|
|
|
|
if(!strcmp(JSON_OBJ(i).name, "weather")){
|
2021-01-28 00:59:58 +01:00
|
|
|
|
strcpy(weather->weath_desc, JSON_OBJ(i).value->u.array.values[0]->u.object.values[2].value->u.string.ptr);
|
|
|
|
|
strcpy(weather->image_code, JSON_OBJ(i).value->u.array.values[0]->u.object.values[3].value->u.string.ptr);
|
2021-01-27 20:37:12 +01:00
|
|
|
|
}
|
|
|
|
|
if(!strcmp(JSON_OBJ(i).name, "wind")){
|
2021-01-29 10:40:07 +01:00
|
|
|
|
weather->wind_deg = JSON_OBJ(i).value->u.object.values[1].value->u.integer;
|
2021-01-28 00:59:58 +01:00
|
|
|
|
if(JSON_OBJ(i).value->u.object.values[0].value->type==json_double)
|
|
|
|
|
{
|
|
|
|
|
weather->wind_speed = (int)JSON_OBJ(i).value->u.object.values[0].value->u.dbl;
|
|
|
|
|
}else{
|
|
|
|
|
weather->wind_speed = JSON_OBJ(i).value->u.object.values[0].value->u.integer;
|
|
|
|
|
}
|
2021-01-27 20:37:12 +01:00
|
|
|
|
}
|
|
|
|
|
if(!strcmp(JSON_OBJ(i).name, "visibility")){
|
|
|
|
|
weather->visibility = JSON_OBJ(i).value->u.integer;
|
|
|
|
|
}
|
|
|
|
|
if(!strcmp(JSON_OBJ(i).name, "timezone")){
|
|
|
|
|
weather->timezone = JSON_OBJ(i).value->u.integer/60/60;
|
|
|
|
|
}
|
|
|
|
|
if(!strcmp(JSON_OBJ(i).name, "message")){
|
|
|
|
|
char *errmsg = safe_malloc(weather->timezone = JSON_OBJ(i).value->u.string.length+6);
|
|
|
|
|
sprintf(errmsg,"'%s!' -E", JSON_OBJ(i).value->u.string.ptr);
|
|
|
|
|
notify_show(errmsg);
|
2021-02-02 18:17:20 +01:00
|
|
|
|
free(errmsg);
|
2021-01-27 20:37:12 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-23 19:21:26 +02:00
|
|
|
|
http_msg* get_json(char *city, char *Token, char* Units)
|
2021-01-27 20:37:12 +01:00
|
|
|
|
{
|
2021-05-23 19:21:26 +02:00
|
|
|
|
sprintf(full_url, API, city, Token, Units, lang);
|
2021-01-27 20:37:12 +01:00
|
|
|
|
http_msg *h = http_get(full_url, 0, HTTP_FLAG_BLOCK, "");
|
|
|
|
|
http_long_receive(h);
|
|
|
|
|
if (h->status == OK || h->status == 404) {
|
2021-01-28 00:59:58 +01:00
|
|
|
|
return h;
|
2021-01-27 20:37:12 +01:00
|
|
|
|
} else {
|
2021-02-02 18:17:20 +01:00
|
|
|
|
http_free(h);
|
2021-01-27 20:37:12 +01:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-02 18:17:20 +01:00
|
|
|
|
void get_image() // Функция загрузки изображения
|
|
|
|
|
{
|
2021-01-27 20:37:12 +01:00
|
|
|
|
sprintf(full_url_image, IMAGE_URL, myw.image_code);
|
2021-02-02 18:17:20 +01:00
|
|
|
|
http_msg *h= http_get(full_url_image, 0, HTTP_FLAG_BLOCK, "");
|
2021-01-27 20:37:12 +01:00
|
|
|
|
http_long_receive(h);
|
|
|
|
|
|
|
|
|
|
if (h->status == OK) {
|
2021-02-02 18:17:20 +01:00
|
|
|
|
Image *image = img_decode(h->content_ptr, h->content_length, 0); // Декодирование RAW данных в данные изображения
|
2021-01-27 20:37:12 +01:00
|
|
|
|
if (image->Type != IMAGE_BPP32) {
|
2021-02-02 18:17:20 +01:00
|
|
|
|
image = img_convert(image, NULL, IMAGE_BPP32, 0, 0); // Конвертируем картику в BPP32
|
2021-01-27 20:37:12 +01:00
|
|
|
|
if (!image) {
|
|
|
|
|
notify_show("'Convetring image error!' -E");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-02 18:17:20 +01:00
|
|
|
|
blend = img_create(64, 64, IMAGE_BPP32); // Создаём фон для картинки
|
|
|
|
|
img_fill_color(blend, 64, 64, sys_color_table.work_area); // Заливаем фон цветом окна
|
|
|
|
|
Image* image2 = img_scale(image, 0, 0, 50, 50, NULL, LIBIMG_SCALE_STRETCH , LIBIMG_INTER_BILINEAR, 64, 64); // Растягиваем изображение
|
|
|
|
|
img_blend(blend, image2, 0, 0, 0, 0, 64, 64); // Смешиваем растянутую картинку и фон для получения прозрачности
|
|
|
|
|
img_destroy(image); // Уничтожаем исходную картинку
|
|
|
|
|
img_destroy(image2); // Уничтажаем растянутую картинку
|
2021-01-27 20:37:12 +01:00
|
|
|
|
}else{
|
|
|
|
|
notify_show("'Image not loaded!!' -W");
|
2021-02-02 18:17:20 +01:00
|
|
|
|
}
|
|
|
|
|
if(h!=NULL){
|
|
|
|
|
http_free(h);
|
|
|
|
|
}
|
2021-01-27 20:37:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-23 19:21:26 +02:00
|
|
|
|
void redraw_gui() // Перересовываем интерфейс
|
2021-01-27 20:37:12 +01:00
|
|
|
|
{
|
2021-05-23 19:21:26 +02:00
|
|
|
|
_ksys_start_draw(); // Начинам прорисовку
|
2021-02-02 18:17:20 +01:00
|
|
|
|
|
2021-05-23 19:21:26 +02:00
|
|
|
|
int new_win_w = (strlen(myw.city)/char_size+12)*(UTF8_W+char_size-1); // Если название города не влезает в окно
|
2021-01-28 00:59:58 +01:00
|
|
|
|
if(new_win_w<WINDOW_W){
|
|
|
|
|
new_win_w=WINDOW_W;
|
|
|
|
|
}
|
2021-01-29 10:40:07 +01:00
|
|
|
|
// Рисуем окно
|
2021-05-23 19:21:26 +02:00
|
|
|
|
_ksys_create_window(win_pos.x, win_pos.y, new_win_w, START_YPOS+220, VERSION, sys_color_table.work_area, 0x14);
|
2021-01-29 10:40:07 +01:00
|
|
|
|
// Выводим жирным шрифтом название локации и временной зоны
|
2021-05-23 19:21:26 +02:00
|
|
|
|
draw_format_text_sys(20, START_YPOS, 0xB0000000 | sys_color_table.work_text, "%s (UTC%+d)", myw.city, myw.timezone);
|
|
|
|
|
draw_format_text_sys(21, START_YPOS, 0xB0000000 | sys_color_table.work_text, "%s (UTC%+d)", myw.city, myw.timezone);
|
2021-01-29 10:40:07 +01:00
|
|
|
|
// Выводим изображение
|
2021-01-28 00:59:58 +01:00
|
|
|
|
img_draw(blend, 10, START_YPOS+30, 64,64,0,0);
|
2021-01-29 10:40:07 +01:00
|
|
|
|
// Выводим жирным шрифтом название локации и временной зоны
|
2021-01-28 00:59:58 +01:00
|
|
|
|
draw_format_text_sys(20, START_YPOS+20, 0xb0000000 | sys_color_table.work_text, myw.weath_desc);
|
|
|
|
|
draw_format_text_sys(21, START_YPOS+20, 0xb0000000 | sys_color_table.work_text, myw.weath_desc);
|
2021-01-29 10:40:07 +01:00
|
|
|
|
// Выводим жирным шрифтом название локации и временной зоны
|
2021-01-28 23:47:41 +01:00
|
|
|
|
draw_format_text_sys(100, START_YPOS+45, 0xb1000000 | sys_color_table.work_text, format_temp_str, myw.temp);
|
|
|
|
|
draw_format_text_sys(101, START_YPOS+46, 0xb1000000 | sys_color_table.work_text, format_temp_str, myw.temp);
|
2021-01-29 10:40:07 +01:00
|
|
|
|
// Выводим обычным шрифтом
|
2021-01-28 23:47:41 +01:00
|
|
|
|
draw_format_text_sys(20, START_YPOS+80, 0xb0000000 | sys_color_table.work_text, pressure_str,myw.pressure);
|
|
|
|
|
draw_format_text_sys(20, START_YPOS+100, 0xb0000000 | sys_color_table.work_text, humidity_str, myw.humidity, "%");
|
|
|
|
|
draw_format_text_sys(20, START_YPOS+120, 0xb0000000 | sys_color_table.work_text, wind_speed_str, myw.wind_speed);
|
2021-01-29 10:40:07 +01:00
|
|
|
|
draw_format_text_sys(20, START_YPOS+140, 0xb0000000 | sys_color_table.work_text, wind_deg_str, myw.wind_deg);
|
|
|
|
|
draw_format_text_sys(20, START_YPOS+160, 0xb0000000 | sys_color_table.work_text, visibility_str, myw.visibility);
|
|
|
|
|
// Определяем кнопку
|
2021-05-23 19:21:26 +02:00
|
|
|
|
_ksys_define_button(new_win_w/2-60, START_YPOS+180, 120, 30, BTN_UPDATE, sys_color_table.work_button);
|
|
|
|
|
_ksys_draw_text(update_str, (new_win_w/2)-(UTF8_W*strlen(update_str)/2/char_size), START_YPOS+190, 0, 0xb0000000 | sys_color_table.work_button_text);
|
|
|
|
|
_ksys_end_draw();
|
2021-01-27 20:37:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-23 19:21:26 +02:00
|
|
|
|
void get_config(char **city, char **token, char **units) // Загружаем конфиг
|
2021-01-27 20:37:12 +01:00
|
|
|
|
{
|
2021-05-23 19:21:26 +02:00
|
|
|
|
ksys_ufile_t config_j = _ksys_load_file(config_name);
|
|
|
|
|
if(!config_j.size){
|
2021-01-27 20:37:12 +01:00
|
|
|
|
notify_show("'Configuration file not found!' -E");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
2021-05-23 19:21:26 +02:00
|
|
|
|
|
|
|
|
|
json_value* value =json_parse (config_j.data, config_j.size); // Парсим конфиг
|
2021-01-27 20:37:12 +01:00
|
|
|
|
for(int i=0; i<value->u.object.length; i++){
|
2021-02-02 18:17:20 +01:00
|
|
|
|
if(!strcmp(JSON_OBJ(i).name, "Location") && JSON_OBJ(i).value->type==json_string){
|
2021-05-23 19:21:26 +02:00
|
|
|
|
*city = JSON_OBJ(i).value->u.string.ptr; // Получаем название города
|
2021-01-27 20:37:12 +01:00
|
|
|
|
}
|
2021-02-02 18:17:20 +01:00
|
|
|
|
else if(!strcmp(JSON_OBJ(i).name, "Token") && JSON_OBJ(i).value->type==json_string){
|
2021-05-23 19:21:26 +02:00
|
|
|
|
*token = JSON_OBJ(i).value->u.string.ptr; // Получаем токен
|
2021-01-28 23:47:41 +01:00
|
|
|
|
}
|
2021-02-02 18:17:20 +01:00
|
|
|
|
else if(!strcmp(JSON_OBJ(i).name, "Celsius") && JSON_OBJ(i).value->type==json_boolean){
|
2021-01-28 23:47:41 +01:00
|
|
|
|
if(JSON_OBJ(i).value->u.boolean){
|
2021-05-23 19:21:26 +02:00
|
|
|
|
*units = "metric";
|
2021-01-28 23:47:41 +01:00
|
|
|
|
temp_char = 'C';
|
|
|
|
|
}else{
|
2021-05-23 19:21:26 +02:00
|
|
|
|
*units = "imperial";
|
2021-01-28 23:47:41 +01:00
|
|
|
|
temp_char = 'F';
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-02 18:17:20 +01:00
|
|
|
|
else if(!strcmp(JSON_OBJ(i).name, "Lang") && JSON_OBJ(i).value->type==json_string){
|
|
|
|
|
strncpy(lang, JSON_OBJ(i).value->u.string.ptr,2); // Получаем язык
|
|
|
|
|
}
|
|
|
|
|
else if(!strcmp(JSON_OBJ(i).name, "AutoUpdate") && JSON_OBJ(i).value->type==json_integer){
|
2021-05-23 19:21:26 +02:00
|
|
|
|
auto_update_time = JSON_OBJ(i).value->u.integer; // Получаем время автообновлений данных
|
2021-01-27 20:37:12 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-23 19:21:26 +02:00
|
|
|
|
if(*city==NULL || *token ==NULL){
|
2021-01-28 23:47:41 +01:00
|
|
|
|
notify_show("'Invalid config!' -E");
|
2021-01-27 20:37:12 +01:00
|
|
|
|
exit(0);
|
|
|
|
|
}
|
2021-05-23 19:21:26 +02:00
|
|
|
|
free(config_j.data);
|
2021-01-27 20:37:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-23 19:21:26 +02:00
|
|
|
|
void update(char* city, char* token, char* units) // Обновление данных
|
2021-01-27 20:37:12 +01:00
|
|
|
|
{
|
2021-01-28 00:59:58 +01:00
|
|
|
|
if(blend!=NULL){
|
2021-02-02 18:17:20 +01:00
|
|
|
|
img_destroy(blend); // Уничтожение картинику с прозрачностью
|
2021-01-28 23:47:41 +01:00
|
|
|
|
blend = NULL;
|
2021-01-28 00:59:58 +01:00
|
|
|
|
}
|
2021-01-29 10:40:07 +01:00
|
|
|
|
memset(&myw, 0, sizeof myw); // Обнуляем структуру
|
2021-05-23 19:21:26 +02:00
|
|
|
|
strcpy(myw.city,"None");
|
2021-01-28 00:59:58 +01:00
|
|
|
|
strcpy(myw.weath_desc,"unknown");
|
2021-01-29 10:40:07 +01:00
|
|
|
|
http_msg *json_file = get_json(city, token, units); // Получаем данные о погоде в формате json
|
2021-01-27 20:37:12 +01:00
|
|
|
|
if(json_file != NULL){
|
2021-02-02 18:17:20 +01:00
|
|
|
|
json_value* value=json_parse(json_file->content_ptr, json_file->content_length); // Парсим json файл
|
2021-01-29 10:40:07 +01:00
|
|
|
|
find_and_set(value, &myw); // Ищем значения в json
|
|
|
|
|
sprintf(format_temp_str, "%s°%c","%d",temp_char); // Формируем строку для вывода температуры
|
2021-02-02 18:17:20 +01:00
|
|
|
|
get_image(); // Получаем картинку
|
|
|
|
|
json_value_free(value); // Уничтожаем полученные json значения
|
|
|
|
|
http_free(json_file);
|
2021-01-27 20:37:12 +01:00
|
|
|
|
}else{
|
2021-01-28 00:59:58 +01:00
|
|
|
|
notify_show("'Connection error!' -E");
|
2021-01-27 20:37:12 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-28 23:47:41 +01:00
|
|
|
|
void set_lang()
|
|
|
|
|
{
|
|
|
|
|
if(!strcmp(lang, "ru")){
|
2021-01-29 10:40:07 +01:00
|
|
|
|
wind_speed_str = "Скорость ветра: %d м/с";
|
|
|
|
|
pressure_str = "Давление: %d гПa";
|
|
|
|
|
visibility_str = "Видимость: %d м";
|
|
|
|
|
humidity_str = "Влажность: %d %s";
|
2021-01-28 23:47:41 +01:00
|
|
|
|
update_str = "Обновить";
|
2021-01-29 10:40:07 +01:00
|
|
|
|
wind_deg_str = "Направление ветра: %d°";
|
|
|
|
|
WINDOW_W = 250;
|
2021-01-28 23:47:41 +01:00
|
|
|
|
char_size = 2;
|
|
|
|
|
}else if(!strcmp(lang, "de")){
|
|
|
|
|
wind_speed_str = "Windgeschwindigkeit: %d m/s";
|
|
|
|
|
pressure_str = "Druck: %d hPa";
|
|
|
|
|
visibility_str = "Sichtbarkeit: %d m";
|
2021-01-29 10:40:07 +01:00
|
|
|
|
humidity_str = "Luftfeuchtigkeit: %d %s";
|
|
|
|
|
wind_deg_str = "Windrichtung %d°";
|
2021-01-28 23:47:41 +01:00
|
|
|
|
WINDOW_W = 270;
|
|
|
|
|
update_str = "Aktualisieren";
|
|
|
|
|
}else{
|
2021-01-29 10:40:07 +01:00
|
|
|
|
pressure_str = "Pressure: %d hPa";
|
|
|
|
|
humidity_str = "Humidity: %d %s";
|
|
|
|
|
visibility_str = "Visibility: %d m";
|
|
|
|
|
wind_speed_str = "Wind speed: %d m/s";
|
|
|
|
|
wind_deg_str = "Wind direction: %d°";
|
2021-01-28 23:47:41 +01:00
|
|
|
|
update_str = "Refresh";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-02 18:17:20 +01:00
|
|
|
|
int main()
|
|
|
|
|
{
|
2021-05-23 19:21:26 +02:00
|
|
|
|
win_pos = _ksys_get_mouse_pos(KSYS_MOUSE_SCREEN_POS); // Получаем позицию курсора
|
|
|
|
|
_ksys_get_system_colors(&sys_color_table); // Получаем таблица цветов
|
2021-01-29 10:40:07 +01:00
|
|
|
|
|
2021-05-23 19:21:26 +02:00
|
|
|
|
char *city=NULL, *token=NULL, *units=NULL; // Указатели на токен, название города, систему мер
|
2021-01-28 23:47:41 +01:00
|
|
|
|
|
2021-05-23 19:21:26 +02:00
|
|
|
|
get_config(&city, &token, &units); // Загружаем конфиг
|
2021-01-29 10:40:07 +01:00
|
|
|
|
set_lang(); // Установить язык приложения
|
2021-05-23 19:21:26 +02:00
|
|
|
|
update(city, token, units);
|
2021-02-02 18:17:20 +01:00
|
|
|
|
|
|
|
|
|
uint32_t (*event)();
|
2021-01-28 00:59:58 +01:00
|
|
|
|
|
2021-05-23 19:21:26 +02:00
|
|
|
|
if(auto_update_time<=0){
|
|
|
|
|
event = _ksys_get_event;
|
2021-02-02 18:17:20 +01:00
|
|
|
|
}else{
|
2021-05-23 19:21:26 +02:00
|
|
|
|
event = _ksys_wait_event;
|
2021-02-02 18:17:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 20:37:12 +01:00
|
|
|
|
while(1){
|
2021-05-23 19:21:26 +02:00
|
|
|
|
switch(event(6000*auto_update_time)){ // Получаем системное событие
|
|
|
|
|
case KSYS_EVENT_NONE: // Нет события
|
|
|
|
|
update(city, token, units);
|
2021-02-02 18:17:20 +01:00
|
|
|
|
debug_printf("Weather: Update\n");
|
2021-01-27 20:37:12 +01:00
|
|
|
|
break;
|
2021-05-23 19:21:26 +02:00
|
|
|
|
case KSYS_EVENT_REDRAW: // Событие перерисовки
|
|
|
|
|
redraw_gui();
|
2021-01-27 20:37:12 +01:00
|
|
|
|
break;
|
2021-05-23 19:21:26 +02:00
|
|
|
|
case KSYS_EVENT_BUTTON: // Событие кнопок
|
|
|
|
|
switch (_ksys_get_button()){
|
2021-02-02 18:17:20 +01:00
|
|
|
|
case BTN_UPDATE:
|
2021-05-23 19:21:26 +02:00
|
|
|
|
update(city, token, units);
|
|
|
|
|
redraw_gui();
|
2021-01-27 20:37:12 +01:00
|
|
|
|
break;
|
2021-02-02 18:17:20 +01:00
|
|
|
|
case BTN_QUIT: // Кнопка выхода
|
2021-01-27 20:37:12 +01:00
|
|
|
|
exit(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-02-02 18:17:20 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2021-01-27 20:37:12 +01:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|