Compare commits

...

3 Commits

Author SHA1 Message Date
Ulysse Cura 1305a9727c Changed encoding of joystick value for more precision. 2026-02-20 17:30:27 +01:00
Ulysse Cura 1e86c7a162 Removed counter 2026-02-20 17:29:16 +01:00
Ulysse Cura 269d2a1e96 Corrected pins 2026-02-20 17:28:45 +01:00
3 changed files with 13 additions and 14 deletions

View File

@ -12,16 +12,16 @@ typedef enum inputs_pin_t {
BUTTON_WHITE_PIN = 6,
BUTTON_GREEN_PIN = 2,
BUTTON_L_PIN = 9,
BUTTON_R_PIN = 13,
BUTTON_L_PIN = 13,
BUTTON_R_PIN = 9,
} inputs_pin_t;
#define JOYSTICK_X_AXIS_ADC_INPUT 0
#define JOYSTICK_Y_AXIS_ADC_INPUT 1
typedef struct inputs_t {
int8_t joystick_x;
int8_t joystick_y;
int16_t joystick_x;
int16_t joystick_y;
struct {
bool button_black : 1;

View File

@ -5,7 +5,7 @@
#include <hardware/adc.h>
#include "headers/controller.h"
#define JOYSTICK_DEAD_ZONE 3
#define JOYSTICK_DEAD_ZONE 5
void inputs_init(void)
{
@ -25,14 +25,17 @@ void inputs_init(void)
void inputs_update(void)
{
// Encoding in 9 bits for values to be between -256 and 255, not optimal now,
// but useful later during transaction between the main controller and the motion controller.
// Update joystick x and y position
adc_select_input(JOYSTICK_X_AXIS_ADC_INPUT);
uint16_t joystick_raw = adc_read();
controller.inputs.joystick_x = (joystick_raw >> 4) - 128;
controller.inputs.joystick_x = (joystick_raw >> 3) - 256;
adc_select_input(JOYSTICK_Y_AXIS_ADC_INPUT);
joystick_raw = adc_read();
controller.inputs.joystick_y = (joystick_raw >> 4) - 128;
controller.inputs.joystick_y = (joystick_raw >> 3) - 256;
// Dead zone
if(abs(controller.inputs.joystick_x) < JOYSTICK_DEAD_ZONE)

View File

@ -4,8 +4,8 @@
#include <string.h>
#include "headers/controller.h"
#define MSG_LEN (sizeof(uint16_t) + sizeof(inputs_t)) / sizeof(uint8_t)
#define MSG_DELAY_MS 50.0f
#define MSG_LEN (sizeof(inputs_t)) / sizeof(uint8_t)
#define MSG_DELAY_MS 20.0f
int udp_server_init(void)
{
@ -30,8 +30,6 @@ void udp_server_send(void)
static float elapsed_time_ms = 0.0f;
elapsed_time_ms += controller.delta_time_ms;
static uint8_t counter = 0;
if(elapsed_time_ms >= MSG_DELAY_MS)
{
static union data_t {
@ -40,9 +38,8 @@ void udp_server_send(void)
} hard;
uint8_t raw[MSG_LEN];
} data = {0};
} data;
//data.hard.packet_number++; // Auto looping
data.hard.inputs = controller.inputs;
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, MSG_LEN, PBUF_RAM);
@ -58,7 +55,6 @@ void udp_server_send(void)
}
elapsed_time_ms = 0.0f;
counter++;
}
}