1 /***************************************************************************
2     Process Inputs.
3 
4     - Read & Process inputs and controls.
5     - Note, this class does not contain platform specific code.
6 
7     Copyright Chris White.
8     See license.txt for more details.
9 ***************************************************************************/
10 
11 #pragma once
12 
13 #include "sdl2/input.hpp"
14 #include "outrun.hpp"
15 
16 class OInputs
17 {
18 public:
19 
20     const static uint8_t BRAKE_THRESHOLD1 = 0x80;
21     const static uint8_t BRAKE_THRESHOLD2 = 0xA0;
22     const static uint8_t BRAKE_THRESHOLD3 = 0xC0;
23     const static uint8_t BRAKE_THRESHOLD4 = 0xE0;
24 
25     int8_t crash_input;
26 
27     // Acceleration Input
28     int16_t input_acc;
29 
30     // Steering Input
31     int16_t input_steering;
32 
33     // Processed / Adjusted Values
34     int16_t steering_adjust;
35     int16_t acc_adjust;
36     int16_t brake_adjust;
37 
38     // True = High Gear. False = Low Gear.
39     bool gear;
40 
41     OInputs(void);
42     ~OInputs(void);
43 
44     void init();
45     void tick();
46     void adjust_inputs();
47     void do_gear();
48     uint8_t do_credits();
49 
50     bool is_analog_l();
51     bool is_analog_r();
52     bool is_analog_select();
53 
54 private:
55     // ------------------------------------------------------------------------
56     // Variables for port
57     // ------------------------------------------------------------------------
58 
59     // Amount to adjust steering per tick. (0x3 is a good test value)
60     uint8_t steering_inc;
61 
62     // Amount to adjust acceleration per tick. (0x10 is a good test value)
63     uint8_t acc_inc;
64 
65     // Amount to adjust brake per tick. (0x10 is a good test value)
66     uint8_t brake_inc;
67 
68     static const int DELAY_RESET = 40;
69     int delay1, delay2, delay3;
70 
71     // Coin Inputs (Only used by CannonBoard)
72     bool coin1, coin2;
73 
74     // ------------------------------------------------------------------------
75     // Variables from original code
76     // ------------------------------------------------------------------------
77 
78     const static uint8_t STEERING_MIN = 0x48;
79     const static uint8_t STEERING_MAX = 0xB8;
80     const static uint8_t STEERING_CENTRE = 0x80;
81 
82     // Current steering value
83     int16_t steering_old;
84     int16_t steering_change;
85 
86     const static uint8_t PEDAL_MIN = 0x30;
87     const static uint8_t PEDAL_MAX = 0x90;
88 
89     // Brake Input
90     int16_t input_brake;
91 
92     void digital_steering();
93     void digital_pedals();
94 };
95 
96 extern OInputs oinputs;
97