
Example showing how to integrate EASE with proximity Sensor and Base board
Dependencies: mbed EsmacatShield X_NUCLEO_6180XA1
Information about Esmacat and EASE is provided in the link below. https://os.mbed.com/users/pratima_hb/code/EASE_Example/wiki/Homepage
Information about the hardware needs and setup is provided in the link below. https://os.mbed.com/users/pratima_hb/code/EASE_Example/wiki/Hardware-Setup
Information about the structure of the system and it's software is provided in the link below. https://os.mbed.com/users/pratima_hb/code/EASE_Example/wiki/Software
main.cpp@6:318b85f6e6a5, 2020-02-07 (annotated)
- Committer:
- pratima_hb
- Date:
- Fri Feb 07 23:15:39 2020 +0000
- Revision:
- 6:318b85f6e6a5
- Parent:
- 4:84dfc00ae7b3
Example code explaining how to use EASE with Proximity sensor and a base board
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pratima_hb | 6:318b85f6e6a5 | 1 | /** |
pratima_hb | 6:318b85f6e6a5 | 2 | ****************************************************************************** |
pratima_hb | 6:318b85f6e6a5 | 3 | * @file main.cpp |
pratima_hb | 6:318b85f6e6a5 | 4 | * @date February 07, 2020 |
pratima_hb | 6:318b85f6e6a5 | 5 | * @brief mbed test application Esmacat Shield working together with |
pratima_hb | 6:318b85f6e6a5 | 6 | * STMicroelectronics X-NUCLEO-6180XA1 |
pratima_hb | 6:318b85f6e6a5 | 7 | * The Expansion Board for range measurement and als measurement. |
pratima_hb | 6:318b85f6e6a5 | 8 | *The original code is by STMicroelectronics which is modified to integrate EASE. |
pratima_hb | 6:318b85f6e6a5 | 9 | *The Copyright of STMicroelectronics is retained below. |
pratima_hb | 6:318b85f6e6a5 | 10 | ****************************************************************************** |
pratima_hb | 6:318b85f6e6a5 | 11 | |
pratima_hb | 6:318b85f6e6a5 | 12 | Copyright (c) 2020 https://www.esmacat.com/ |
pratima_hb | 6:318b85f6e6a5 | 13 | |
pratima_hb | 6:318b85f6e6a5 | 14 | Licensed under the Apache License, Version 2.0 (the "License"); |
pratima_hb | 6:318b85f6e6a5 | 15 | you may not use this file except in compliance with the License. |
pratima_hb | 6:318b85f6e6a5 | 16 | You may obtain a copy of the License at |
pratima_hb | 6:318b85f6e6a5 | 17 | |
pratima_hb | 6:318b85f6e6a5 | 18 | http://www.apache.org/licenses/LICENSE-2.0 |
pratima_hb | 6:318b85f6e6a5 | 19 | |
pratima_hb | 6:318b85f6e6a5 | 20 | Unless required by applicable law or agreed to in writing, software |
pratima_hb | 6:318b85f6e6a5 | 21 | distributed under the License is distributed on an "AS IS" BASIS, |
pratima_hb | 6:318b85f6e6a5 | 22 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
pratima_hb | 6:318b85f6e6a5 | 23 | See the License for the specific language governing permissions and |
pratima_hb | 6:318b85f6e6a5 | 24 | limitations under the License. |
pratima_hb | 6:318b85f6e6a5 | 25 | |
pratima_hb | 6:318b85f6e6a5 | 26 | EsmacatShield.h - Library for using EtherCAT Arduino Shield by Esmacat(EASE). |
pratima_hb | 6:318b85f6e6a5 | 27 | Created by Esmacat, 01/22/2020 |
pratima_hb | 6:318b85f6e6a5 | 28 | |
pratima_hb | 6:318b85f6e6a5 | 29 | ******************************************************************************* |
pratima_hb | 6:318b85f6e6a5 | 30 | * @file EsmacatShield.h |
pratima_hb | 6:318b85f6e6a5 | 31 | ******************************************************************************* |
pratima_hb | 6:318b85f6e6a5 | 32 | */ |
pratima_hb | 6:318b85f6e6a5 | 33 | |
Davidroid | 4:84dfc00ae7b3 | 34 | /* |
Davidroid | 4:84dfc00ae7b3 | 35 | This VL6180X Expansion board test application performs a range measurement |
Davidroid | 4:84dfc00ae7b3 | 36 | and an als measurement in interrupt mode on the onboard embedded top sensor. |
Davidroid | 4:84dfc00ae7b3 | 37 | The board red slider selects on the flight the measurement type as ALS or |
Davidroid | 4:84dfc00ae7b3 | 38 | RANGE; the measured data is diplayed on the on bord 4digits display. |
Davidroid | 4:84dfc00ae7b3 | 39 | |
Davidroid | 4:84dfc00ae7b3 | 40 | User Blue button allows to stop current measurement and the entire program |
Davidroid | 4:84dfc00ae7b3 | 41 | releasing all the resources. |
Davidroid | 4:84dfc00ae7b3 | 42 | Reset button is used to restart the program. |
Davidroid | 4:84dfc00ae7b3 | 43 | |
Davidroid | 4:84dfc00ae7b3 | 44 | Polling operating modes don`t require callback function that handles IRQ |
Davidroid | 4:84dfc00ae7b3 | 45 | callbacks. IRQ functions are used only for measures that require interrupts. |
Davidroid | 4:84dfc00ae7b3 | 46 | |
Davidroid | 4:84dfc00ae7b3 | 47 | Notes: |
Davidroid | 4:84dfc00ae7b3 | 48 | + get_measurement() is asynchronous! It returns NOT_READY if the measurement |
Davidroid | 4:84dfc00ae7b3 | 49 | value is not ready to be read from the corresponding register. So you need |
Davidroid | 4:84dfc00ae7b3 | 50 | to wait for the result to be ready.\ |
Davidroid | 4:84dfc00ae7b3 | 51 | */ |
Davidroid | 4:84dfc00ae7b3 | 52 | |
Davidroid | 4:84dfc00ae7b3 | 53 | |
Davidroid | 4:84dfc00ae7b3 | 54 | /* Includes ------------------------------------------------------------------*/ |
Davidroid | 4:84dfc00ae7b3 | 55 | |
mapellil | 0:b706d6b7c1d3 | 56 | #include "mbed.h" |
Davidroid | 4:84dfc00ae7b3 | 57 | #include "XNucleo6180XA1.h" |
mapellil | 0:b706d6b7c1d3 | 58 | #include <string.h> |
mapellil | 0:b706d6b7c1d3 | 59 | #include <stdlib.h> |
mapellil | 0:b706d6b7c1d3 | 60 | #include <stdio.h> |
mapellil | 0:b706d6b7c1d3 | 61 | #include <assert.h> |
pratima_hb | 6:318b85f6e6a5 | 62 | #include <EsmacatShield.h> //Esmacat : Include Esmacat Shield Library |
pratima_hb | 6:318b85f6e6a5 | 63 | |
mapellil | 0:b706d6b7c1d3 | 64 | |
mapellil | 0:b706d6b7c1d3 | 65 | |
Davidroid | 4:84dfc00ae7b3 | 66 | /* Definitions ---------------------------------------------------------------*/ |
mapellil | 0:b706d6b7c1d3 | 67 | |
mapellil | 0:b706d6b7c1d3 | 68 | #define VL6180X_I2C_SDA D14 |
mapellil | 0:b706d6b7c1d3 | 69 | #define VL6180X_I2C_SCL D15 |
mapellil | 0:b706d6b7c1d3 | 70 | |
mapellil | 0:b706d6b7c1d3 | 71 | #define RANGE 0 |
mapellil | 0:b706d6b7c1d3 | 72 | #define ALS 1 |
mapellil | 0:b706d6b7c1d3 | 73 | |
Davidroid | 3:d3719ebf51c4 | 74 | #define DELAY 2000 // 2Sec |
Davidroid | 3:d3719ebf51c4 | 75 | |
Davidroid | 3:d3719ebf51c4 | 76 | |
Davidroid | 4:84dfc00ae7b3 | 77 | /* Types ---------------------------------------------------------------------*/ |
Davidroid | 4:84dfc00ae7b3 | 78 | |
pratima_hb | 6:318b85f6e6a5 | 79 | |
pratima_hb | 6:318b85f6e6a5 | 80 | /* Esmacat communication------------------------------------------------------*/ |
pratima_hb | 6:318b85f6e6a5 | 81 | DigitalOut selectPin(D10); // D10 is used to drive chip enable low |
pratima_hb | 6:318b85f6e6a5 | 82 | SPI spi(D11, D12, D13); // mosi, miso, sclk |
pratima_hb | 6:318b85f6e6a5 | 83 | EsmacatShield slave(spi, selectPin); // EsmacatShield Slave object creation |
pratima_hb | 6:318b85f6e6a5 | 84 | int sendToEsmacat; |
pratima_hb | 6:318b85f6e6a5 | 85 | bool led_on; |
pratima_hb | 6:318b85f6e6a5 | 86 | /* Esmacat communication------------------------------------------------------*/ |
pratima_hb | 6:318b85f6e6a5 | 87 | |
Davidroid | 4:84dfc00ae7b3 | 88 | /* Operating mode */ |
Davidroid | 4:84dfc00ae7b3 | 89 | operating_mode_t operating_mode, prev_operating_mode; |
Davidroid | 4:84dfc00ae7b3 | 90 | enum op_mode_int_poll_t { |
Davidroid | 4:84dfc00ae7b3 | 91 | PollMeasure, |
Davidroid | 4:84dfc00ae7b3 | 92 | IntMeasure |
Davidroid | 4:84dfc00ae7b3 | 93 | }; |
Davidroid | 4:84dfc00ae7b3 | 94 | |
Davidroid | 4:84dfc00ae7b3 | 95 | |
Davidroid | 4:84dfc00ae7b3 | 96 | /* Variables -----------------------------------------------------------------*/ |
Davidroid | 4:84dfc00ae7b3 | 97 | |
Davidroid | 3:d3719ebf51c4 | 98 | /* Expansion board */ |
Davidroid | 4:84dfc00ae7b3 | 99 | static XNucleo6180XA1 *board = NULL; |
Davidroid | 3:d3719ebf51c4 | 100 | |
Davidroid | 3:d3719ebf51c4 | 101 | /* Measure data */ |
Davidroid | 4:84dfc00ae7b3 | 102 | measure_data_t data_sensor_top; |
Davidroid | 3:d3719ebf51c4 | 103 | |
Davidroid | 3:d3719ebf51c4 | 104 | /* Flags that handle interrupt request */ |
Davidroid | 3:d3719ebf51c4 | 105 | bool int_sensor_top = false, int_stop_measure = false; |
mapellil | 0:b706d6b7c1d3 | 106 | |
Davidroid | 4:84dfc00ae7b3 | 107 | |
Davidroid | 4:84dfc00ae7b3 | 108 | /* Functions -----------------------------------------------------------------*/ |
Davidroid | 4:84dfc00ae7b3 | 109 | |
mapellil | 0:b706d6b7c1d3 | 110 | /* ISR callback function of the sensor_top */ |
Davidroid | 4:84dfc00ae7b3 | 111 | void sensor_top_irq(void) |
mapellil | 0:b706d6b7c1d3 | 112 | { |
Davidroid | 3:d3719ebf51c4 | 113 | int_sensor_top = true; |
Davidroid | 4:84dfc00ae7b3 | 114 | board->sensor_top->disable_interrupt_measure_detection_irq(); |
Davidroid | 3:d3719ebf51c4 | 115 | } |
mapellil | 0:b706d6b7c1d3 | 116 | |
mapellil | 0:b706d6b7c1d3 | 117 | /* ISR callback function of the user blue button to stop program */ |
Davidroid | 4:84dfc00ae7b3 | 118 | void stop_measure_irq(void) |
mapellil | 0:b706d6b7c1d3 | 119 | { |
Davidroid | 3:d3719ebf51c4 | 120 | int_stop_measure = true; |
mapellil | 0:b706d6b7c1d3 | 121 | } |
mapellil | 0:b706d6b7c1d3 | 122 | |
mapellil | 0:b706d6b7c1d3 | 123 | /* On board 4 digit local display refresh */ |
Davidroid | 4:84dfc00ae7b3 | 124 | void display_refresh(operating_mode_t op_mode) |
Davidroid | 3:d3719ebf51c4 | 125 | { |
Davidroid | 3:d3719ebf51c4 | 126 | char str[5]; |
Davidroid | 3:d3719ebf51c4 | 127 | |
Davidroid | 3:d3719ebf51c4 | 128 | if (op_mode==range_continuous_interrupt || op_mode==range_continuous_polling) { |
Davidroid | 3:d3719ebf51c4 | 129 | if (data_sensor_top.range_mm!=0xFFFFFFFF) { |
Davidroid | 3:d3719ebf51c4 | 130 | sprintf(str,"%d",data_sensor_top.range_mm); |
pratima_hb | 6:318b85f6e6a5 | 131 | /*Copy Sensor data to be sent to EASE*/ |
pratima_hb | 6:318b85f6e6a5 | 132 | sendToEsmacat = data_sensor_top.range_mm; |
Davidroid | 3:d3719ebf51c4 | 133 | } else { |
pratima_hb | 6:318b85f6e6a5 | 134 | /*Copy Sensor data to be sent to EASE*/ |
pratima_hb | 6:318b85f6e6a5 | 135 | sendToEsmacat = 0; // Esmacat |
Davidroid | 3:d3719ebf51c4 | 136 | sprintf(str,"%s","----"); |
Davidroid | 3:d3719ebf51c4 | 137 | } |
Davidroid | 3:d3719ebf51c4 | 138 | } else if (op_mode==als_continuous_interrupt || op_mode==als_continuous_polling) { |
Davidroid | 3:d3719ebf51c4 | 139 | if (data_sensor_top.lux!=0xFFFFFFFF) { |
Davidroid | 3:d3719ebf51c4 | 140 | sprintf(str,"%d",data_sensor_top.lux); |
pratima_hb | 6:318b85f6e6a5 | 141 | /*Copy Sensor data to be sent to EASE*/ |
pratima_hb | 6:318b85f6e6a5 | 142 | sendToEsmacat = data_sensor_top.lux; // Esmacat |
Davidroid | 3:d3719ebf51c4 | 143 | } else { |
pratima_hb | 6:318b85f6e6a5 | 144 | /*If not valid data then send 0 to EASE*/ |
pratima_hb | 6:318b85f6e6a5 | 145 | sendToEsmacat = 0; // Esmacat |
Davidroid | 3:d3719ebf51c4 | 146 | sprintf(str,"%s","----"); |
Davidroid | 3:d3719ebf51c4 | 147 | } |
Davidroid | 3:d3719ebf51c4 | 148 | } |
pratima_hb | 6:318b85f6e6a5 | 149 | |
pratima_hb | 6:318b85f6e6a5 | 150 | /*Toggle the LED on EASE board*/ |
pratima_hb | 6:318b85f6e6a5 | 151 | led_on = !led_on; |
pratima_hb | 6:318b85f6e6a5 | 152 | printf("sendToEsmacat value %d \n", sendToEsmacat); // Esmacat |
pratima_hb | 6:318b85f6e6a5 | 153 | slave.write_reg_value(0,sendToEsmacat, led_on); // Write data to EASE |
pratima_hb | 6:318b85f6e6a5 | 154 | |
pratima_hb | 6:318b85f6e6a5 | 155 | board->display->display_string(str, strlen(str)); |
mapellil | 0:b706d6b7c1d3 | 156 | } |
mapellil | 0:b706d6b7c1d3 | 157 | |
mapellil | 0:b706d6b7c1d3 | 158 | /* On board red slider position check */ |
Davidroid | 4:84dfc00ae7b3 | 159 | operating_mode_t check_slider(enum op_mode_int_poll_t op_mode) |
Davidroid | 3:d3719ebf51c4 | 160 | { |
Davidroid | 4:84dfc00ae7b3 | 161 | operating_mode_t ret; |
Davidroid | 4:84dfc00ae7b3 | 162 | int measure = board->rd_switch(); |
mapellil | 0:b706d6b7c1d3 | 163 | |
Davidroid | 4:84dfc00ae7b3 | 164 | switch (op_mode) { |
Davidroid | 3:d3719ebf51c4 | 165 | case PollMeasure: |
Davidroid | 3:d3719ebf51c4 | 166 | if (measure==RANGE) { |
Davidroid | 3:d3719ebf51c4 | 167 | ret = range_continuous_polling; |
Davidroid | 3:d3719ebf51c4 | 168 | } else if (measure==ALS) { |
Davidroid | 3:d3719ebf51c4 | 169 | ret = als_continuous_polling; |
Davidroid | 3:d3719ebf51c4 | 170 | } |
Davidroid | 3:d3719ebf51c4 | 171 | break; |
Davidroid | 3:d3719ebf51c4 | 172 | case IntMeasure: |
Davidroid | 3:d3719ebf51c4 | 173 | if (measure==RANGE) { |
Davidroid | 3:d3719ebf51c4 | 174 | ret = range_continuous_interrupt; |
Davidroid | 3:d3719ebf51c4 | 175 | } else if (measure==ALS) { |
Davidroid | 3:d3719ebf51c4 | 176 | ret = als_continuous_interrupt; |
Davidroid | 3:d3719ebf51c4 | 177 | } |
Davidroid | 3:d3719ebf51c4 | 178 | break; |
Davidroid | 3:d3719ebf51c4 | 179 | } |
Davidroid | 3:d3719ebf51c4 | 180 | return ret; |
mapellil | 0:b706d6b7c1d3 | 181 | } |
mapellil | 0:b706d6b7c1d3 | 182 | |
Davidroid | 4:84dfc00ae7b3 | 183 | /* Print on USB Serial the started operating_mode_t */ |
Davidroid | 4:84dfc00ae7b3 | 184 | void print_start_message(operating_mode_t op_mode) |
mapellil | 0:b706d6b7c1d3 | 185 | { |
Davidroid | 3:d3719ebf51c4 | 186 | if (op_mode==range_continuous_interrupt) { |
Davidroid | 3:d3719ebf51c4 | 187 | printf("\nStarted range continuous interrupt measure\n\r"); |
Davidroid | 3:d3719ebf51c4 | 188 | } else if (prev_operating_mode==als_continuous_interrupt) { |
Davidroid | 3:d3719ebf51c4 | 189 | printf("\nStarted als continuous interrupt measure\n\r"); |
Davidroid | 3:d3719ebf51c4 | 190 | } |
mapellil | 0:b706d6b7c1d3 | 191 | } |
mapellil | 0:b706d6b7c1d3 | 192 | |
Davidroid | 4:84dfc00ae7b3 | 193 | /* Print on USB Serial the stopped operating_mode_t */ |
Davidroid | 4:84dfc00ae7b3 | 194 | void print_stop_message(operating_mode_t op_mode) |
mapellil | 0:b706d6b7c1d3 | 195 | { |
Davidroid | 3:d3719ebf51c4 | 196 | if (op_mode==range_continuous_interrupt) { |
Davidroid | 3:d3719ebf51c4 | 197 | printf("Stopped range continuous interrupt measure\n\r"); |
Davidroid | 3:d3719ebf51c4 | 198 | } else if (prev_operating_mode==als_continuous_interrupt) { |
Davidroid | 3:d3719ebf51c4 | 199 | printf("Stopped als continuous interrupt measure\n\r"); |
Davidroid | 3:d3719ebf51c4 | 200 | } |
mapellil | 0:b706d6b7c1d3 | 201 | } |
mapellil | 0:b706d6b7c1d3 | 202 | |
mapellil | 0:b706d6b7c1d3 | 203 | /* Print on board 4 Digit display the indicated message <= 4 char */ |
Davidroid | 4:84dfc00ae7b3 | 204 | void display_msg(const char * msg) |
mapellil | 0:b706d6b7c1d3 | 205 | { |
Davidroid | 3:d3719ebf51c4 | 206 | Timer timer; |
Davidroid | 3:d3719ebf51c4 | 207 | char str[5]; |
Davidroid | 3:d3719ebf51c4 | 208 | |
Davidroid | 3:d3719ebf51c4 | 209 | timer.start(); |
Davidroid | 3:d3719ebf51c4 | 210 | for (int i=0; i<DELAY; i=timer.read_ms()) |
Davidroid | 3:d3719ebf51c4 | 211 | { |
Davidroid | 3:d3719ebf51c4 | 212 | sprintf(str,"%s",msg); |
Davidroid | 4:84dfc00ae7b3 | 213 | board->display->display_string(str, strlen(str)); |
Davidroid | 3:d3719ebf51c4 | 214 | } |
Davidroid | 3:d3719ebf51c4 | 215 | timer.stop(); |
mapellil | 0:b706d6b7c1d3 | 216 | } |
mapellil | 0:b706d6b7c1d3 | 217 | |
Davidroid | 3:d3719ebf51c4 | 218 | /* Handle continuous ALS or Range measurement. */ |
Davidroid | 4:84dfc00ae7b3 | 219 | void int_continous_als_or_range_measure (DevI2C *device_i2c) { |
pratima_hb | 6:318b85f6e6a5 | 220 | |
Davidroid | 3:d3719ebf51c4 | 221 | int status; |
Davidroid | 3:d3719ebf51c4 | 222 | |
Davidroid | 3:d3719ebf51c4 | 223 | /* Creates the 6180XA1 expansion board singleton obj */ |
Davidroid | 3:d3719ebf51c4 | 224 | #ifdef TARGET_STM32F429 |
pratima_hb | 6:318b85f6e6a5 | 225 | board = XNucleo6180XA1::instance(device_i2c, A5, A2, D7, D2);//Pratima D13 -> D7 |
Davidroid | 3:d3719ebf51c4 | 226 | #else |
pratima_hb | 6:318b85f6e6a5 | 227 | board = XNucleo6180XA1::instance(device_i2c, A3, A2, D7, D2);//Pratima D13 -> D7 |
Davidroid | 3:d3719ebf51c4 | 228 | #endif |
Davidroid | 4:84dfc00ae7b3 | 229 | display_msg("INT"); |
Davidroid | 3:d3719ebf51c4 | 230 | |
Davidroid | 3:d3719ebf51c4 | 231 | /* Init the 6180XA1 expansion board with default values */ |
Davidroid | 4:84dfc00ae7b3 | 232 | status = board->init_board(); |
Davidroid | 3:d3719ebf51c4 | 233 | if (status) { |
Davidroid | 3:d3719ebf51c4 | 234 | printf("Failed to init board!\n\r"); |
Davidroid | 3:d3719ebf51c4 | 235 | } |
Davidroid | 3:d3719ebf51c4 | 236 | |
Davidroid | 3:d3719ebf51c4 | 237 | /* Check the red slider position for ALS/Range measure */ |
Davidroid | 4:84dfc00ae7b3 | 238 | operating_mode=check_slider(IntMeasure); |
Davidroid | 3:d3719ebf51c4 | 239 | |
Davidroid | 3:d3719ebf51c4 | 240 | /* Start the measure on sensor top */ |
Davidroid | 4:84dfc00ae7b3 | 241 | status = board->sensor_top->start_measurement(operating_mode, sensor_top_irq, NULL, NULL); |
Davidroid | 3:d3719ebf51c4 | 242 | if (!status) { |
Davidroid | 3:d3719ebf51c4 | 243 | prev_operating_mode=operating_mode; |
Davidroid | 4:84dfc00ae7b3 | 244 | print_start_message(operating_mode); |
Davidroid | 3:d3719ebf51c4 | 245 | while (true) { |
Davidroid | 3:d3719ebf51c4 | 246 | if (int_sensor_top) { /* 6180 isr was triggered */ |
Davidroid | 3:d3719ebf51c4 | 247 | int_sensor_top = false; |
Davidroid | 4:84dfc00ae7b3 | 248 | status = board->sensor_top->handle_irq(operating_mode, &data_sensor_top); /* handle the isr and read the meaure */ |
Davidroid | 4:84dfc00ae7b3 | 249 | display_refresh(operating_mode); |
Davidroid | 3:d3719ebf51c4 | 250 | } |
Davidroid | 3:d3719ebf51c4 | 251 | if (int_stop_measure) { /* Blue Button isr was triggered */ |
Davidroid | 4:84dfc00ae7b3 | 252 | status = board->sensor_top->stop_measurement(prev_operating_mode); /* stop the measure and exit */ |
Davidroid | 3:d3719ebf51c4 | 253 | if (!status) { |
Davidroid | 4:84dfc00ae7b3 | 254 | print_stop_message(prev_operating_mode); |
Davidroid | 3:d3719ebf51c4 | 255 | } |
Davidroid | 3:d3719ebf51c4 | 256 | int_stop_measure = false; |
Davidroid | 3:d3719ebf51c4 | 257 | printf("\nProgram stopped!\n\n\r"); |
Davidroid | 3:d3719ebf51c4 | 258 | break; |
Davidroid | 3:d3719ebf51c4 | 259 | } |
Davidroid | 4:84dfc00ae7b3 | 260 | operating_mode = check_slider(IntMeasure); /* check if red slider was moved */ |
Davidroid | 3:d3719ebf51c4 | 261 | if (operating_mode!=prev_operating_mode) { |
Davidroid | 4:84dfc00ae7b3 | 262 | display_refresh(prev_operating_mode); |
Davidroid | 4:84dfc00ae7b3 | 263 | status = board->sensor_top->stop_measurement(prev_operating_mode); /* stop the running measure */ |
Davidroid | 3:d3719ebf51c4 | 264 | if (!status) { |
Davidroid | 4:84dfc00ae7b3 | 265 | print_stop_message(prev_operating_mode); |
Davidroid | 3:d3719ebf51c4 | 266 | } |
Davidroid | 3:d3719ebf51c4 | 267 | prev_operating_mode = operating_mode; |
Davidroid | 4:84dfc00ae7b3 | 268 | status = board->sensor_top->start_measurement(operating_mode, sensor_top_irq, NULL, NULL); /* start the new measure */ |
Davidroid | 3:d3719ebf51c4 | 269 | if (!status) { |
Davidroid | 4:84dfc00ae7b3 | 270 | print_start_message(operating_mode); |
Davidroid | 3:d3719ebf51c4 | 271 | } |
Davidroid | 3:d3719ebf51c4 | 272 | } else { |
Davidroid | 4:84dfc00ae7b3 | 273 | display_refresh(operating_mode); |
Davidroid | 3:d3719ebf51c4 | 274 | } |
pratima_hb | 6:318b85f6e6a5 | 275 | |
Davidroid | 3:d3719ebf51c4 | 276 | } |
Davidroid | 3:d3719ebf51c4 | 277 | } |
Davidroid | 4:84dfc00ae7b3 | 278 | display_msg("BYE"); |
pratima_hb | 6:318b85f6e6a5 | 279 | |
Davidroid | 3:d3719ebf51c4 | 280 | } |
mapellil | 0:b706d6b7c1d3 | 281 | |
pratima_hb | 6:318b85f6e6a5 | 282 | |
mapellil | 0:b706d6b7c1d3 | 283 | /*=================================== Main ================================== |
mapellil | 0:b706d6b7c1d3 | 284 | Move the VL6180X Expansion board red slider to switch between ALS or Range |
mapellil | 0:b706d6b7c1d3 | 285 | measures. |
Davidroid | 4:84dfc00ae7b3 | 286 | Press the blue user button to stop the measurements in progress. |
mapellil | 0:b706d6b7c1d3 | 287 | =============================================================================*/ |
mapellil | 0:b706d6b7c1d3 | 288 | int main() |
mapellil | 0:b706d6b7c1d3 | 289 | { |
pratima_hb | 6:318b85f6e6a5 | 290 | /* Esmacat communication*/ |
pratima_hb | 6:318b85f6e6a5 | 291 | |
pratima_hb | 6:318b85f6e6a5 | 292 | slave.setup_spi(); //Setup SPI for EASE |
pratima_hb | 6:318b85f6e6a5 | 293 | |
pratima_hb | 6:318b85f6e6a5 | 294 | |
pratima_hb | 6:318b85f6e6a5 | 295 | |
Davidroid | 3:d3719ebf51c4 | 296 | #if USER_BUTTON==PC_13 // Cross compiling for Nucleo-F401 |
Davidroid | 3:d3719ebf51c4 | 297 | InterruptIn stop_button (USER_BUTTON); |
Davidroid | 4:84dfc00ae7b3 | 298 | stop_button.rise (&stop_measure_irq); |
mapellil | 0:b706d6b7c1d3 | 299 | #endif |
Davidroid | 3:d3719ebf51c4 | 300 | DevI2C *device_i2c = new DevI2C(VL6180X_I2C_SDA, VL6180X_I2C_SCL); |
Davidroid | 3:d3719ebf51c4 | 301 | |
Davidroid | 3:d3719ebf51c4 | 302 | /* Start continous measures Interrupt based */ |
Davidroid | 4:84dfc00ae7b3 | 303 | int_continous_als_or_range_measure (device_i2c); |
mapellil | 0:b706d6b7c1d3 | 304 | } |
pratima_hb | 6:318b85f6e6a5 | 305 | |
pratima_hb | 6:318b85f6e6a5 | 306 |