Add calibration and separate the interface
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
parent
a863ff6b9f
commit
2c23021a5e
8 changed files with 760 additions and 367 deletions
135
interface_lib/include/device3.h
Normal file
135
interface_lib/include/device3.h
Normal file
|
@ -0,0 +1,135 @@
|
|||
#pragma once
|
||||
//
|
||||
// Created by thejackimonster on 30.03.23.
|
||||
//
|
||||
// Copyright (c) 2023 thejackimonster. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct __attribute__((__packed__)) device3_packet_t {
|
||||
uint8_t signature [2];
|
||||
uint8_t _padding0 [2];
|
||||
uint64_t timestamp;
|
||||
uint8_t _padding1 [6];
|
||||
uint8_t angular_velocity_x [3];
|
||||
uint8_t angular_velocity_y [3];
|
||||
uint8_t angular_velocity_z [3];
|
||||
uint8_t _padding2 [6];
|
||||
uint8_t acceleration_x [3];
|
||||
uint8_t acceleration_y [3];
|
||||
uint8_t acceleration_z [3];
|
||||
uint8_t _padding3 [6];
|
||||
int16_t magnetic_x;
|
||||
int16_t magnetic_y;
|
||||
int16_t magnetic_z;
|
||||
uint32_t checksum;
|
||||
uint8_t _padding4 [6];
|
||||
};
|
||||
|
||||
enum device3_event_t {
|
||||
DEVICE3_EVENT_UNKNOWN = 0,
|
||||
DEVICE3_EVENT_INIT = 1,
|
||||
DEVICE3_EVENT_UPDATE = 2,
|
||||
};
|
||||
|
||||
struct device3_ahrs_t;
|
||||
struct device3_calibration_t;
|
||||
|
||||
struct device3_vec3_t {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
};
|
||||
|
||||
struct device3_quat_t {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float w;
|
||||
};
|
||||
|
||||
typedef struct device3_packet_t device3_packet_type;
|
||||
typedef enum device3_event_t device3_event_type;
|
||||
|
||||
typedef struct device3_ahrs_t device3_ahrs_type;
|
||||
typedef struct device3_calibration_t device3_calibration_type;
|
||||
|
||||
typedef struct device3_vec3_t device3_vec3_type;
|
||||
typedef struct device3_quat_t device3_quat_type;
|
||||
|
||||
typedef void (*device3_event_callback)(
|
||||
uint64_t timestamp,
|
||||
device3_event_type event,
|
||||
const device3_ahrs_type* ahrs
|
||||
);
|
||||
|
||||
struct device3_t {
|
||||
uint16_t vendor_id;
|
||||
uint16_t product_id;
|
||||
|
||||
void* context;
|
||||
void* handle;
|
||||
|
||||
uint8_t interface_number;
|
||||
|
||||
uint8_t endpoint_address_in;
|
||||
uint8_t max_packet_size_in;
|
||||
|
||||
uint8_t endpoint_address_out;
|
||||
uint8_t max_packet_size_out;
|
||||
|
||||
bool detached;
|
||||
bool claimed;
|
||||
|
||||
uint64_t last_timestamp;
|
||||
|
||||
void* offset;
|
||||
device3_ahrs_type* ahrs;
|
||||
|
||||
device3_event_callback callback;
|
||||
device3_calibration_type* calibration;
|
||||
};
|
||||
|
||||
typedef struct device3_t device3_type;
|
||||
|
||||
device3_type* device3_open(device3_event_callback callback);
|
||||
|
||||
void device3_reset_calibration(device3_type* device);
|
||||
|
||||
int device3_load_calibration(device3_type* device, const char* path);
|
||||
|
||||
int device3_save_calibration(device3_type* device, const char* path);
|
||||
|
||||
int device3_calibrate(device3_type* device, uint32_t iterations, bool gyro, bool accel, bool magnet);
|
||||
|
||||
int device3_read(device3_type* device, int timeout);
|
||||
|
||||
device3_vec3_type device3_get_earth_acceleration(const device3_ahrs_type* ahrs);
|
||||
|
||||
device3_vec3_type device3_get_linear_acceleration(const device3_ahrs_type* ahrs);
|
||||
|
||||
device3_quat_type device3_get_orientation(const device3_ahrs_type* ahrs);
|
||||
|
||||
device3_vec3_type device3_get_euler(device3_quat_type quat);
|
||||
|
||||
void device3_close(device3_type* device);
|
102
interface_lib/include/device4.h
Normal file
102
interface_lib/include/device4.h
Normal file
|
@ -0,0 +1,102 @@
|
|||
#pragma once
|
||||
//
|
||||
// Created by thejackimonster on 29.03.23.
|
||||
//
|
||||
// Copyright (c) 2023 thejackimonster. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define DEVICE4_ACTION_PASSIVE_POLL_START 0b00010
|
||||
#define DEVICE4_ACTION_BRIGHTNESS_COMMAND 0b00011
|
||||
#define DEVICE4_ACTION_MANUAL_POLL_CLICK 0b00101
|
||||
#define DEVICE4_ACTION_ACTIVE_POLL 0b01001
|
||||
#define DEVICE4_ACTION_PASSIVE_POLL_END 0b10010
|
||||
|
||||
#define DEVICE4_BUTTON_DISPLAY_TOGGLE 0x1
|
||||
#define DEVICE4_BUTTON_BRIGHTNESS_UP 0x2
|
||||
#define DEVICE4_BUTTON_BRIGHTNESS_DOWN 0x3
|
||||
|
||||
struct __attribute__((__packed__)) device4_packet_t {
|
||||
uint8_t signature;
|
||||
uint32_t checksum;
|
||||
uint16_t length;
|
||||
uint8_t _padding0 [4];
|
||||
uint32_t timestamp;
|
||||
uint8_t action;
|
||||
uint8_t _padding1 [6];
|
||||
union {
|
||||
char text [42];
|
||||
uint8_t data [42];
|
||||
};
|
||||
};
|
||||
|
||||
enum device4_event_t {
|
||||
DEVICE4_EVENT_UNKNOWN = 0,
|
||||
DEVICE4_EVENT_SCREEN_ON = 1,
|
||||
DEVICE4_EVENT_SCREEN_OFF = 2,
|
||||
DEVICE4_EVENT_BRIGHTNESS_SET = 3,
|
||||
DEVICE4_EVENT_BRIGHTNESS_UP = 4,
|
||||
DEVICE4_EVENT_BRIGHTNESS_DOWN = 5,
|
||||
DEVICE4_EVENT_MESSAGE = 6,
|
||||
};
|
||||
|
||||
typedef struct device4_packet_t device4_packet_type;
|
||||
typedef enum device4_event_t device4_event_type;
|
||||
typedef void (*device4_event_callback)(
|
||||
uint32_t timestamp,
|
||||
device4_event_type event,
|
||||
uint8_t brightness,
|
||||
const char* msg
|
||||
);
|
||||
|
||||
struct device4_t {
|
||||
uint16_t vendor_id;
|
||||
uint16_t product_id;
|
||||
|
||||
void* context;
|
||||
void* handle;
|
||||
|
||||
uint8_t interface_number;
|
||||
|
||||
uint8_t endpoint_address_in;
|
||||
uint8_t max_packet_size_in;
|
||||
|
||||
uint8_t endpoint_address_out;
|
||||
uint8_t max_packet_size_out;
|
||||
|
||||
bool detached;
|
||||
bool claimed;
|
||||
bool active;
|
||||
|
||||
uint8_t brightness;
|
||||
|
||||
device4_event_callback callback;
|
||||
};
|
||||
|
||||
typedef struct device4_t device4_type;
|
||||
|
||||
device4_type* device4_open(device4_event_callback callback);
|
||||
|
||||
int device4_read(device4_type* device, int timeout);
|
||||
|
||||
void device4_close(device4_type* device);
|
Reference in a new issue