Routine infrastructure
This commit is contained in:
parent
603ef99919
commit
9f005b547b
11 changed files with 527 additions and 30 deletions
44
routines/input_echo.c
Normal file
44
routines/input_echo.c
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
|
||||
#include "includes/routine.h"
|
||||
#include "includes/ble.h"
|
||||
|
||||
static void ble_input_callback(const void *buffer, uint16_t buffer_len);
|
||||
|
||||
routine_return_e
|
||||
input_echo()
|
||||
{
|
||||
ble_register_oninput_callback(ble_input_callback);
|
||||
|
||||
while (routine_status() == ROUTINE_STATUS_RUNNING) {
|
||||
routine_yield();
|
||||
}
|
||||
|
||||
ble_clear_oninput_callback();
|
||||
return (ROUTINE_RETURN_SUCCESS);
|
||||
}
|
||||
|
||||
static void
|
||||
ble_input_callback(const void *buffer, uint16_t buffer_len)
|
||||
{
|
||||
size_t echo_length = snprintk(
|
||||
NULL, 0, "Echo: %.*s",
|
||||
buffer_len, (const char *)buffer
|
||||
);
|
||||
char *echo_buf = k_malloc(echo_length + 1);
|
||||
|
||||
if (echo_buf == NULL) {
|
||||
ble_set_telemetry_data("Alloc failure", 13);
|
||||
return;
|
||||
}
|
||||
|
||||
snprintk(
|
||||
echo_buf, echo_length + 1, "Echo: %.*s",
|
||||
buffer_len, (const char *)buffer
|
||||
);
|
||||
ble_set_telemetry_data(echo_buf, echo_length);
|
||||
k_free(echo_buf);
|
||||
}
|
||||
11
routines/routine_list.c
Normal file
11
routines/routine_list.c
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include <stddef.h>
|
||||
|
||||
#include "core/routine.h"
|
||||
|
||||
/** Extern all of your routines here so they can be included in the list **/
|
||||
extern routine_return_e input_echo();
|
||||
|
||||
const routine_listing_t routine_list[] = {
|
||||
{ .entry = input_echo, .name = "Input Echo" },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
Loading…
Reference in a new issue