-
Notifications
You must be signed in to change notification settings - Fork 11
/
shifter.cpp
45 lines (38 loc) · 889 Bytes
/
shifter.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
#include "shifter.h"
#include "update.h"
#include <Servo.h>
const float klowgear = 0.8;
const float kneutral = 0.5;
const float khighgear = 0.2;
shifter::shifter(Servo& a, Servo& b) {
shift1 = &a;
shift2 = &b;
cur_gear = LOW;
registry().register_func(update_helper, (void*)this);
}
shifter::~shifter() {
registry().unregister_func(update_helper, (void*)this);
}
void shifter::set(GEAR g) {
cur_gear = g;
}
void shifter::update() {
const float * servoval;
switch (cur_gear) {
default:
case LOW:
servoval = &klowgear;
break;
case HIGH:
servoval = &khighgear;
break;
case NEUTRAL:
servoval = &kneutral;
break;
}
shift1->Set(*servoval);
shift2->Set(*servoval);
}
void shifter::update_helper(void * obj) {
((shifter*)obj)->update();
}