@Alex-Kushleyev I have it included, heres my full main file:
#include <stdio.h> // for fprintf
#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include <modal_pipe.h>
#include <voxl_cutils.h>
#include <voxl_io.h>
#include "hello_cross.h"
#define CLIENT_NAME "hello-cross"
static char en_newline = 0;
static char imu_name[64];
static int opt = 0;
static int device = 1; // default. /dev/ttyHS1
static int baud = 115200;
void printHelloCross(void);
// called whenever we disconnect from the server
static void _disconnect_cb(__attribute__((unused)) int ch, __attribute__((unused)) void *context)
{
fprintf(stderr, "\r" CLEAR_LINE FONT_BLINK "server disconnected" RESET_FONT);
return;
}
// called when the simple helper has data for us
static void _helper_cb(__attribute__((unused)) int ch, char *data, int bytes, __attribute__((unused)) void *context)
{
const uint8_t MIN_WRITE_LEN = 32;
uint8_t write_buf[MIN_WRITE_LEN];
// validate that the data makes sense
int n_packets;
imu_data_t *data_array = pipe_validate_imu_data_t(data, bytes, &n_packets);
if (data_array == NULL)
return;
// print everything in one go.
if (!en_newline)
printf("\r" CLEAR_LINE);
printf("%7.2f|%7.2f|%7.2f|%7.2f|%7.2f|%7.2f",
(double)data_array[n_packets - 1].accl_ms2[0],
(double)data_array[n_packets - 1].accl_ms2[1],
(double)data_array[n_packets - 1].accl_ms2[2],
(double)data_array[n_packets - 1].gyro_rad[0],
(double)data_array[n_packets - 1].gyro_rad[1],
(double)data_array[n_packets - 1].gyro_rad[2]);
if (en_newline)
printf("\n");
int write_res = voxl_uart_write(device, write_buf, MIN_WRITE_LEN);
if (write_res < 0)
{
//ERROR("Failed to write to UART");
return;
}
fflush(stdout);
return;
}
int main(int argc, char *const argv[])
{
enable_signal_handler();
main_running = 1;
int uart_res = voxl_uart_init(device, baud, 1.0, 0, 1, 0);
if (uart_res < 0)
{
//ERROR("Failed to open port");
return 1;
}
pipe_client_set_simple_helper_cb(0, _helper_cb, NULL);
pipe_client_set_disconnect_cb(0, _disconnect_cb, NULL);
int pipe_open_res = pipe_client_open(0, imu_name, CLIENT_NAME,
EN_PIPE_CLIENT_SIMPLE_HELPER,
IMU_RECOMMENDED_READ_BUF_SIZE);
if (pipe_open_res < 0)
{
pipe_print_error(pipe_open_res);
printf(ENABLE_WRAP);
return -1;
}
// keep going until the signal handler sets the running flag to 0
while (main_running)
usleep(500000);
// all done, signal pipe read threads to stop
printf("\nclosing and exiting\n" RESET_FONT ENABLE_WRAP);
pipe_client_close_all();
int ret = voxl_uart_close(device);
if (ret < 0)
{
//ERROR("Failed to close UART device");
return 1;
}
}
void printHelloCross()
{
printf(" Imu Acceleration and Gyro\n");
printf(" X | Y | Z | X | Y | Z\n");
}