Skip to content

Commit ff466fd

Browse files
Remove deprecated ml_getLabels() function (& update some comments).
1 parent bd9a807 commit ff466fd

File tree

4 files changed

+5
-87
lines changed

4 files changed

+5
-87
lines changed

mlrunner/example_dataprocessor.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
* Copyright 2024 Micro:bit Educational Foundation.
66
* SPDX-License-Identifier: MIT
77
*
8-
* TODO: Need to double buffer this so that a model can be run while the
9-
* next data is being collected.
10-
* TODO: Need to make isDataReady() more robust as right now it needs to be
11-
* called after each recordData() call.
8+
* This processor is no longer used in testextension.cpp, but it is still
9+
* included as a simpler example of how to implement a data processor.
1210
*/
1311
#include "mldataprocessor.h"
1412

mlrunner/filterdataprocessor.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
* Copyright 2024 Micro:bit Educational Foundation.
66
* SPDX-License-Identifier: MIT
77
*
8-
* TODO: Need to double buffer this so that a model can be run while the
9-
* next data is being collected.
8+
* TODO: Could be double buffered so that an interruptible model could be
9+
* run while the data is still being collected. Currently the model run
10+
* is quick enough where this is not necessary.
1011
*/
1112
#include <string.h>
1213
#include "mldataprocessor.h"

mlrunner/mlrunner.c

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -142,78 +142,6 @@ int ml_getOutputLength() {
142142
return output_length;
143143
}
144144

145-
// TODO: Remove this function and use ml_getLabels instead
146-
ml_labels_t* ml_getLabels() {
147-
static ml_labels_t labels = {
148-
.num_labels = 0,
149-
.labels = NULL
150-
};
151-
152-
const ml_model_header_t* const model_header = (ml_model_header_t*)MODEL_ADDRESS;
153-
if (model_header == NULL) {
154-
labels.num_labels = 0;
155-
if (labels.labels != NULL) {
156-
free(labels.labels);
157-
labels.labels = NULL;
158-
}
159-
return NULL;
160-
}
161-
162-
// Workout the addresses in flash from each label, there are as many strings
163-
// as indicated by model_header->number_of_actions
164-
const char* flash_labels[model_header->number_of_actions];
165-
ml_header_action_t *action = (ml_header_action_t *)&model_header->actions[0];
166-
for (int i = 0; i < model_header->number_of_actions; i++) {
167-
flash_labels[i] = &action->label[0];
168-
// Check the label has a single null terminator at the end
169-
for (int j = 0; j < action->label_length - 1; j++) {
170-
if (flash_labels[i][j] == '\0') {
171-
return NULL;
172-
}
173-
}
174-
// And check the last character is a null terminator
175-
if (flash_labels[i][action->label_length - 1] != '\0') {
176-
return NULL;
177-
}
178-
action = (ml_header_action_t *)((uint32_t)action + ml_action_size_without_label + action->label_length);
179-
// Next action address is 4 byte aligned
180-
action = (ml_header_action_t *)(((uint32_t)action + 3) & ~3);
181-
}
182-
183-
// First check if the labels are the same, if not we need to set them again
184-
bool set_labels = false;
185-
if (labels.num_labels == 0 || labels.labels == NULL) {
186-
set_labels = true;
187-
} else if (labels.num_labels != model_header->number_of_actions) {
188-
set_labels = true;
189-
} else {
190-
for (size_t i = 0; i < labels.num_labels; i++) {
191-
if (labels.labels[i] != flash_labels[i]) {
192-
set_labels = true;
193-
break;
194-
}
195-
}
196-
}
197-
if (set_labels) {
198-
// First clear them out if needed
199-
labels.num_labels = 0;
200-
if (labels.labels != NULL) {
201-
free(labels.labels);
202-
}
203-
// Then set them to point to the strings in flash
204-
labels.labels = (const char **)malloc(model_header->number_of_actions * sizeof(char *));
205-
if (labels.labels == NULL) {
206-
return NULL;
207-
}
208-
labels.num_labels = model_header->number_of_actions;
209-
for (size_t i = 0; i < labels.num_labels; i++) {
210-
labels.labels[i] = flash_labels[i];
211-
}
212-
}
213-
214-
return &labels;
215-
}
216-
217145
ml_actions_t* ml_allocateActions() {
218146
const ml_model_header_t* const model_header = (ml_model_header_t*)MODEL_ADDRESS;
219147
if (model_header == NULL) {

mlrunner/mlrunner.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,6 @@ int ml_getInputLength();
136136
*/
137137
int ml_getOutputLength();
138138

139-
/**
140-
* @brief Get the model labels.
141-
*
142-
* The label pointers point directly to the strings stored in flash.
143-
*
144-
* @return A pointer to a ml_labels_t object containing the labels.
145-
*/
146-
ml_labels_t* ml_getLabels();
147-
148139
/**
149140
* @brief Allocate memory for the model actions.
150141
*

0 commit comments

Comments
 (0)