298 lines
8.6 KiB
C
298 lines
8.6 KiB
C
#include <string.h>
|
||
|
||
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
|
||
|
||
#include "api.h"
|
||
|
||
|
||
void s(){
|
||
struct ya_api api = ya_api_create("Authorization: Bearer ---------------------------");
|
||
api.list_devices(&api);
|
||
printf("SAS@@@\n");
|
||
for (int i = 0; i != api.data.devs->len; i++){
|
||
struct ya_dev_struct *dev = api.data.devs->dev[i];
|
||
if (dev->capabilities != NULL && dev->capabilities->color_setting != NULL){
|
||
if (dev->capabilities->color_setting->color_target == 2){
|
||
struct color_struct *color = dev->capabilities->color_setting->color;
|
||
printf("%s\n", dev->name);
|
||
printf("HSV = %i %i %i\n", color->h, color->s, color->v);
|
||
//ya_dev_hsv(dev, 177,93,80); // hsv(177, 93%, 80%)
|
||
api.hsv(dev, 284,93,80);
|
||
}
|
||
if (dev->capabilities->color_setting->color_target == 1){
|
||
struct temperature_k_struct *temperature_k = dev->capabilities->color_setting->temperature_k;
|
||
printf("%s\n", dev->name);
|
||
printf("temperature_k = %i \n", temperature_k->value);
|
||
}
|
||
|
||
}
|
||
//api.data.devs->dev[i]->capabilities->color_setting->color_status;
|
||
}
|
||
//perror("Пиздец!!!\n");
|
||
|
||
|
||
/*
|
||
for (int i = 0; i != api.data.groups->len; i++){
|
||
printf("ГРУППА: %s\n", api.data.groups->group[i]->name);
|
||
//printf("S%s\n", api.data.groups->group[i]->devs->len);
|
||
|
||
//printf("S%s\n", api.data.groups->group[i]->devs->dev[0]->id);
|
||
//printf("S%i\n", api.data.groups->group[i]->devs->len);
|
||
//printf(" ДЕВЫЙС: %s\n", api.data.groups->group[i]->devs->dev[0]->name);
|
||
for (int a = 0; a != api.data.groups->group[i]->devs->len; a++){
|
||
struct ya_dev_struct *dev = api.data.groups->group[i]->devs->dev[a];
|
||
printf("\tДЕВЫЙС %s: %s\n", dev->type, dev->name);
|
||
//api.brightness(dev, 100);
|
||
//dev->capabilities->color_setting->temperature_k->
|
||
|
||
}
|
||
|
||
}
|
||
*/
|
||
//api.on_off(3);
|
||
//api.list_devices(&api);
|
||
//printf("%s\n", ya_api_recvest("https://api.iot.yandex.net/v1.0/user/info", NULL, api.data.tocen));
|
||
|
||
|
||
|
||
|
||
//api.on_off(api.data.devs->dev[6]);
|
||
/*
|
||
for (int i = 0; i != api.data.groups->len; i++){
|
||
printf("ГРУППА: %s\n", api.data.groups->group[i]->name);
|
||
//printf("S%s\n", api.data.groups->group[i]->devs->len);
|
||
|
||
//printf("S%s\n", api.data.groups->group[i]->devs->dev[0]->id);
|
||
//printf("S%i\n", api.data.groups->group[i]->devs->len);
|
||
//printf(" ДЕВЫЙС: %s\n", api.data.groups->group[i]->devs->dev[0]->name);
|
||
for (int a = 0; a != api.data.groups->group[i]->devs->len; a++){
|
||
printf(" ДЕВАЙС: %s\n", api.data.groups->group[i]->devs->dev[a]->name);
|
||
printf(" Мин: %i\n", api.data.groups->group[i]->devs->dev[a]->capabilities->color_setting->temperature_k->min);
|
||
printf(" Макс: %i\n", api.data.groups->group[i]->devs->dev[a]->capabilities->color_setting->temperature_k->max);
|
||
//api.kelvin(api.data.groups->group[i]->devs->dev[a], 6500);
|
||
|
||
//api.on_off(api.data.groups->group[i]->devs->dev[a]);
|
||
}
|
||
|
||
}
|
||
*/
|
||
|
||
|
||
|
||
//api.data.devs
|
||
//struct ya_dev_struct* dev = api.data.devs->dev[0];
|
||
//for (int i = 0; i != api.data.devs->len; i++){
|
||
// printf("%s\n", api.data.devs->dev[i]->name);
|
||
//}
|
||
|
||
//printf("%i\n", api.data.groups->len);
|
||
/*
|
||
printf("%s\n", api.data.groups->group[0]->id);
|
||
|
||
printf("%s\n", api.data.devs->dev[0]->groups->group[0]->name);
|
||
|
||
printf("%s\n", api.data.groups->group[0]->id);
|
||
*/
|
||
/*
|
||
api.on_off(api.data.devs->dev[0]);
|
||
api.on_off(api.data.devs->dev[3]);
|
||
api.on_off(api.data.devs->dev[4]);
|
||
*/
|
||
|
||
//api.brightness(dev, 100);
|
||
//api.kelvin(dev, 4500);
|
||
//api.dev_id(dev);
|
||
|
||
//printf("%s\n", dev->loop->data.tocen);
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
int sas_1(int a){};
|
||
int sas_2(int a, int b){};
|
||
int sas_3(int a, ...){
|
||
|
||
return a;
|
||
};
|
||
struct test{
|
||
int (*sas) (int, ...);
|
||
};
|
||
|
||
|
||
int main(int argc, char *argv[]){
|
||
/*
|
||
struct test t;
|
||
t.sas = sas_3;
|
||
int a = t.sas(1,2);
|
||
printf("%i\n", a);
|
||
*/
|
||
s();
|
||
|
||
|
||
//struct ya_api api = ya_api_create("TOKEN");
|
||
//api.data.ya_devs->dev[0]->ol->data.ya_devs->dev[0]->ol->data.ya_devs->dev[0]->ol->data.ya_devs->dev[0]->ol->
|
||
|
||
|
||
///struct ya_api api = ya_api_create("Authorization: Bearer --------------------------");
|
||
//api.list_devices(&api);
|
||
//api.brightness(api.data.ya_devs->dev[0], 100);
|
||
//api.kelvin(api.data.ya_devs->dev[0], 6500);
|
||
//api.on_off(api.data.ya_devs->dev[0]);
|
||
//printf("%s\n", api.data.ya_devs->dev[0]->ol->data.tocen);
|
||
|
||
|
||
//api.list_devices(&api);
|
||
//api.on_off(api.data.ya_devs->dev[0]);
|
||
//api.brightness(api.data.ya_devs->dev[0], 100);
|
||
|
||
//api.kelvin(api.data.ya_devs->dev[0], 6500);
|
||
|
||
|
||
|
||
//api.ya_dev_on_off(api.data.ya_devs->dev[0]);
|
||
//printf("%s\n", api.ya_dev_kelvin(api.data.ya_devs->dev[0], 6500));
|
||
//char* s = yan_brightness(api.data.ya_devs->dev[0]->id, 100);
|
||
//printf("%s\n",ya_api_recvest("https://api.iot.yandex.net/v1.0/devices/actions", s));
|
||
//printf("%s\n", api.ya_dev_kelvin(api.data.ya_devs->dev[0], 6500));
|
||
|
||
//printf("%s\n", api.data.ya_devs->dev[0]->capabilities->range->value);
|
||
//char* s = yan_hsv_lampochka(api.data.ya_devs->dev[0]->id, 0,0,100);
|
||
//printf("%s\n", s);
|
||
//printf("%s\n",ya_api_recvest("https://api.iot.yandex.net/v1.0/devices/actions", s));
|
||
/*
|
||
struct ya_api api = ya_api_create("Authorization: Bearer -----------------------------");
|
||
api.list_devices(&api);
|
||
printf("1\n");
|
||
//api.ya_dev_on_off(api.data.ya_devs->dev[5]);
|
||
printf("2\n");
|
||
//api.ya_dev_on_off(api.data.ya_devs->dev[0]);
|
||
printf("3\n");
|
||
api.ya_dev_kelvin(api.data.ya_devs->dev[0], 6500);
|
||
*/
|
||
|
||
|
||
|
||
|
||
|
||
|
||
//printf("%s\n", ya_dev_kelvin(api.data.ya_devs->dev[0], 6500));
|
||
|
||
|
||
//printf("max: %i\n", api.data.ya_devs->dev[0]->capabilities->color_setting->temperature_k->max);
|
||
//printf("min: %i\n", api.data.ya_devs->dev[0]->capabilities->color_setting->temperature_k->min);
|
||
|
||
//api.ya_devs_free(&api);// dsdsdsd
|
||
|
||
|
||
|
||
/*
|
||
for (int i = 0; i != s->len; i++){
|
||
printf("%s\n", s->dev[i]->name);
|
||
}
|
||
|
||
api.ya_devs_free(s);
|
||
*/
|
||
//ya_devs_free(s);
|
||
//api.ya_dev_on_off(api.list_devices()->dev[0]);
|
||
//api.ya_devs_free();
|
||
|
||
|
||
//struct test api;
|
||
//ya_devs* devs = list_devices();
|
||
//ya_dev_on_off(devs->dev[0]);
|
||
//api.TEST = TEST;
|
||
//api.TEST();
|
||
//api.ya_dev_on_off(devs->dev[0]);
|
||
/*
|
||
ya_devs* devs = list_devices();
|
||
//printf("%s\n", devs->dev[0]->id);
|
||
for (int i = 0; i != devs->len; i++){
|
||
printf("%s\n", devs->dev[i]->name);
|
||
}
|
||
|
||
printf("%s\n", ya_dev_on_off(devs->dev[3]));
|
||
|
||
ya_devs_free(devs);
|
||
*/
|
||
|
||
/*
|
||
char* sdsd = list_json();
|
||
printf("SSS%s\n", sdsd);
|
||
for (int i = 0; i != 1000000; i++){
|
||
ya_dev* devs = list_devices(sdsd);
|
||
for (int i = 0; i != devs->len; i++){
|
||
//printf("%s\n", devs->dev[i]->name);
|
||
}
|
||
ya_dev_free(devs);
|
||
//free(devs);
|
||
}
|
||
*/
|
||
//struct ya_list sas;
|
||
//char* stdjson = list_json();
|
||
//ya_list* dev_id = list_devices_id();
|
||
|
||
|
||
|
||
|
||
//dev_off(id);
|
||
//dev_on(id);
|
||
|
||
|
||
|
||
/*
|
||
ya_dev* devs = list_devices();
|
||
for (int i = 0; i != devs->len; i++){
|
||
if (devs->dev[i]->capabilities != NULL){ //printf("%i\n", devs->dev[i]->capabilities->color_setting->temperature_k->max);
|
||
if (devs->dev[i]->capabilities->color_setting != NULL){
|
||
printf("%s\n", devs->dev[i]->name);//
|
||
printf("%i\n", devs->dev[i]->capabilities->color_setting->temperature_k->value);
|
||
//printf("%i\n", devs->dev[i]->capabilities->color_setting->temperature_k->max);
|
||
}
|
||
//printf("%i\n", devs->dev[i]->capabilities->color_setting->temperature_k->max);
|
||
//printf("SAS\n");
|
||
}
|
||
}
|
||
free(devs);
|
||
*/
|
||
|
||
|
||
/*
|
||
//printf("%i\n", devs->dev[2]->groups->len);
|
||
|
||
if (devs->dev[1]->groups != NULL){
|
||
|
||
printf("SASMMM\n");
|
||
//printf("%s\n", devs->dev[0]->groups->id[0]);
|
||
//printf("%s\n", devs->dev[0]->groups->len);
|
||
}
|
||
for (int i = 0; i != devs->len; i++){
|
||
printf("id: %s\t name: %s\n",devs->dev[i]->id, devs->dev[i]->name);
|
||
//if (devs->dev[0]->groups != NULL) printf("SAS\n");
|
||
|
||
if (devs->dev[i]->groups != NULL){
|
||
for (int n = 0; n != devs->dev[i]->groups->len; n++) printf("%s\n", devs->dev[i]->groups->id[n]);
|
||
|
||
}
|
||
|
||
}
|
||
*/
|
||
|
||
/*
|
||
ya_list* dev_id = list_devices_id();
|
||
|
||
for (int i = 0; i != dev_id->len; i++){
|
||
printf("%s\n", dev_id->id[i]);
|
||
}
|
||
*/
|
||
|
||
|
||
|
||
|
||
return 0;
|
||
}
|