Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2105 | - | 1 | #include "main.h" |
2 | #include "calibration.h" |
||
3 | #include "frame.h" |
||
4 | #include "file.h" |
||
5 | #include "gpio.h" |
||
6 | |||
7 | |||
8 | void calibrate(void){ |
||
9 | frame_print("Please calibrate. Begin with Layout, assign buttons and axis:\n", 1, 0); |
||
10 | int i = 0; |
||
11 | while(i < NUMBER_OF_AXES_USED){ |
||
12 | frame_print("\n (Axis) ", 0, 0); |
||
13 | frame_print(LablesOfAxis[i], 0, 0); |
||
14 | int u = -1; |
||
15 | int axisDefault = 0; |
||
16 | while(1){if(!value_sum(1)){break;}} //Wait until all buttons released |
||
17 | while(u == -1){ |
||
18 | for (int p = 0; p < NumberOfAxesAvailiable; p++) |
||
19 | { |
||
20 | read_gamepad_data(); |
||
21 | if(u == -1 && Axis[p] != axisDefault){u = p;} |
||
22 | } |
||
23 | } |
||
24 | GamepadLayout[i] = u; |
||
25 | i++; |
||
26 | frame_print(" check", 0, 0); |
||
27 | buzzer_short(1); |
||
28 | } |
||
29 | while(i < (NUMBER_OF_BUTTONS_USED + NUMBER_OF_AXES_USED)){ |
||
30 | frame_print("\n (Button) ", 0, 0); |
||
31 | frame_print(LablesOfButtons[i - NUMBER_OF_AXES_USED], 0, 0); |
||
32 | int u = -1; |
||
33 | while(1){if(!value_sum(0)){break;}} |
||
34 | while(u == -1){ |
||
35 | u = check_if_button_pushed(); |
||
36 | } |
||
37 | GamepadLayout[i] = u; |
||
38 | i++; |
||
39 | frame_print(" check", 0, 0); |
||
40 | buzzer_short(1); |
||
41 | } |
||
42 | while(1){if(!value_sum(0)){break;}} |
||
43 | frame_print("Press Button 1 to continue...", 1, 1); |
||
44 | while(!check_if_button_pushed() == 0){}; |
||
45 | buzzer_short(1); |
||
46 | frame_print("To calibrate the maximum value of the axis, \n pull and hold the assigned CamNick axis at the maximum \n and store the value by pressing any button.\n\n Maximum Value of Nick axis: ", 1, 0); |
||
47 | while(1){if(!value_sum(0)){break;}} |
||
48 | while(1){ |
||
49 | read_gamepad_data(); |
||
50 | if(value_sum(0)) |
||
51 | { |
||
52 | MaxAxisValue = Axis[GamepadLayout[0]]; |
||
53 | break; |
||
54 | } |
||
55 | } |
||
56 | buzzer_short(1); |
||
57 | fflush(stdout); |
||
58 | frame_print(" check", 0, 0); |
||
59 | write_file(); |
||
60 | frame_print("", 1, 0); |
||
61 | } |
||
62 | |||
63 | //>> Ensuring that no button is being pushed and no axis moved |
||
64 | //------------------------------------------------------------------------------------------------------ |
||
65 | int value_sum(int q){ |
||
66 | read_gamepad_data(); |
||
67 | int tmp = 0; |
||
68 | if(q) |
||
69 | { |
||
70 | for (int i = 0; i < NumberOfAxesAvailiable; ++i) |
||
71 | { |
||
72 | tmp += Axis[i]; |
||
73 | } |
||
74 | } |
||
75 | if(!q) |
||
76 | { |
||
77 | for (int i = 0; i < NumberOfButtonsAvailiable; ++i) |
||
78 | { |
||
79 | tmp += Button[i]; |
||
80 | } |
||
81 | } |
||
82 | return(tmp); |
||
83 | } |
||
84 | |||
85 | //>> Initializing calibration of Gamepad |
||
86 | //------------------------------------------------------------------------------------------------------ |
||
87 | void calibration_init(){ |
||
88 | if(FileExists){ |
||
89 | frame_stay("Found Profile!\n\n Pad connected:\n %s\n %d Axis\n %d Buttons", GamepadConnected, NUMBER_OF_AXES_USED, NUMBER_OF_BUTTONS_USED); |
||
90 | frame_print("Press Button 1 for recalibration .", 1, 1); |
||
91 | int i = 0; |
||
92 | buzzer_short(1); |
||
93 | while(i < 1000){ |
||
94 | if(check_if_button_pushed() == 0){ |
||
95 | i = 1; |
||
96 | buzzer_short(3); |
||
97 | break; |
||
98 | } |
||
99 | usleep(5000); |
||
100 | if(!(i%100)){ |
||
101 | frame_print(" .", 0, 1); |
||
102 | buzzer_short(1); |
||
103 | } |
||
104 | i++; |
||
105 | } |
||
106 | if(i == 1) |
||
107 | { |
||
108 | calibrate(); |
||
109 | frame_print("START", 1, 1); |
||
110 | }else |
||
111 | { |
||
112 | while(1){if(!value_sum(0)){break;} |
||
113 | } |
||
114 | frame_print("START", 1, 1); |
||
115 | } |
||
116 | }else{ |
||
117 | buzzer_short(5); |
||
118 | frame_stay("No Profile found!\n\n Pad connected:\n %s\n %d Axis\n %d Buttons", GamepadConnected, NUMBER_OF_AXES_USED, NUMBER_OF_BUTTONS_USED); |
||
119 | calibrate(); |
||
120 | frame_print("START", 1, 1); |
||
121 | } |
||
122 | } |