mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-30 02:20:48 +00:00
Previously our accel / gyro drivers assumed that we had exactly two of each identical part in the system. Some systems may have different configurations, so allow this to be specified at the board-level. Note that our motion_sense algorithm currently assumes that we have one accelerometer in the lid and one in the base -- we'll need to fix that in another CL. BUG=chrome-os-partner:27320 TEST=Compile-only. Tested in future Samus commit. BRANCH=None. Change-Id: I1fae1f6c578fedebe78b473a5d66a5794ccaae00 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/212321 Reviewed-by: Alec Berg <alecaberg@chromium.org>
53 lines
1.2 KiB
C
53 lines
1.2 KiB
C
/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*
|
|
* Test motion sense code.
|
|
*/
|
|
|
|
#include <math.h>
|
|
|
|
#include "math_util.h"
|
|
#include "motion_sense.h"
|
|
#include "test_util.h"
|
|
#include "util.h"
|
|
|
|
/*****************************************************************************/
|
|
/* Need to define motion sensor globals just to compile. */
|
|
const struct motion_sensor_t motion_sensors[] = {};
|
|
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
|
|
|
|
/*****************************************************************************/
|
|
/* Test utilities */
|
|
|
|
/* Macro to compare two floats and check if they are equal within diff. */
|
|
#define IS_FLOAT_EQUAL(a, b, diff) ((a) >= ((b) - diff) && (a) <= ((b) + diff))
|
|
|
|
#define ACOS_TOLERANCE_DEG 0.5f
|
|
#define RAD_TO_DEG (180.0f / 3.1415926f)
|
|
|
|
static int test_acos(void)
|
|
{
|
|
float a, b;
|
|
float test;
|
|
|
|
/* Test a handful of values. */
|
|
for (test = -1.0; test <= 1.0; test += 0.01) {
|
|
a = arc_cos(test);
|
|
b = acos(test) * RAD_TO_DEG;
|
|
TEST_ASSERT(IS_FLOAT_EQUAL(a, b, ACOS_TOLERANCE_DEG));
|
|
}
|
|
|
|
return EC_SUCCESS;
|
|
}
|
|
|
|
|
|
void run_test(void)
|
|
{
|
|
test_reset();
|
|
|
|
RUN_TEST(test_acos);
|
|
|
|
test_print_result();
|
|
}
|