accel: Add per-axis accel scale helpers

This commit is contained in:
Bastien Nocera
2020-05-04 11:32:03 +02:00
parent ed427251b7
commit 1b8c1c6b37
3 changed files with 63 additions and 2 deletions

View File

@@ -30,8 +30,10 @@ iio_sensor_proxy_SOURCES = \
iio-buffer-utils.c \
accel-mount-matrix.h \
accel-mount-matrix.c \
accel-attributes.h \
accel-attributes.c \
accel-attributes.h \
accel-attributes.c \
accel-scale.h \
accel-scale.c \
$(BUILT_SOURCES)
iio_sensor_proxy_CPPFLAGS = \

39
src/accel-scale.c Normal file
View File

@@ -0,0 +1,39 @@
/*
* Copyright (c) 2020 Bastien Nocera <hadess@hadess.net>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published by
* the Free Software Foundation.
*
*/
#include <glib.h>
#include "accel-scale.h"
void
reset_accel_scale (AccelScale *scale)
{
set_accel_scale (scale, 1.0);
}
void
set_accel_scale (AccelScale *scale,
double value)
{
g_return_if_fail (scale != NULL);
g_return_if_fail (value != 0.0);
scale->x = scale->y = scale->z = value;
}
void
copy_accel_scale (AccelScale *target,
AccelScale source)
{
g_return_if_fail (target != NULL);
target->x = source.x;
target->y = source.y;
target->z = source.z;
}

20
src/accel-scale.h Normal file
View File

@@ -0,0 +1,20 @@
/*
* Copyright (c) 2020 Bastien Nocera <hadess@hadess.net>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published by
* the Free Software Foundation.
*
*/
#pragma once
typedef struct {
double x;
double y;
double z;
} AccelScale;
void reset_accel_scale (AccelScale *scale);
void set_accel_scale (AccelScale *scale, double value);
void copy_accel_scale (AccelScale *target, AccelScale source);