Compare commits

..

No commits in common. "1305a9727c27e696d0b20d2c9cda144ca78dea4e" and "8b98d85a246456c6be014c8fb4214f7193b1d27e" have entirely different histories.

3 changed files with 14 additions and 13 deletions

View File

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

View File

@ -5,7 +5,7 @@
#include <hardware/adc.h> #include <hardware/adc.h>
#include "headers/controller.h" #include "headers/controller.h"
#define JOYSTICK_DEAD_ZONE 5 #define JOYSTICK_DEAD_ZONE 3
void inputs_init(void) void inputs_init(void)
{ {
@ -25,17 +25,14 @@ void inputs_init(void)
void inputs_update(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 // Update joystick x and y position
adc_select_input(JOYSTICK_X_AXIS_ADC_INPUT); adc_select_input(JOYSTICK_X_AXIS_ADC_INPUT);
uint16_t joystick_raw = adc_read(); uint16_t joystick_raw = adc_read();
controller.inputs.joystick_x = (joystick_raw >> 3) - 256; controller.inputs.joystick_x = (joystick_raw >> 4) - 128;
adc_select_input(JOYSTICK_Y_AXIS_ADC_INPUT); adc_select_input(JOYSTICK_Y_AXIS_ADC_INPUT);
joystick_raw = adc_read(); joystick_raw = adc_read();
controller.inputs.joystick_y = (joystick_raw >> 3) - 256; controller.inputs.joystick_y = (joystick_raw >> 4) - 128;
// Dead zone // Dead zone
if(abs(controller.inputs.joystick_x) < JOYSTICK_DEAD_ZONE) if(abs(controller.inputs.joystick_x) < JOYSTICK_DEAD_ZONE)

View File

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