Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/Microchip/PIC32MX320F128H/PmodGYRO2/Command.c

raw symbols SCIP
1 /***************************************************************************//**
2 * @file Command.c
3 * @brief Implementation of the commands given by user through UART for PmodACL.
4 * @author DBogdan ([email protected])
5 ********************************************************************************
6 * Copyright 2013(c) Analog Devices, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * - Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 * - The use of this software may or may not infringe the patent rights
22 * of one or more patent holders. This license does not release you
23 * from the requirement that you obtain separate licenses from these
24 * patent holders to use this software.
25 * - Use of the software either in source or binary form, must be run
26 * on or directly connected to an Analog Devices Inc. component.
27 *
28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *
39 *******************************************************************************/
40
41 /******************************************************************************/
42 /***************************** Include Files **********************************/
43 /******************************************************************************/
44 #include "Communication.h"
45 #include "Command.h"
46 #include "ADXRS453.h"
47 #include "Console.h"
48
49 /******************************************************************************/
50 /************************ Constants Definitions *******************************/
51 /******************************************************************************/
52
53 /*!< List of available commands */
54 const char* cmdList[] = {"help?",
55 "temperature?",
56 "measure!"};
57 const char* cmdDescription[] = {
58 " - Displays all available commands.",
59 " - Displays the ambient temperature.",
60 " - Starts measurement for 30 samples."};
61 const char* cmdExample[] = {
62 "",
63 "",
64 ""};
65
66 const char cmdNo = (sizeof(cmdList) / sizeof(const char*));
67
68 /******************************************************************************/
69 /************************ Variables Definitions *******************************/
70 /******************************************************************************/
71 cmdFunction cmdFunctions[3] = {GetHelp, GetTemperature, DoMeasure};
72
73 /******************************************************************************/
74 /************************ Functions Description *******************************/
75 /******************************************************************************/
76
77 /***************************************************************************//**
78 * @brief Displays all available commands.
79 *
80 * @return None.
81 *******************************************************************************/
82 void GetHelp(double* param, char paramNo) /*!< "help?" command */
83 {
84 char displayCmd;
85
86 CONSOLE_Print("Available commands:\r\n");
87 for(displayCmd = 0; displayCmd < cmdNo; displayCmd++)
88 {
89 CONSOLE_Print("%s%s\r\n", (char*)cmdList[displayCmd],
90 (char*)cmdDescription[displayCmd]);
91 }
92 }
93
94 /***************************************************************************//**
95 * @brief Initializes the device.
96 *
97 * @return - The result of the initialization.
98 * Example: ERROR - the device was not initialized or the device
99 * is not present.
100 * SUCCES - the device was initialized and the device
101 * is present.
102 *******************************************************************************/
103 char DoDeviceInit(void)
104 {
105
106 if(ADXRS453_Init() == 0)
107 {
108 CONSOLE_Print("ADXRS453 OK\r\n");
109 GetHelp(NULL, 0);
110 return SUCCESS;
111 }
112 else
113 {
114 CONSOLE_Print("ADXRS453 Error\r\n");
115
116 return ERROR;
117 }
118 }
119
120
121 /***************************************************************************//**
122 * @brief Displays the temperature.
123 *
124 * @return None.
125 *******************************************************************************/
126 void GetTemperature(double* param, char paramNo) /*!< "temperature?" command */
127 {
128 float temperature = 0; /*!< Last read value. */
129
130 /*!< Read temperature from the device */
131 temperature = ADXRS453_GetTemperature();
132 /*!< Send the requested value to user */
133 CONSOLE_Print("temperature=%.1f [C]\r\n",temperature);
134 }
135
136 /***************************************************************************//**
137 * @brief Displays the angular velocity for 30 samples.
138 *
139 * @return None.
140 *******************************************************************************/
141 void DoMeasure(double* param, char paramNo) /*!< "measure!" command */
142 {
143 unsigned long samplesNr = 0; /*!< Number of samples read from the device */
144 unsigned short rxData = 0; /*!< Angular velocity(raw data)*/
145 double angularVelocity = 0; /*!< Angular velocity(degrees/second) */
146
147 samplesNr = 30;
148 while(samplesNr)
149 {
150 angularVelocity = ADXRS453_GetRate();
151
152 /*!< Send the requested value to user */
153 CONSOLE_Print("%.2f [deg/s]\r\n",angularVelocity);
154 TIME_DelayMs(200);
155 samplesNr --;
156 }
157 /*!< Measurement process has finished */
158 CONSOLE_Print("Measurement done.\r\n");
159 }