#include <stdlib.h>
#include <string.h>
#include "mcu.h"
#define EXECUTION_TIME_US 500
#define GET_TEMPERATURE_EP 12
#define SEND_TEMPERATURE_EP 13
static uint32_t temperature = 0;
static void set_string_from_value(uint32_t value,
uint8_t * bytes,
uint8_t max_bytes)
{
for (int i = max_bytes - 1; i >= 0; i--)
{
bytes[i] = value % 10 + 0x30;
value /= 10;
}
}
static const uint8_t decimal[4] = { 0, 25, 50, 75 };
uint32_t send_temperature(void)
{
uint8_t answer[13] = "TEMP is 00,00";
set_string_from_value(temperature >> 2, &answer[8], 2);
set_string_from_value(decimal[temperature % 4], &answer[11], 2);
data_to_send.
bytes = (
const uint8_t *) &answer;
lib_data->sendData(&data_to_send);
}
static void temp_interrupt_handler(void)
{
NRF_TEMP->INTENCLR = 1;
if (NRF_TEMP->EVENTS_DATARDY != 0)
{
temperature = NRF_TEMP->TEMP;
}
else
{
temperature = 0;
}
0,
EXECUTION_TIME_US);
}
static void start_temperature_measurement()
{
temperature = 0;
NRF_TEMP->TASKS_START = 1;
NRF_TEMP->INTENSET = 1;
}
{
{
start_temperature_measurement();
}
}
{
{
return;
}
lib_data->setDataReceivedCb(unicastDataReceivedCb);
lib_state->startStack();
}