Commit 7acf38b304f8979abfdec9e260949267440deb29

Kano 2014-01-05T21:34:43

api add data type AVG float 3 decimal

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__ */