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_WHITE_PIN = 6,
|
||||||
BUTTON_GREEN_PIN = 2,
|
BUTTON_GREEN_PIN = 2,
|
||||||
|
|
||||||
BUTTON_L_PIN = 9,
|
BUTTON_L_PIN = 13,
|
||||||
BUTTON_R_PIN = 13,
|
BUTTON_R_PIN = 9,
|
||||||
} 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 {
|
||||||
int8_t joystick_x;
|
int16_t joystick_x;
|
||||||
int8_t joystick_y;
|
int16_t joystick_y;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
bool button_black : 1;
|
bool button_black : 1;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include <hardware/adc.h>
|
#include <hardware/adc.h>
|
||||||
#include "headers/controller.h"
|
#include "headers/controller.h"
|
||||||
|
|
||||||
#define JOYSTICK_DEAD_ZONE 3
|
#define JOYSTICK_DEAD_ZONE 5
|
||||||
|
|
||||||
void inputs_init(void)
|
void inputs_init(void)
|
||||||
{
|
{
|
||||||
|
|
@ -25,14 +25,17 @@ 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 >> 4) - 128;
|
controller.inputs.joystick_x = (joystick_raw >> 3) - 256;
|
||||||
|
|
||||||
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 >> 4) - 128;
|
controller.inputs.joystick_y = (joystick_raw >> 3) - 256;
|
||||||
|
|
||||||
// Dead zone
|
// Dead zone
|
||||||
if(abs(controller.inputs.joystick_x) < JOYSTICK_DEAD_ZONE)
|
if(abs(controller.inputs.joystick_x) < JOYSTICK_DEAD_ZONE)
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "headers/controller.h"
|
#include "headers/controller.h"
|
||||||
|
|
||||||
#define MSG_LEN (sizeof(uint16_t) + sizeof(inputs_t)) / sizeof(uint8_t)
|
#define MSG_LEN (sizeof(inputs_t)) / sizeof(uint8_t)
|
||||||
#define MSG_DELAY_MS 50.0f
|
#define MSG_DELAY_MS 20.0f
|
||||||
|
|
||||||
int udp_server_init(void)
|
int udp_server_init(void)
|
||||||
{
|
{
|
||||||
|
|
@ -30,8 +30,6 @@ 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 {
|
||||||
|
|
@ -40,9 +38,8 @@ void udp_server_send(void)
|
||||||
} hard;
|
} hard;
|
||||||
|
|
||||||
uint8_t raw[MSG_LEN];
|
uint8_t raw[MSG_LEN];
|
||||||
} data = {0};
|
} data;
|
||||||
|
|
||||||
//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);
|
||||||
|
|
@ -58,7 +55,6 @@ void udp_server_send(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
elapsed_time_ms = 0.0f;
|
elapsed_time_ms = 0.0f;
|
||||||
counter++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue