Compare commits
3 Commits
8b98d85a24
...
1305a9727c
| Author | SHA1 | Date |
|---|---|---|
|
|
1305a9727c | |
|
|
1e86c7a162 | |
|
|
269d2a1e96 |
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue