1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/shell/commands/sc_l3g4200d.c
kushalsingh007 9aae656be9 shell: Return-based error-handling for shell handlers
- Included the missing parts.
- Squashed with @authmillenon's commit
2015-03-25 23:54:04 +05:30

78 lines
1.6 KiB
C

/*
* Copyright (C) 2014 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup sys_shell_commands
* @{
*
* @file
* @brief Provides shell commands to poll the L3G4200D sensor
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#include <stdio.h>
#include "board.h"
#include "l3g4200d.h"
#ifdef MODULE_L3G4200D
#define MODE L3G4200D_MODE_100_25
#define SCALE L3G4200D_SCALE_500DPS
static l3g4200d_t l3g4200d_dev;
int _get_l3g4200d_init_handler(int argc, char **argv)
{
(void)argc;
(void)argv;
int res;
res = l3g4200d_init(&l3g4200d_dev, L3G4200D_I2C, L3G4200D_ADDR,
L3G4200D_INT, L3G4200D_DRDY,
MODE, SCALE);
if (res) {
puts("Error initializing L3G4200D sensor.");
return 1;
}
else {
puts("Initialized L3G4200D sensor with default values");
return 0;
}
}
int _get_l3g4200d_read_handler(int argc, char **argv)
{
(void)argc;
(void)argv;
int res;
l3g4200d_data_t data;
if (!l3g4200d_dev.addr) {
puts("Error: please call `l3g4200d_init` first!");
return 1;
}
res = l3g4200d_read(&l3g4200d_dev, &data);
if (res < 0) {
puts("Error reading gyro values from L3G4200D.");
return 1;
}
else {
printf("L3G4200D: gyro values: roll(x): %6i pitch(y): %6i yaw(z): %6i\n",
data.acc_x, data.acc_y, data.acc_z);
return 0;
}
}
#endif /* MODULE_L3G4200D */