api add data type AVG float 3 decimal
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
diff --git a/api.c b/api.c
index 0c0dc0a..60636c0 100644
--- a/api.c
+++ b/api.c
@@ -903,6 +903,7 @@ static struct api_data *api_add_data_full(struct api_data *root, char *name, enu
break;
case API_VOLTS:
case API_TEMP:
+ case API_AVG:
api_data->data = (void *)malloc(sizeof(float));
*((float *)(api_data->data)) = *((float *)data);
break;
@@ -1032,6 +1033,11 @@ struct api_data *api_add_percent(struct api_data *root, char *name, double *data
return api_add_data_full(root, name, API_PERCENT, (void *)data, copy_data);
}
+struct api_data *api_add_avg(struct api_data *root, char *name, float *data, bool copy_data)
+{
+ return api_add_data_full(root, name, API_AVG, (void *)data, copy_data);
+}
+
static struct api_data *print_data(struct api_data *root, char *buf, bool isjson, bool precom)
{
struct api_data *tmp;
@@ -1108,6 +1114,7 @@ static struct api_data *print_data(struct api_data *root, char *buf, bool isjson
sprintf(buf, "%.2f", *((double *)(root->data)));
break;
case API_VOLTS:
+ case API_AVG:
sprintf(buf, "%.3f", *((float *)(root->data)));
break;
case API_MHTOTAL:
diff --git a/miner.h b/miner.h
index cab07c6..08b1fa0 100644
--- a/miner.h
+++ b/miner.h
@@ -1413,7 +1413,8 @@ enum api_data_type {
API_VOLTS,
API_HS,
API_DIFF,
- API_PERCENT
+ API_PERCENT,
+ API_AVG
};
struct api_data {
@@ -1448,5 +1449,6 @@ extern struct api_data *api_add_volts(struct api_data *root, char *name, float *
extern struct api_data *api_add_hs(struct api_data *root, char *name, double *data, bool copy_data);
extern struct api_data *api_add_diff(struct api_data *root, char *name, double *data, bool copy_data);
extern struct api_data *api_add_percent(struct api_data *root, char *name, double *data, bool copy_data);
+extern struct api_data *api_add_avg(struct api_data *root, char *name, float *data, bool copy_data);
#endif /* __MINER_H__ */