-
Notifications
You must be signed in to change notification settings - Fork 0
/
PaddleClutch.h
95 lines (73 loc) · 2.67 KB
/
PaddleClutch.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
PaddleClutch.h - PaddleClutch manager class
Created by Morgan Gardner, December 10th, 2020.
Modified by Morgan Gardner, June 30th, 2021.
Released under the GPL-3.0 license.
*/
#ifndef PaddleClutch_h
#define PaddleClutch_h
#include "Arduino.h"
class PaddleClutch
{
public:
struct calibration
{
uint16_t lpMin;
uint16_t lpMax;
uint16_t rpMin;
uint16_t rpMax;
uint16_t btptMin; //for potentiometer bitepoint
uint16_t btptMax; //for potentiometer bitepoint
uint16_t btptValue;
} calibVals;
PaddleClutch()
{
}
uint16_t getClutchOutput(uint16_t leftPaddleReading, uint16_t rightPaddleReading)
{
uint16_t leftPaddleConstVal = constrain(leftPaddleReading, calibVals.lpMin, calibVals.lpMax);
uint16_t leftPaddleMappedVal = map(leftPaddleConstVal, calibVals.lpMin, calibVals.lpMax, 0, 1023);
this->lpValue = leftPaddleMappedVal;
uint16_t rightPaddleConstVal = constrain(rightPaddleReading, calibVals.rpMin, calibVals.rpMax);
uint16_t rightPaddleMappedVal = map(rightPaddleConstVal, calibVals.rpMin, calibVals.rpMax, 0, 1023);
this->rpValue = rightPaddleMappedVal;
uint16_t leftPaddleMapped = map(leftPaddleMappedVal, 0, 1023, 0, calibVals.btptValue); //map left paddle max to btpt pot val
if (rightPaddleMappedVal > leftPaddleMapped) //if right paddle val is higher than left
return rightPaddleMappedVal; //set output val to right paddle
else
return leftPaddleMapped; //set output val to left paddle
}
uint16_t updateBitePoint(uint16_t value) //potentiometer bite point set
{
uint16_t btptConstVal = constrain(value, calibVals.btptMin, calibVals.btptMax);
uint16_t btptMappedVal = map(btptConstVal, calibVals.btptMin, calibVals.btptMax, 0, 1023);
calibVals.btptValue = btptMappedVal;
}
uint16_t updateBitePointPercent(uint16_t value) //RaceX bite point set (0-100%)
{
calibVals.btptValue = map(value, 0, 100, 0, 1023);
}
uint16_t updateBitePoint() //button bite point set
{
calibVals.btptValue = rpValue;
}
void setLeftPaddleRange(uint16_t min, uint16_t max)
{
calibVals.lpMin = min;
calibVals.lpMax = max;
}
void setRightPaddleRange(uint16_t min, uint16_t max)
{
calibVals.rpMin = min;
calibVals.rpMax = max;
}
void setBitePointPotRange(uint16_t min, uint16_t max)
{
calibVals.btptMin = min;
calibVals.btptMax = max;
}
private:
uint16_t lpValue; //left paddle value
uint16_t rpValue; //right paddle value
};
#endif