Commit 70c40cb92de407a9fb12776b765a4a12b9b3f099
1 parent
ed65270a
changement des fonctions manette.c et joystick .h dans polytech lille et dans le…
…s drivers afin de faire fonctionner le potentiometre de la manette sur 8 bits pour gerer les deux axes, le programme compile, jattends demain pour tester
Showing
2 changed files
with
50 additions
and
17 deletions
Show diff stats
src/lufa-LUFA-170418/LUFA/Drivers/Board/AVR8/PINGUI/Joystick.h
... | ... | @@ -51,9 +51,11 @@ |
51 | 51 | * |
52 | 52 | * @{ |
53 | 53 | */ |
54 | +#include <stdint.h> | |
55 | +#include <avr/io.h> | |
56 | +#ifndef __JOYSTICK_PINGUI_H__ | |
57 | +#define __JOYSTICK_PINGUI_H__ | |
54 | 58 | |
55 | -#ifndef __JOYSTICK_BUMBLEB_H__ | |
56 | -#define __JOYSTICK_BUMBLEB_H__ | |
57 | 59 | |
58 | 60 | /* Includes: */ |
59 | 61 | #include "../../../../Common/Common.h" |
... | ... | @@ -77,12 +79,13 @@ |
77 | 79 | /* Public Interface - May be used in end-application: */ |
78 | 80 | /* Macros: */ |
79 | 81 | /** Mask for the joystick being pushed in the left direction. */ |
80 | - #define JOY_V (1 << 2) | |
82 | + //#define JOY_V (1 << 2) | |
81 | 83 | |
82 | 84 | /** Mask for the joystick being pushed in the upward direction. */ |
83 | - #define JOY_H (1 << 3) | |
85 | + //#define JOY_H (1 << 3) | |
84 | 86 | |
85 | - | |
87 | + #define joy_X_ADC 6 //pour utilisrr l'adc par rapport aux 2 axes | |
88 | + #define joy_Y_ADC 7 | |
86 | 89 | // ** Mask for the joystick being pushed in the right direction. |
87 | 90 | // #define JOY_RIGHT (1 << 0) |
88 | 91 | // |
... | ... | @@ -93,6 +96,29 @@ |
93 | 96 | // #define JOY_PRESS (1 << 4) |
94 | 97 | |
95 | 98 | /* Inline Functions: */ |
99 | +//these are the functions coming from the examples we got on Mr REDON website | |
100 | + | |
101 | + | |
102 | + void adc_init(unsigned char mux) | |
103 | + { | |
104 | + ADCSRA = (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0); // Maximum resolution, take some time | |
105 | + ADCSRA |= (1<<ADEN); // Enable ADC | |
106 | + ADCSRB = (((mux&0x20)==0?0:1)<<MUX5); // Line to use | |
107 | + ADMUX = mux&0x1f; | |
108 | + ADMUX |= (0<<REFS1) | (1<<REFS0); // Reference to AVCC | |
109 | + ADMUX |= (1<<ADLAR); // Left adjusted, it is sufficient to read ADCH | |
110 | + } | |
111 | + | |
112 | + int adc_read(void) | |
113 | + { | |
114 | + ADCSRA |= (1<<ADSC); // Start conversion | |
115 | + while(ADCSRA & (1<<ADSC)); | |
116 | + return ADCH; | |
117 | + } | |
118 | + | |
119 | + | |
120 | + | |
121 | + | |
96 | 122 | #if !defined(__DOXYGEN__) |
97 | 123 | static inline void Joystick_Init(void) |
98 | 124 | { |
... | ... | @@ -112,7 +138,14 @@ |
112 | 138 | static inline uint8_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT; |
113 | 139 | static inline uint8_t Joystick_GetStatus(void) |
114 | 140 | { |
115 | - return (uint8_t)(~PIND & JOY_MASK); | |
141 | + adc_init(joy_X_ADC); | |
142 | + uinit8_t Xquatrebits = adc_read(); | |
143 | + Xquatrebits&=0xF0; //pour les quatres bits de poids fort pour axe X | |
144 | + adc_init(joy_Y_ADC); | |
145 | + uinit8_t Yquatrebits = adc_read(); | |
146 | + Yquatrebits&=0xF0; | |
147 | + Yquatrebits=Yquatrebits>>4 //pour les quatres bits de poids faible pour axe Y, on place en fort et on decale de 4 bits into le poids faible | |
148 | + return (uint8_t)(Xquatrebits+Yquatrebits); | |
116 | 149 | } |
117 | 150 | #endif |
118 | 151 | ... | ... |
src/lufa-LUFA-170418/PolytechLille/Manette/Manette.c
... | ... | @@ -166,23 +166,23 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn |
166 | 166 | USB_JoystickReport_Data_t* JoystickReport = (USB_JoystickReport_Data_t*)ReportData; |
167 | 167 | |
168 | 168 | uint8_t JoyStatus_LCL = Joystick_GetStatus(); |
169 | - uint8_t ButtonStatus_LCL = Buttons_GetStatus_HAUT(); | |
169 | + //uint8_t ButtonStatus_LCL = Buttons_GetStatus_HAUT(); // poir les boutons | |
170 | 170 | |
171 | - if (JoyStatus_LCL & JOY_UP) | |
172 | - JoystickReport->Y = -100; | |
173 | - else if (JoyStatus_LCL & JOY_DOWN) | |
174 | - JoystickReport->Y = 100; | |
175 | 171 | |
176 | - if (JoyStatus_LCL & JOY_LEFT) | |
177 | - JoystickReport->X = -100; | |
178 | - else if (JoyStatus_LCL & JOY_RIGHT) | |
179 | - JoystickReport->X = 100; | |
172 | + JoystickReport->X = JoyStatus_LCL & 0xF0; | |
173 | + JoystickReport->Y = JoyStatus_LCL & 0x0F; | |
174 | + | |
175 | + | |
176 | +// if (JoyStatus_LCL & JOY_LEFT) | |
177 | +// JoystickReport->X = -100; | |
178 | +// else if (JoyStatus_LCL & JOY_RIGHT) | |
179 | +// JoystickReport->X = 100; | |
180 | 180 | |
181 | 181 | /* if (JoyStatus_LCL & JOY_PRESS) |
182 | 182 | JoystickReport->Button |= (1 << 1); |
183 | 183 | */ |
184 | - if (ButtonStatus_LCL & BUTTONS_HAUT) | |
185 | - JoystickReport->Button |= (1 << 0); | |
184 | +// if (ButtonStatus_LCL & BUTTONS_HAUT) | |
185 | +// JoystickReport->Button |= (1 << 0); | |
186 | 186 | |
187 | 187 | *ReportSize = sizeof(USB_JoystickReport_Data_t); |
188 | 188 | return false; | ... | ... |