mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-14 10:46:51 -07:00
Finish Motion in Setsu
This commit is contained in:
parent
698bce8022
commit
88c03aa744
5 changed files with 160 additions and 26 deletions
|
@ -8,9 +8,29 @@
|
|||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <signal.h>
|
||||
#include <math.h>
|
||||
|
||||
Setsu *setsu;
|
||||
|
||||
#define NAME_LEN 8
|
||||
const char * const names[] = {
|
||||
"accel x ",
|
||||
"accel y ",
|
||||
"accel z ",
|
||||
" gyro x ",
|
||||
" gyro y ",
|
||||
" gyro z "
|
||||
};
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
float accel_x, accel_y, accel_z;
|
||||
float gyro_x, gyro_y, gyro_z;
|
||||
};
|
||||
float v[6];
|
||||
} vals;
|
||||
uint32_t timestamp;
|
||||
bool dirty = false;
|
||||
bool log_mode;
|
||||
volatile bool should_quit;
|
||||
|
@ -22,14 +42,44 @@ void sigint(int s)
|
|||
should_quit = true;
|
||||
}
|
||||
|
||||
#define BAR_LENGTH 100
|
||||
#define BAR_MAX 2.0f
|
||||
#define BAR_MAX_GYRO 180.0f
|
||||
|
||||
void print_state()
|
||||
{
|
||||
#if 0
|
||||
char buf[256];
|
||||
*buf = 0;
|
||||
char buf[6 * (1 + NAME_LEN + BAR_LENGTH) + 1];
|
||||
size_t i = 0;
|
||||
for(size_t b=0; b<6; b++)
|
||||
{
|
||||
buf[i++] = '\n';
|
||||
memcpy(buf + i, names[b], NAME_LEN);
|
||||
i += NAME_LEN;
|
||||
buf[i++] = '[';
|
||||
size_t max = BAR_LENGTH-2;
|
||||
for(size_t bi=0; bi<max; bi++)
|
||||
{
|
||||
#define BAR_VAL(x) ((b > 2 ? BAR_MAX_GYRO : BAR_MAX) * (2.0f * (float)(x) / (float)max - 1.0f))
|
||||
float cur = BAR_VAL(bi);
|
||||
float prev = BAR_VAL((int)bi - 1);
|
||||
if(prev < 0.0f && cur >= 0.0f)
|
||||
{
|
||||
buf[i++] = '|';
|
||||
continue;
|
||||
}
|
||||
bool cov = ((vals.v[b] < 0.0f) == (cur < 0.0f)) && fabsf(vals.v[b]) > fabsf(cur);
|
||||
float next = BAR_VAL(bi + 1);
|
||||
#define MARK_VAL (b > 2 ? 90.0f : 1.0f)
|
||||
bool mark = cur < -MARK_VAL && next >= -MARK_VAL || prev < MARK_VAL && cur >= MARK_VAL;
|
||||
buf[i++] = cov ? (mark ? '#' : '=') : (mark ? '.' : ' ');
|
||||
#undef BAR_VAL
|
||||
}
|
||||
buf[i++] = ']';
|
||||
}
|
||||
buf[i++] = '\0';
|
||||
assert(i == sizeof(buf));
|
||||
printf("\033[2J%s", buf);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
}
|
||||
|
||||
void event(SetsuEvent *event, void *user)
|
||||
|
@ -49,7 +99,19 @@ void event(SetsuEvent *event, void *user)
|
|||
break;
|
||||
LOG("Device removed: %s\n", event->path);
|
||||
break;
|
||||
// TODO: motion events
|
||||
case SETSU_EVENT_MOTION:
|
||||
LOG("Motion: %f, %f, %f / %f, %f, %f / %u\n",
|
||||
event->motion.accel_x, event->motion.accel_y, event->motion.accel_z,
|
||||
event->motion.gyro_x, event->motion.gyro_y, event->motion.gyro_z,
|
||||
(unsigned int)event->motion.timestamp);
|
||||
vals.accel_x = event->motion.accel_x;
|
||||
vals.accel_y = event->motion.accel_y;
|
||||
vals.accel_z = event->motion.accel_z;
|
||||
vals.gyro_x = event->motion.gyro_x;
|
||||
vals.gyro_y = event->motion.gyro_y;
|
||||
vals.gyro_z = event->motion.gyro_z;
|
||||
timestamp = event->motion.timestamp;
|
||||
dirty = true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -80,13 +80,13 @@ void event(SetsuEvent *event, void *user)
|
|||
LOG("Device removed: %s\n", event->path);
|
||||
break;
|
||||
case SETSU_EVENT_TOUCH_DOWN:
|
||||
LOG("Down for %s, tracking id %d\n", setsu_device_get_path(event->dev), event->tracking_id);
|
||||
LOG("Down for %s, tracking id %d\n", setsu_device_get_path(event->dev), event->touch.tracking_id);
|
||||
for(size_t i=0; i<TOUCHES_MAX; i++)
|
||||
{
|
||||
if(!touches[i].down)
|
||||
{
|
||||
touches[i].down = true;
|
||||
touches[i].tracking_id = event->tracking_id;
|
||||
touches[i].tracking_id = event->touch.tracking_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -94,19 +94,19 @@ void event(SetsuEvent *event, void *user)
|
|||
case SETSU_EVENT_TOUCH_POSITION:
|
||||
case SETSU_EVENT_TOUCH_UP:
|
||||
if(event->type == SETSU_EVENT_TOUCH_UP)
|
||||
LOG("Up for %s, tracking id %d\n", setsu_device_get_path(event->dev), event->tracking_id);
|
||||
LOG("Up for %s, tracking id %d\n", setsu_device_get_path(event->dev), event->touch.tracking_id);
|
||||
else
|
||||
LOG("Position for %s, tracking id %d: %u, %u\n", setsu_device_get_path(event->dev),
|
||||
event->tracking_id, (unsigned int)event->x, (unsigned int)event->y);
|
||||
event->touch.tracking_id, (unsigned int)event->touch.x, (unsigned int)event->touch.y);
|
||||
for(size_t i=0; i<TOUCHES_MAX; i++)
|
||||
{
|
||||
if(touches[i].down && touches[i].tracking_id == event->tracking_id)
|
||||
if(touches[i].down && touches[i].tracking_id == event->touch.tracking_id)
|
||||
{
|
||||
switch(event->type)
|
||||
{
|
||||
case SETSU_EVENT_TOUCH_POSITION:
|
||||
touches[i].x = event->x;
|
||||
touches[i].y = event->y;
|
||||
touches[i].x = event->touch.x;
|
||||
touches[i].y = event->touch.y;
|
||||
break;
|
||||
case SETSU_EVENT_TOUCH_UP:
|
||||
touches[i].down = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue