PMK2020_full_os
Dependencies: X_NUCLEO_IKS01A3
main.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file main.cpp 00004 * @author SRA 00005 * @version V1.0.0 00006 * @date 5-March-2019 00007 * @brief Simple Example application for using the X_NUCLEO_IKS01A3 00008 * MEMS Inertial & Environmental Sensor Nucleo expansion board. 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT(c) 2019 STMicroelectronics</center></h2> 00013 * 00014 * Redistribution and use in source and binary forms, with or without modification, 00015 * are permitted provided that the following conditions are met: 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 2. Redistributions in binary form must reproduce the above copyright notice, 00019 * this list of conditions and the following disclaimer in the documentation 00020 * and/or other materials provided with the distribution. 00021 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00022 * may be used to endorse or promote products derived from this software 00023 * without specific prior written permission. 00024 * 00025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00026 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00028 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00029 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00030 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00031 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00033 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00034 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 ****************************************************************************** 00037 */ 00038 00039 /* Includes */ 00040 #include "mbed.h" 00041 #include "XNucleoIKS01A3.h" 00042 00043 /* Instantiate the expansion board */ 00044 static XNucleoIKS01A3 *mems_expansion_board = XNucleoIKS01A3::instance(D14, D15, D4, D5, A3, D6, A4); 00045 00046 /* Retrieve the composing elements of the expansion board */ 00047 static LIS2DW12Sensor *accelerometer = mems_expansion_board->accelerometer; 00048 00049 InterruptIn mybutton(USER_BUTTON); 00050 DigitalOut myled(LED1); 00051 00052 volatile int mems_event = 0; 00053 volatile int send_orientation_request = 0; 00054 00055 /* User button callback. */ 00056 void pressed_cb() 00057 { 00058 send_orientation_request = 1; 00059 } 00060 00061 /* Interrupt 1 callback. */ 00062 void int1_cb() 00063 { 00064 mems_event = 1; 00065 } 00066 00067 /* Print the orientation. */ 00068 void send_orientation() 00069 { 00070 uint8_t xl = 0; 00071 uint8_t xh = 0; 00072 uint8_t yl = 0; 00073 uint8_t yh = 0; 00074 uint8_t zl = 0; 00075 uint8_t zh = 0; 00076 00077 accelerometer->get_6d_orientation_xl(&xl); 00078 accelerometer->get_6d_orientation_xh(&xh); 00079 accelerometer->get_6d_orientation_yl(&yl); 00080 accelerometer->get_6d_orientation_yh(&yh); 00081 accelerometer->get_6d_orientation_zl(&zl); 00082 accelerometer->get_6d_orientation_zh(&zh); 00083 00084 if (xl == 1 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 0) { 00085 printf("\r\n ________________ " \ 00086 "\r\n | | " \ 00087 "\r\n | * | " \ 00088 "\r\n | | " \ 00089 "\r\n | | " \ 00090 "\r\n | | " \ 00091 "\r\n | | " \ 00092 "\r\n |________________| \r\n"); 00093 } 00094 00095 else if (xl == 0 && yl == 1 && zl == 0 && xh == 0 && yh == 0 && zh == 0) { 00096 printf("\r\n ________________ " \ 00097 "\r\n | | " \ 00098 "\r\n | * | " \ 00099 "\r\n | | " \ 00100 "\r\n | | " \ 00101 "\r\n | | " \ 00102 "\r\n | | " \ 00103 "\r\n |________________| \r\n"); 00104 } 00105 00106 else if (xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 1 && zh == 0) { 00107 printf("\r\n ________________ " \ 00108 "\r\n | | " \ 00109 "\r\n | | " \ 00110 "\r\n | | " \ 00111 "\r\n | | " \ 00112 "\r\n | | " \ 00113 "\r\n | * | " \ 00114 "\r\n |________________| \r\n"); 00115 } 00116 00117 else if (xl == 0 && yl == 0 && zl == 0 && xh == 1 && yh == 0 && zh == 0) { 00118 printf("\r\n ________________ " \ 00119 "\r\n | | " \ 00120 "\r\n | | " \ 00121 "\r\n | | " \ 00122 "\r\n | | " \ 00123 "\r\n | | " \ 00124 "\r\n | * | " \ 00125 "\r\n |________________| \r\n"); 00126 } 00127 00128 else if (xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 1) { 00129 printf("\r\n __*_____________ " \ 00130 "\r\n |________________| \r\n"); 00131 } 00132 00133 else if (xl == 0 && yl == 0 && zl == 1 && xh == 0 && yh == 0 && zh == 0) { 00134 printf("\r\n ________________ " \ 00135 "\r\n |________________| " \ 00136 "\r\n * \r\n"); 00137 } 00138 00139 else { 00140 printf("None of the 6D orientation axes is set in LIS2DW12 - accelerometer.\r\n"); 00141 } 00142 } 00143 00144 /* Simple main function */ 00145 int main() 00146 { 00147 /* Attach callback to User button press */ 00148 mybutton.fall(&pressed_cb); 00149 /* Attach callback to LIS2DW12 INT1 */ 00150 accelerometer->attach_int1_irq(&int1_cb); 00151 00152 /* Enable LIS2DW12 accelerometer */ 00153 accelerometer->enable_x(); 00154 /* Enable 6D Orientation. */ 00155 accelerometer->enable_6d_orientation(); 00156 00157 printf("\r\n--- Starting new run ---\r\n"); 00158 00159 while (1) { 00160 if (mems_event) { 00161 mems_event = 0; 00162 LIS2DW12_Event_Status_t status; 00163 accelerometer->get_event_status(&status); 00164 if (status.D6DOrientationStatus) { 00165 /* Send 6D Orientation */ 00166 send_orientation(); 00167 00168 /* Led blinking. */ 00169 myled = 1; 00170 wait(0.2); 00171 myled = 0; 00172 } 00173 } 00174 00175 if (send_orientation_request) { 00176 send_orientation_request = 0; 00177 send_orientation(); 00178 } 00179 } 00180 }
Generated on Mon Jul 25 2022 12:12:39 by 1.7.2