Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for a fourth OpenAPS prediction line #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"prediction2": 11,
"prediction3": 12,
"predictionRecency": 13,
"prediction4": 14,

"mmol": 1,
"topOfGraph": 2,
Expand Down
2 changes: 2 additions & 0 deletions src/app_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ bool validate_data_message(DictionaryIterator *data, DataMessage *out) {
memcpy(out->prediction_1, zeroes, PREDICTION_MAX_LENGTH * sizeof(uint8_t));
memcpy(out->prediction_2, zeroes, PREDICTION_MAX_LENGTH * sizeof(uint8_t));
memcpy(out->prediction_3, zeroes, PREDICTION_MAX_LENGTH * sizeof(uint8_t));
memcpy(out->prediction_4, zeroes, PREDICTION_MAX_LENGTH * sizeof(uint8_t));

bool success = true
&& get_int32(data, &out->recency, MESSAGE_KEY_recency, false, 0)
Expand All @@ -162,6 +163,7 @@ bool validate_data_message(DictionaryIterator *data, DataMessage *out) {
get_prediction(data, out->prediction_1, MESSAGE_KEY_prediction1, &out->prediction_length);
get_prediction(data, out->prediction_2, MESSAGE_KEY_prediction2, &out->prediction_length);
get_prediction(data, out->prediction_3, MESSAGE_KEY_prediction3, &out->prediction_length);
get_prediction(data, out->prediction_4, MESSAGE_KEY_prediction4, &out->prediction_length);
if (out->prediction_length > 0) {
success = success && get_int32(data, &out->prediction_recency, MESSAGE_KEY_predictionRecency, false, 0);
}
Expand Down
1 change: 1 addition & 0 deletions src/app_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef struct __attribute__((__packed__)) DataMessage {
uint8_t prediction_1[PREDICTION_MAX_LENGTH];
uint8_t prediction_2[PREDICTION_MAX_LENGTH];
uint8_t prediction_3[PREDICTION_MAX_LENGTH];
uint8_t prediction_4[PREDICTION_MAX_LENGTH];
int32_t prediction_recency;
} DataMessage;

Expand Down
6 changes: 3 additions & 3 deletions src/comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#include <pebble.h>
#include "app_messages.h"

// This can theoretically be maxed out to 984 bytes by combining:
// This can theoretically be maxed out to 1044 bytes by combining:
// - status bar text of 255 characters
// - point width of 1px (144 points + 144 "graph extra")
// - 3 prediction series of length 60
#define CONTENT_SIZE 1024
// - 4 prediction series of length 60
#define CONTENT_SIZE 1200

// There are many failure modes...
#define INITIAL_TIMEOUT_HALVED 2500
Expand Down
4 changes: 2 additions & 2 deletions src/graph_element.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ static void graph_update_proc(Layer *layer, GContext *ctx) {

// Prediction
if (data->prediction_length > 0 && data->received_at - data->prediction_recency >= time(NULL) - MAX_PREDICTION_AGE_TO_SHOW_SECONDS) {
uint8_t* series[3] = {data->prediction_1, data->prediction_2, data->prediction_3};
for(uint8_t si = 0; si < 3; si++) {
uint8_t* series[4] = {data->prediction_1, data->prediction_2, data->prediction_3, data->prediction_4};
for(uint8_t si = 0; si < 4; si++) {
for(i = prediction_skip; i < data->prediction_length; i++) {
bg = series[si][i] * 2;
if (bg == 0) {
Expand Down
1 change: 1 addition & 0 deletions src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function app(Pebble, c) {
prediction1: predictions.series1,
prediction2: predictions.series2,
prediction3: predictions.series3,
prediction4: predictions.series4,
predictionRecency: predictions.recency,
});
} catch (e) {
Expand Down
3 changes: 2 additions & 1 deletion src/js/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,10 @@ var data = function(c, maxSGVCount) {

if (lastPredicted && lastPredicted['predBGs']) {
var series = [
lastPredicted['predBGs']['UAM'],
lastPredicted['predBGs']['IOB'],
lastPredicted['predBGs']['COB'],
lastPredicted['predBGs']['aCOB'],
lastPredicted['predBGs']['ZT'] || lastPredicted['predBGs']['aCOB'],
].filter(function(s) {
return s !== undefined;
});
Expand Down
1 change: 1 addition & 0 deletions src/js/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ var format = function(c) {
series1: formattedSeries[0],
series2: formattedSeries[1],
series3: formattedSeries[2],
series4: formattedSeries[3],
recency: recency,
};
};
Expand Down