-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadc.cpp
40 lines (34 loc) · 850 Bytes
/
adc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//#include "fsl_adc.h"
//#include "../ammdk-carrier/carrier_adc.h"
#include <stdint.h>
#include <stddef.h>
#include "adc.h"
#include "fsl_adc16.h"
#include "../pressuresensor.h"
#include "spi_remote_api.h"
#include "spi_chunk_defines.h"
#include "spi_chunks_slave.h"
int adc_bad_chunks = 0;
//OP_SET currently has no meaning for adcs
void
adc_handle_slave(struct adc_cmd *cmd)
{
if (cmd->id >= ADC_NUM) {adc_bad_chunks++; return;}
uint32_t adc_read;
switch (cmd->cmd) {
case OP_GET:
if (cmd->id < ADC_NUM) {
adc_read = carrier_sensors[cmd->id].raw_pressure;
uint8_t buf[] = {0, CHUNK_TYPE_ADC, cmd->id, OP_GET,
adc_read&0xff, (adc_read>>8)&0xff,
(adc_read>>16)&0xff, (adc_read>>24)&0xff};
send_chunk(buf, 8);
return;
} else {
{adc_bad_chunks++; return;}
}
default:
{adc_bad_chunks++; return;}
}
return;
}