Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
rpm.h
Go to the documentation of this file.
1#include <math.h>
2#include <algorithm>
3#include <iterator>
4
6{
7 int input;
8 char output[4];
9};
11
12void rpm_2_byte(float rr_rpm, char *rr_rpm_byte)
13{
14 /*
15 1st we multiply rpm by 100 to get a 2 decimal place value.
16 The roundf() function rounds rpm to the nearest integer value.
17 */
18 data.input = roundf(rr_rpm * 100);
19 /*
20 The order of the bytes in the output array depends on the endianness the system.
21 -> little-endian system, the least significant byte will be at output[0],
22 and the most significant byte will be at output[3].
23 -> big-endian system, it's the other way around.
24 */
25 std::copy(std::begin(data.output), std::end(data.output), rr_rpm_byte);
26
27 return;
28}
float rr_rpm
Definition main.cpp:80
void rpm_2_byte(float rr_rpm, char *rr_rpm_byte)
Definition rpm.h:12
float2bytes data
Definition rpm.h:10
char output[4]
Definition rpm.h:8
int input
Definition rpm.h:7