mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-17 04:15:44 +00:00
d/psmv: Add variable tracking
This commit is contained in:
parent
676bc81f40
commit
9192c9c6b5
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include "xrt/xrt_prober.h"
|
#include "xrt/xrt_prober.h"
|
||||||
|
|
||||||
|
#include "util/u_var.h"
|
||||||
#include "util/u_time.h"
|
#include "util/u_time.h"
|
||||||
#include "util/u_misc.h"
|
#include "util/u_misc.h"
|
||||||
#include "util/u_debug.h"
|
#include "util/u_debug.h"
|
||||||
|
@ -270,12 +271,16 @@ struct psmv_device
|
||||||
|
|
||||||
struct os_hid_device *hid;
|
struct os_hid_device *hid;
|
||||||
|
|
||||||
int64_t resend_time;
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
uint8_t red;
|
int64_t resend_time;
|
||||||
uint8_t green;
|
struct xrt_colour_rgb_u8 led;
|
||||||
uint8_t blue;
|
uint8_t rumble;
|
||||||
|
} wants;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
struct xrt_colour_rgb_u8 led;
|
||||||
uint8_t rumble;
|
uint8_t rumble;
|
||||||
} state;
|
} state;
|
||||||
|
|
||||||
|
@ -494,20 +499,29 @@ static void
|
||||||
psmv_led_and_trigger_update(struct psmv_device *psmv, int64_t time)
|
psmv_led_and_trigger_update(struct psmv_device *psmv, int64_t time)
|
||||||
{
|
{
|
||||||
// Need to keep sending led control packets to keep the leds on.
|
// Need to keep sending led control packets to keep the leds on.
|
||||||
if (psmv->resend_time > time) {
|
if (psmv->wants.resend_time > time &&
|
||||||
|
psmv->state.led.r == psmv->wants.led.r &&
|
||||||
|
psmv->state.led.g == psmv->wants.led.g &&
|
||||||
|
psmv->state.led.b == psmv->wants.led.b &&
|
||||||
|
psmv->state.rumble == psmv->wants.rumble) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
psmv->resend_time = time + 1000000000;
|
psmv->state.led.r = psmv->wants.led.r;
|
||||||
psmv_send_led_control(psmv, psmv->state.red, psmv->state.green,
|
psmv->state.led.g = psmv->wants.led.g;
|
||||||
psmv->state.blue, psmv->state.rumble);
|
psmv->state.led.b = psmv->wants.led.b;
|
||||||
|
psmv->state.rumble = psmv->wants.rumble;
|
||||||
|
|
||||||
|
psmv->wants.resend_time = time + 1000000000;
|
||||||
|
psmv_send_led_control(psmv, psmv->state.led.r, psmv->state.led.g,
|
||||||
|
psmv->state.led.b, psmv->state.rumble);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
psmv_force_led_and_rumble_update(struct psmv_device *psmv, int64_t time)
|
psmv_force_led_and_rumble_update(struct psmv_device *psmv, int64_t time)
|
||||||
{
|
{
|
||||||
// Force a resend;
|
// Force a resend;
|
||||||
psmv->resend_time = 0;
|
psmv->wants.resend_time = 0;
|
||||||
psmv_led_and_trigger_update(psmv, time);
|
psmv_led_and_trigger_update(psmv, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -618,6 +632,9 @@ psmv_device_destroy(struct xrt_device *xdev)
|
||||||
{
|
{
|
||||||
struct psmv_device *psmv = psmv_device(xdev);
|
struct psmv_device *psmv = psmv_device(xdev);
|
||||||
|
|
||||||
|
// Remove the variable tracking.
|
||||||
|
u_var_remove_root(psmv);
|
||||||
|
|
||||||
if (psmv->hid != NULL) {
|
if (psmv->hid != NULL) {
|
||||||
psmv_send_led_control(psmv, 0x00, 0x00, 0x00, 0x00);
|
psmv_send_led_control(psmv, 0x00, 0x00, 0x00, 0x00);
|
||||||
|
|
||||||
|
@ -677,7 +694,7 @@ psmv_device_set_output(struct xrt_device *xdev,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
psmv->state.rumble =
|
psmv->wants.rumble =
|
||||||
psmv_clamp_zero_to_one_float_to_u8(value->vibration.amplitude);
|
psmv_clamp_zero_to_one_float_to_u8(value->vibration.amplitude);
|
||||||
|
|
||||||
// Force a resend;
|
// Force a resend;
|
||||||
|
@ -685,6 +702,7 @@ psmv_device_set_output(struct xrt_device *xdev,
|
||||||
psmv_force_led_and_rumble_update(psmv, now);
|
psmv_force_led_and_rumble_update(psmv, now);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* Prober functions.
|
* Prober functions.
|
||||||
|
@ -744,12 +762,12 @@ psmv_found(struct xrt_prober *xp,
|
||||||
|
|
||||||
static int hack = 0;
|
static int hack = 0;
|
||||||
switch (hack++ % 3) {
|
switch (hack++ % 3) {
|
||||||
case 0: psmv->state.red = 0xff; break;
|
case 0: psmv->wants.led.r = 0xff; break;
|
||||||
case 1:
|
case 1:
|
||||||
psmv->state.red = 0xff;
|
psmv->wants.led.r = 0xff;
|
||||||
psmv->state.blue = 0xff;
|
psmv->wants.led.b = 0xff;
|
||||||
break;
|
break;
|
||||||
case 2: psmv->state.blue = 0xff; break;
|
case 2: psmv->wants.led.b = 0xff; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get calibration data.
|
// Get calibration data.
|
||||||
|
@ -766,6 +784,13 @@ psmv_found(struct xrt_prober *xp,
|
||||||
// Clear any packets
|
// Clear any packets
|
||||||
psmv_read_hid(psmv);
|
psmv_read_hid(psmv);
|
||||||
|
|
||||||
|
// Start the variable tracking now that everything is in place.
|
||||||
|
u_var_add_root(psmv, "PSMV Controller", true);
|
||||||
|
u_var_add_rgb_u8(psmv, &psmv->wants.led, "Led");
|
||||||
|
u_var_add_u8(psmv, &psmv->wants.rumble, "Rumble");
|
||||||
|
u_var_add_bool(psmv, &psmv->print_debug, "Debug");
|
||||||
|
u_var_add_bool(psmv, &psmv->print_spew, "Spew");
|
||||||
|
|
||||||
// And finally done
|
// And finally done
|
||||||
*out_xdevs = &psmv->base;
|
*out_xdevs = &psmv->base;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue