This repository has been archived by the owner on Jun 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
KLS.h
77 lines (59 loc) · 1.48 KB
/
KLS.h
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
/*
* William Zhang
* Written to interface with KLS 12201-8080I
* motor controller over CAN
* Uses pawelsky fork of FlexCAN library found at
* https://github.com/pawelsky/FlexCAN_Library
*/
#ifndef __KLS_H__
#define __KLS_H__
#define MAX_PWM 13000
#include <FlexCAN.h>
#include <kinetis_flexcan.h>
#include <cstdlib>
#include <string>
#include "pindef.h"
typedef struct KLS_switches {
bool hall_a;
bool hall_b;
bool hall_c;
bool brake;
bool backward;
bool forward;
bool foot;
bool boost;
} KLS_switches;
typedef struct KLS_errors {
uint8_t count;
bool errors[16] = {0};
} KLS_errors;
typedef struct KLS_status {
uint32_t rpm;
float current;
float voltage;
float throttle;
uint32_t controller_temp;
uint32_t motor_temp;
bool command_status;
bool feedback_status;
KLS_switches switches;
KLS_errors errors;
} KLS_status;
class KLS {
private:
uint8_t id;
public:
KLS_status status;
KLS(uint8_t addr);
uint8_t parse(const CAN_message_t &msg);
KLS_errors parse_errors(uint8_t lsb, uint8_t msb);
void set_throttle(uint32_t value);
void regen_en(bool value); // untested
void set_regen(uint32_t value); // untested
void set_direction(int8_t value); // untested
static void eco_en(boolean value); // untested
void update(const KLS_status &new_status);
void update(uint32_t rpm, float current, float voltage, float throttle);
void print();
};
#endif // __KLS_H__