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
5
union
float2bytes
6
{
7
int
input
;
8
char
output
[4];
9
};
10
float2bytes
data
;
11
12
void
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
}
rr_rpm
float rr_rpm
Definition
main.cpp:80
rpm_2_byte
void rpm_2_byte(float rr_rpm, char *rr_rpm_byte)
Definition
rpm.h:12
data
float2bytes data
Definition
rpm.h:10
float2bytes
Definition
rpm.h:6
float2bytes::output
char output[4]
Definition
rpm.h:8
float2bytes::input
int input
Definition
rpm.h:7
c1
include
rpm.h
Generated by
1.9.8