-
Notifications
You must be signed in to change notification settings - Fork 25
/
davega_util.cpp
85 lines (73 loc) · 2.6 KB
/
davega_util.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
Copyright 2018 Jan Pomikalek <[email protected]>
This file is part of the DAVEga firmware.
DAVEga firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAVEga firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DAVEga firmware. If not, see <https://www.gnu.org/licenses/>.
*/
#include "davega_util.h"
#include "vesc_comm.h"
char fw_version_buffer[6];
const char* make_fw_version(const char* fw_version, const char* revision_id) {
if (fw_version[0] == 'v') {
return fw_version;
}
else {
String r = String("r");
String upper_rev_id = String(revision_id).substring(5, 9);
upper_rev_id.toUpperCase();
r.concat(upper_rev_id);
r.toCharArray(fw_version_buffer, sizeof(fw_version_buffer));
return fw_version_buffer;
}
}
float convert_distance(float distance_km, bool imperial_units)
{
if (imperial_units)
return distance_km * KM_PER_MILE;
else
return distance_km;
}
float convert_speed(float speed_kph, bool imperial_units)
{
return convert_distance(speed_kph, imperial_units);
}
float convert_temperature(float temp_celsius, bool imperial_units) {
if (imperial_units)
return temp_celsius * 9.0 / 5.0 + 32;
else
return temp_celsius;
}
void format_total_distance(float total_distance, char* result) {
if (total_distance >= 1000)
dtostrf(((int) round(total_distance)) % 10000, 4, 0, result);
else
dtostrf(total_distance, 5, 1, result);
}
const char* vesc_fault_code_to_string(vesc_comm_fault_code fault_code) {
switch (fault_code) {
case FAULT_CODE_NONE:
return "FAULT CODE NONE";
case FAULT_CODE_OVER_VOLTAGE:
return "OVER VOLTAGE";
case FAULT_CODE_UNDER_VOLTAGE:
return "UNDER VOLTAGE";
case FAULT_CODE_DRV:
return "DRV FAULT";
case FAULT_CODE_ABS_OVER_CURRENT:
return "OVER CURRENT";
case FAULT_CODE_OVER_TEMP_FET:
return "OVER TEMP FET";
case FAULT_CODE_OVER_TEMP_MOTOR:
return "OVER TEMP MOTOR";
default:
return "unexpected fault code";
}
}