SunTracker_BLE

Dependencies:   BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 X_NUCLEO_IHM01A1 X_NUCLEO_IKS01A1 mbed

Fork of SunTracker_BLE by ST Expansion SW Team

Overview

The SunTracker is a demo application running on ST Nucleo-F401RE stacking a set of ST X-NUCLEO expansion boards.
Main features provided are:

  • A solar panel follows the light source, orienting the panel in order to achieve the best panel efficiency.
  • Orientation is controlled thanks to a couple of VL6180X FlightSense light sensors mounted on a X-NUCLEO-6180XA1 expansion board and driven by X-NUCLEO-IHM01A1 controlled stepper motor acting as actuator to orientate the panel.
  • The system features a progressive control on the stepper motor in order to modulate the panel rotation speed according to the light angle.
  • The application is also able to control the panel productivity reading the panel voltage through an ADC and proving feedback on the local display.
  • A manual orientation is possible by using the accelerometer on a X-NUCLEO-IKS01A1 expansion board that, according on board tilt, controls the speed and the rotate direction.
  • A remote control is available using a X-NUCLEO-IDB04A1 or a X-NUCLEO-IDB05A1 Bluetooth Low Energy expansion board. Remote control software is here.

/media/uploads/fabiombed/suntracker_server-client.png

Working Status

  • SunTracker has 3 working status visible on FlightSense display and switchable by pressing the User Button:

Status 0 (Idle)

  • Motor: Free Turning
  • Display: Waiting for User Button

Status 1

  • Motor: Driven by Light
  • Display: Direction and Light Intensity = Direction and Motor Speed

Status 2

  • Motor: Driven by Light
  • Display: Solar Panel Efficiency

Status 3

  • Motor: Driven by Accelerometer
  • Display: Direction and Accelerometer Intensity

Server Startup

  • When you plug the power supply, the word ‘PUSH’ is shown on display.
  • You can manually rotate the structure to assign the ‘Zero Point’. Then press the User Button to launch the application.
  • The display will show this status, which means that the structure is oriented to maximize the efficiency of the solar panel.
  • If there is a light displacement, the structure will rotate, left or right, to follow the light source and on display is shown the direction and the speed.
  • You can press the User Button to show the panel efficiency with 4 digits that represent the range from 0v (0000) to 3,3v (3300).
  • Further pressing the User Button you will manual rotate the panel by tilt the Server or Client accelerometer depending by BLE connection.

Client Startup

  • The Client application can remotely control the User Button and the Accelerometer functions.
  • Power on the Client AFTER the Server, it will automatically search for the SunTracker and will establish a BLE connection.
  • The Green Led on Nucleo Client board will be powered on.

Rotation Features

  • It has been implemented a block of rotation to avoid cables twist.
  • The blocking point can be set in the firmware by changing a constant.
  • You can manually rotate the structure to assign the ‘Zero Point’ before press the User Button to launch the application.
  • The system features a progressive control on the stepper motor in order to modulate the rotation speed according to the light or accelerometer angle.

List of Components

SERVER SunTracker_BLE

  • Stepper Motor 400’’ (Part Number 5350401) - To orientate the Mechanical Structure.
  • Solar Panel 0.446w (Part Number 0194127) - To capture sunlight and generate electrical current.
  • Power Supply 12v (Part Number 7262993) - To provide power supply at the Stepper Motor.
  • Flat Cable 6 ways (Part Number 1807010) - To plug VL6180X-SATEL with X-NUCLEO-6180XA1 (60cm length each x2).
  • Cable Connector (Part Number 6737694) - To plug the Flat Cable (x4).
  • Power Connector (Part Number 0487842) - To provide Power Supply to X-NUCLEO-IHM01A1.

CLIENT SunTracker_BLE_Remote

MECHANICAL STRUCTURE

Find here the STL files to print with a 3D printer.

/media/uploads/fabiombed/assembly.png

/media/uploads/fabiombed/mechanical_structure_and_motor_legs.png

FLAT CABLE ASSEMBLY

/media/uploads/fabiombed/flat_cable.png

HARDWARE SETUP

Nucleo ADC + Solar Panel

Connect Solar Panel cables to Nucleo Morpho PC_3 (white) and Nucleo Morpho GND (black). Connect a capacitor 10uF between PC_3 and GND to stabilize its voltage value shown on display.

EasySpin (L6474) + BLE

Hardware conflict between EasySpin DIR1 and BLE Reset, both on same Arduino Pin PA_8. Disconnect PA_8 between EasySpin and Nucleo by fold EasySpin Pin. PB_2 has been configured as EasySpin DIR1 in the firmware . Connect Nucleo Morpho PB_2 to FlightSense Arduino PA_8 by a wire.

FlightSense Satellites

In case of instability with I2C due to long flat cables, solder 4 SMD capacitors 47pF on FlightSense board in parallel between R15, R16, R17, R18 and plug 2 capacitors 15pF between FlightSense Arduino PB_8 and PB_9 to GND pin to cut-off noises over 720 KHz.

Arduino & Morpho Pinout

/media/uploads/fabiombed/arduino_pinout.png /media/uploads/fabiombed/morpho_pinout.png

Committer:
fabiombed
Date:
Mon Mar 21 10:18:41 2016 +0000
Revision:
15:019b8d60c89d
Parent:
14:644f9e7278e9
Child:
16:d69c0d5d5ab2
Update SERVER

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fabiombed 0:becf0d313663 1 /**
fabiombed 0:becf0d313663 2 ******************************************************************************
fabiombed 0:becf0d313663 3 * @file main.cpp
fabiombed 1:8f312c1686b6 4 * @author Fabio Brembilla
fabiombed 4:1d3d071a4c2c 5 * @version V2.0.0
fabiombed 12:1e6a1d3a66b5 6 * @date March, 2016
fabiombed 12:1e6a1d3a66b5 7 * @brief SunTracker + BLE (Server) Vertical Application
fabiombed 1:8f312c1686b6 8 * This application use IHM01A1, 6180XA1, IKS01A1, IDB0XA1 expansion boards
fabiombed 0:becf0d313663 9 ******************************************************************************
fabiombed 0:becf0d313663 10 * @attention
fabiombed 4:1d3d071a4c2c 11 *
fabiombed 4:1d3d071a4c2c 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
fabiombed 0:becf0d313663 13 *
fabiombed 0:becf0d313663 14 * Redistribution and use in source and binary forms, with or without modification,
fabiombed 0:becf0d313663 15 * are permitted provided that the following conditions are met:
fabiombed 0:becf0d313663 16 * 1. Redistributions of source code must retain the above copyright notice,
fabiombed 0:becf0d313663 17 * this list of conditions and the following disclaimer.
fabiombed 0:becf0d313663 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
fabiombed 0:becf0d313663 19 * this list of conditions and the following disclaimer in the documentation
fabiombed 0:becf0d313663 20 * and/or other materials provided with the distribution.
fabiombed 0:becf0d313663 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
fabiombed 0:becf0d313663 22 * may be used to endorse or promote products derived from this software
fabiombed 0:becf0d313663 23 * without specific prior written permission.
fabiombed 0:becf0d313663 24 *
fabiombed 0:becf0d313663 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
fabiombed 0:becf0d313663 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
fabiombed 0:becf0d313663 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
fabiombed 0:becf0d313663 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
fabiombed 0:becf0d313663 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
fabiombed 0:becf0d313663 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
fabiombed 0:becf0d313663 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
fabiombed 0:becf0d313663 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
fabiombed 0:becf0d313663 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
fabiombed 0:becf0d313663 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
fabiombed 0:becf0d313663 35 *
fabiombed 0:becf0d313663 36 ******************************************************************************
fabiombed 0:becf0d313663 37 */
fabiombed 4:1d3d071a4c2c 38
fabiombed 14:644f9e7278e9 39 /* Define --------------------------------------------------------------------*/
fabiombed 14:644f9e7278e9 40
fabiombed 14:644f9e7278e9 41 #define FlightSense //6180XA1 Main (remove only for debug)
fabiombed 14:644f9e7278e9 42 #define EasySpin //IHM01A1 Main (remove only for debug)
fabiombed 14:644f9e7278e9 43 #define Sensors //IKS01A1 Option
fabiombed 14:644f9e7278e9 44 #define Ble //IDB0XA1 Option
fabiombed 14:644f9e7278e9 45
fabiombed 0:becf0d313663 46 /* Includes ------------------------------------------------------------------*/
fabiombed 4:1d3d071a4c2c 47
fabiombed 6:4cbf7303b496 48 // Mbed specific header files
fabiombed 0:becf0d313663 49 #include "mbed.h"
fabiombed 4:1d3d071a4c2c 50
fabiombed 6:4cbf7303b496 51 // Helper header files
fabiombed 0:becf0d313663 52 #include "DevSPI.h"
fabiombed 1:8f312c1686b6 53 #include "DevI2C.h"
fabiombed 0:becf0d313663 54
fabiombed 6:4cbf7303b496 55 // Component specific header files
fabiombed 14:644f9e7278e9 56 #ifdef FlightSense
fabiombed 14:644f9e7278e9 57 #include "x_nucleo_6180xa1.h"
fabiombed 14:644f9e7278e9 58 #endif
fabiombed 14:644f9e7278e9 59
fabiombed 14:644f9e7278e9 60 #ifdef EasySpin
fabiombed 14:644f9e7278e9 61 #include "l6474_class.h"
fabiombed 14:644f9e7278e9 62 #endif
fabiombed 14:644f9e7278e9 63
fabiombed 14:644f9e7278e9 64 #ifdef Sensors
fabiombed 14:644f9e7278e9 65 #include "x_nucleo_iks01a1.h"
fabiombed 14:644f9e7278e9 66 #endif
fabiombed 0:becf0d313663 67
fabiombed 6:4cbf7303b496 68 // C header files
fabiombed 1:8f312c1686b6 69 #include <string.h>
fabiombed 1:8f312c1686b6 70 #include <stdlib.h>
fabiombed 1:8f312c1686b6 71 #include <stdio.h>
fabiombed 1:8f312c1686b6 72 #include <assert.h>
fabiombed 0:becf0d313663 73
fabiombed 5:76fb6b783487 74 /* BlueTooth -----------------------------------------------------------------*/
fabiombed 5:76fb6b783487 75
fabiombed 14:644f9e7278e9 76 #ifdef Ble
fabiombed 14:644f9e7278e9 77
fabiombed 5:76fb6b783487 78 #include "debug.h" // Need for PRINTF
fabiombed 14:644f9e7278e9 79 #include "Utils.h" // Need for STORE_LE_16 and STORE_LE_32
fabiombed 5:76fb6b783487 80
fabiombed 8:144855fe02bd 81 const unsigned LENGTH_OF_LONG_UUID = 16;
fabiombed 8:144855fe02bd 82 typedef uint16_t ShortUUIDBytes_t;
fabiombed 8:144855fe02bd 83 typedef uint8_t LongUUIDBytes_t[LENGTH_OF_LONG_UUID];
fabiombed 8:144855fe02bd 84
fabiombed 5:76fb6b783487 85 typedef enum ConnectionStatus_t {
fabiombed 5:76fb6b783487 86 DISCONNECTED =0,
fabiombed 5:76fb6b783487 87 CONNECTED =1
fabiombed 8:144855fe02bd 88 } cns_t;
fabiombed 5:76fb6b783487 89
fabiombed 8:144855fe02bd 90 #define BLE_DEV_NAME "SunTracker"
fabiombed 15:019b8d60c89d 91 #define BLE_DEV_MAC 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF // SERVER address (must be set into CLIENT BLE_peer_address_BE)
fabiombed 14:644f9e7278e9 92 //#define BLE_DEV_MAC 0xFD,0x66,0x05,0x13,0xBE,0xBA // Default ST
fabiombed 8:144855fe02bd 93 #define BLE_ADVERTISING_INTERVAL 1000
fabiombed 5:76fb6b783487 94
fabiombed 5:76fb6b783487 95 #include "CustomControlService.h"
fabiombed 5:76fb6b783487 96 #include "CustomSensorsService.h"
fabiombed 5:76fb6b783487 97
fabiombed 6:4cbf7303b496 98 static BLE *p_BLEdev = NULL;
fabiombed 7:54984d031243 99 static CustomControlService *p_customcontrolservice = NULL;
fabiombed 7:54984d031243 100 static CustomSensorService *p_customsensorservice = NULL;
fabiombed 7:54984d031243 101
fabiombed 15:019b8d60c89d 102 int16_t value_read = 0;
fabiombed 15:019b8d60c89d 103
fabiombed 14:644f9e7278e9 104 #endif
fabiombed 14:644f9e7278e9 105
fabiombed 0:becf0d313663 106 /* Definitions ---------------------------------------------------------------*/
fabiombed 0:becf0d313663 107
fabiombed 1:8f312c1686b6 108 #define SET_ACC 400 // Set Motor Acceleration
fabiombed 1:8f312c1686b6 109 #define SET_DEC 400 // Set Motor Deceleration
fabiombed 1:8f312c1686b6 110 #define SET_MAX 200 // Set Motor MaxSpeed
fabiombed 1:8f312c1686b6 111 #define SET_MIN 100 // Set Motor MinSpeed
fabiombed 1:8f312c1686b6 112 #define STOP 1000 // Set Motor Stop Position
fabiombed 1:8f312c1686b6 113 #define TOLLERANCE 100 // Tollerance between Left and Right before Start Movement
fabiombed 1:8f312c1686b6 114 #define RANGE_1 200 // Range 1 for Motor Speed
fabiombed 1:8f312c1686b6 115 #define RANGE_2 500 // Range 2 for Motor Speed
fabiombed 0:becf0d313663 116
fabiombed 0:becf0d313663 117 /* Variables -----------------------------------------------------------------*/
fabiombed 0:becf0d313663 118
fabiombed 14:644f9e7278e9 119 int8_t dir=0; // Motor Rotation Direction: 0 = Stop, 1 = Anticlockwise, 2 = Clockwise
fabiombed 14:644f9e7278e9 120 int8_t changedir=0; // Change Direction: 0 = No, 1 = Yes
fabiombed 14:644f9e7278e9 121 int8_t arrest=0; // Arrest: 0 = No, 1 = Yes
fabiombed 15:019b8d60c89d 122 int16_t babybear=0; // Difference (in Lux) between Left and Right
fabiombed 14:644f9e7278e9 123 int32_t acc_data[3]; // Difference of Accelerometer
fabiombed 15:019b8d60c89d 124 int16_t diff=0; // Babybear or Accelerometer difference [--> Send BLE]
fabiombed 15:019b8d60c89d 125 int16_t diff_abs=0; // Abs of Babybear or Accelerometer difference
fabiombed 14:644f9e7278e9 126 int8_t left=0; // Left Command for Rotate Direction
fabiombed 14:644f9e7278e9 127 int8_t right=0; // Right Command for Rotate Direction
fabiombed 14:644f9e7278e9 128 int8_t start=0; // Waiting User Button Push
fabiombed 15:019b8d60c89d 129 int16_t pos=0; // Motor Position [--> Send BLE]
fabiombed 15:019b8d60c89d 130 int16_t measure=0; // ADC Value from SunPanel [--> Send BLE]
fabiombed 14:644f9e7278e9 131 char DisplayStr[5]; // Status Display
fabiombed 15:019b8d60c89d 132 int8_t display=0; // Shown on Display: 0 = Motor Speed, 1 = Solar Panel Value, 2 = Manual Control [--> Send BLE]
fabiombed 1:8f312c1686b6 133 int16_t status, status_t, status_b, status_l, status_r; // Babybear Status
fabiombed 1:8f312c1686b6 134
fabiombed 8:144855fe02bd 135 /* Initializations ------------------------------------------------------------*/
fabiombed 8:144855fe02bd 136
fabiombed 8:144855fe02bd 137 // Initializing SPI bus
fabiombed 8:144855fe02bd 138 DevSPI dev_spi(D11, D12, D13);
fabiombed 8:144855fe02bd 139
fabiombed 8:144855fe02bd 140 // Initializing I2C bus
fabiombed 8:144855fe02bd 141 DevI2C dev_i2c(D14, D15);
fabiombed 8:144855fe02bd 142
fabiombed 14:644f9e7278e9 143 #ifdef FlightSense
fabiombed 14:644f9e7278e9 144 // Initializing FlightSense Component 6180XA1
fabiombed 8:144855fe02bd 145 static X_NUCLEO_6180XA1 *board;
fabiombed 8:144855fe02bd 146 MeasureData_t data_sensor_top, data_sensor_bottom, data_sensor_left, data_sensor_right;
fabiombed 14:644f9e7278e9 147 #endif
fabiombed 14:644f9e7278e9 148
fabiombed 14:644f9e7278e9 149 #ifdef EasySpin
fabiombed 14:644f9e7278e9 150 // Initializing EasySpin Component IHM01A1
fabiombed 14:644f9e7278e9 151 static L6474 *motor;
fabiombed 14:644f9e7278e9 152 #endif
fabiombed 14:644f9e7278e9 153
fabiombed 14:644f9e7278e9 154 #ifdef Sensors
fabiombed 14:644f9e7278e9 155 // Initializing Sensors Component IKS01A1
fabiombed 8:144855fe02bd 156 static X_NUCLEO_IKS01A1 *mems;
fabiombed 8:144855fe02bd 157 MotionSensor *accelerometer;
fabiombed 14:644f9e7278e9 158 #endif
fabiombed 8:144855fe02bd 159
fabiombed 8:144855fe02bd 160 InterruptIn mybutton(USER_BUTTON);
fabiombed 8:144855fe02bd 161
fabiombed 14:644f9e7278e9 162 AnalogIn analog_read(PC_3); // A1 Conflict with BLE SPI_CS --> Changed in Morpho PC_3
fabiombed 8:144855fe02bd 163
fabiombed 8:144855fe02bd 164 /* User_Button_Pressed -------------------------------------------------------*/
fabiombed 8:144855fe02bd 165
fabiombed 14:644f9e7278e9 166 void User_Button_Pressed(void)
fabiombed 8:144855fe02bd 167 {
fabiombed 8:144855fe02bd 168
fabiombed 15:019b8d60c89d 169 if (start>0) { display++; }
fabiombed 14:644f9e7278e9 170 #ifdef Sensors
fabiombed 15:019b8d60c89d 171 if (display>2) { display=0; }
fabiombed 14:644f9e7278e9 172 #else
fabiombed 15:019b8d60c89d 173 if (display>1) { display=0; }
fabiombed 14:644f9e7278e9 174 #endif
fabiombed 8:144855fe02bd 175 if (start==0) { start=1; }
fabiombed 14:644f9e7278e9 176
fabiombed 14:644f9e7278e9 177 char State[12]; // Characters into State must be <12 and never =>12 or it crash!!!
fabiombed 15:019b8d60c89d 178 if (display==0) strcpy(State,"FlightSense");
fabiombed 15:019b8d60c89d 179 if (display==1) strcpy(State,"ADCSunPanel");
fabiombed 15:019b8d60c89d 180 if (display==2) strcpy(State,"Sensors");
fabiombed 14:644f9e7278e9 181 printf("\r\n\r\nPUSH Display: %s", State);
fabiombed 8:144855fe02bd 182
fabiombed 8:144855fe02bd 183 }
fabiombed 8:144855fe02bd 184
fabiombed 14:644f9e7278e9 185 #ifdef Ble
fabiombed 14:644f9e7278e9 186
fabiombed 9:ca289bf57f52 187 /* Bluetooth CallBack ---------------------------------------------------------*/
fabiombed 9:ca289bf57f52 188
fabiombed 9:ca289bf57f52 189 static void onUpdatesEnabledCallback(GattAttribute::Handle_t handle)
fabiombed 9:ca289bf57f52 190 {
fabiombed 15:019b8d60c89d 191 if (p_customcontrolservice->isContHandle(handle)) p_customcontrolservice->enNotify(handle);
fabiombed 15:019b8d60c89d 192 if (p_customsensorservice->isDifferenceHandle(handle)) p_customsensorservice->enNotify(handle);
fabiombed 15:019b8d60c89d 193 if (p_customsensorservice->isPositionHandle(handle)) p_customsensorservice->enNotify(handle);
fabiombed 15:019b8d60c89d 194 if (p_customsensorservice->isSunpanelHandle(handle)) p_customsensorservice->enNotify(handle);
fabiombed 9:ca289bf57f52 195 }
fabiombed 9:ca289bf57f52 196
fabiombed 9:ca289bf57f52 197 static void onUpdatesDisabledCallback(Gap::Handle_t handle)
fabiombed 9:ca289bf57f52 198 {
fabiombed 15:019b8d60c89d 199 if (p_customcontrolservice->isContHandle(handle)) p_customcontrolservice->disNotify(handle);
fabiombed 15:019b8d60c89d 200 if (p_customsensorservice->isDifferenceHandle(handle)) p_customsensorservice->disNotify(handle);
fabiombed 15:019b8d60c89d 201 if (p_customsensorservice->isPositionHandle(handle)) p_customsensorservice->disNotify(handle);
fabiombed 15:019b8d60c89d 202 if (p_customsensorservice->isSunpanelHandle(handle)) p_customsensorservice->disNotify(handle);
fabiombed 9:ca289bf57f52 203 }
fabiombed 9:ca289bf57f52 204
fabiombed 9:ca289bf57f52 205 static void onDataReadCallback(const GattReadCallbackParams *eventDataP)
fabiombed 9:ca289bf57f52 206 {
fabiombed 9:ca289bf57f52 207
fabiombed 9:ca289bf57f52 208 }
fabiombed 9:ca289bf57f52 209
fabiombed 14:644f9e7278e9 210 // This Callback happen when it RECEIVE a WRITE
fabiombed 9:ca289bf57f52 211 static void myonDataWriteCallback(const GattWriteCallbackParams *eventDataP)
fabiombed 14:644f9e7278e9 212 {
fabiombed 14:644f9e7278e9 213 //printf ("myonDataWriteCallback attr_handle: %x att_data[3]: %x data_length: %d\n\r", eventDataP->handle, eventDataP->data[3], eventDataP->len );
fabiombed 15:019b8d60c89d 214
fabiombed 15:019b8d60c89d 215 // Return original value after inverted with STORE_LE_16 to send by BLE
fabiombed 15:019b8d60c89d 216 value_read = eventDataP->data[0] + (eventDataP->data[1]<<8);
fabiombed 9:ca289bf57f52 217
fabiombed 15:019b8d60c89d 218 if (p_customcontrolservice->isContHandle(eventDataP->handle))
fabiombed 9:ca289bf57f52 219 {
fabiombed 15:019b8d60c89d 220 //printf("\r\n\r\nmyonDataWriteCallback (data[0] %x)", eventDataP->data[0]);
fabiombed 15:019b8d60c89d 221 //printf("\r\nmyonDataWriteCallback (data[1] %x)", eventDataP->data[1]);
fabiombed 15:019b8d60c89d 222 printf("\r\n\r\nonDataRead BUTTON (data %d)", value_read);
fabiombed 14:644f9e7278e9 223
fabiombed 14:644f9e7278e9 224 User_Button_Pressed(); // Change Display Status
fabiombed 9:ca289bf57f52 225 }
fabiombed 15:019b8d60c89d 226
fabiombed 15:019b8d60c89d 227 if (p_customsensorservice->isDifferenceHandle(eventDataP->handle))
fabiombed 15:019b8d60c89d 228 {
fabiombed 15:019b8d60c89d 229 //printf("\r\n\r\nmyonDataWriteCallback (data[0] %x)", eventDataP->data[0]);
fabiombed 15:019b8d60c89d 230 //printf("\r\nmyonDataWriteCallback (data[1] %x)", eventDataP->data[1]);
fabiombed 15:019b8d60c89d 231 //printf("\r\n\r\nonDataRead (data %d)", value_read);
fabiombed 15:019b8d60c89d 232
fabiombed 15:019b8d60c89d 233 diff = value_read; // Change Diff
fabiombed 15:019b8d60c89d 234 }
fabiombed 15:019b8d60c89d 235
fabiombed 9:ca289bf57f52 236 }
fabiombed 9:ca289bf57f52 237
fabiombed 9:ca289bf57f52 238 static void onConnectionCallback(const Gap::ConnectionCallbackParams_t * connectionParams)
fabiombed 9:ca289bf57f52 239 {
fabiombed 14:644f9e7278e9 240 printf("\r\n\r\nonConnectionCallback (Line %d)", __LINE__);
fabiombed 9:ca289bf57f52 241 }
fabiombed 9:ca289bf57f52 242
fabiombed 9:ca289bf57f52 243 static void onDisconnectionCallback(const Gap::DisconnectionCallbackParams_t * disConnectionReason)
fabiombed 9:ca289bf57f52 244 {
fabiombed 14:644f9e7278e9 245 printf("\r\n\r\nonDisconnectionCallback (Line %d)", __LINE__);
fabiombed 9:ca289bf57f52 246 p_BLEdev->gap().startAdvertising();
fabiombed 9:ca289bf57f52 247 }
fabiombed 9:ca289bf57f52 248
fabiombed 14:644f9e7278e9 249 #endif
fabiombed 14:644f9e7278e9 250
fabiombed 9:ca289bf57f52 251 /* Bluetooth Initialization ---------------------------------------------------*/
fabiombed 9:ca289bf57f52 252
fabiombed 9:ca289bf57f52 253 bool BLE_Initialization(void)
fabiombed 9:ca289bf57f52 254 {
fabiombed 9:ca289bf57f52 255
fabiombed 14:644f9e7278e9 256 #ifdef Ble
fabiombed 14:644f9e7278e9 257
fabiombed 9:ca289bf57f52 258 p_BLEdev = new BLE;
fabiombed 9:ca289bf57f52 259 if (!p_BLEdev) { printf("\r\nBLE Device creation failed\r\n"); }
fabiombed 9:ca289bf57f52 260 const Gap::Address_t BLE_address_BE = {BLE_DEV_MAC};
fabiombed 9:ca289bf57f52 261 p_BLEdev->gap().setAddress(BLEProtocol::AddressType::PUBLIC, BLE_address_BE);
fabiombed 9:ca289bf57f52 262
fabiombed 9:ca289bf57f52 263 p_BLEdev->init();
fabiombed 9:ca289bf57f52 264
fabiombed 9:ca289bf57f52 265 // Set BLE CallBack Functions
fabiombed 9:ca289bf57f52 266 p_BLEdev->gattServer().onUpdatesEnabled(onUpdatesEnabledCallback);
fabiombed 9:ca289bf57f52 267 p_BLEdev->gattServer().onUpdatesDisabled(onUpdatesDisabledCallback);
fabiombed 9:ca289bf57f52 268 p_BLEdev->gattServer().onDataRead(onDataReadCallback);
fabiombed 9:ca289bf57f52 269 p_BLEdev->gattServer().onDataWritten(myonDataWriteCallback);
fabiombed 9:ca289bf57f52 270 p_BLEdev->gap().onConnection(onConnectionCallback);
fabiombed 9:ca289bf57f52 271 p_BLEdev->gap().onDisconnection(onDisconnectionCallback);
fabiombed 9:ca289bf57f52 272 //p_BLEdev->gattServer().onConfirmationReceived(onConfirmationReceivedCallback);
fabiombed 9:ca289bf57f52 273 //p_BLEdev->gattServer().onDataSent(onDataSentCallback);
fabiombed 9:ca289bf57f52 274 //p_BLEdev->gap().onTimeout(onTimeoutCallback);
fabiombed 9:ca289bf57f52 275
fabiombed 9:ca289bf57f52 276 // BLE Services
fabiombed 14:644f9e7278e9 277 p_customcontrolservice = new CustomControlService(*p_BLEdev);
fabiombed 9:ca289bf57f52 278 p_customsensorservice = new CustomSensorService(*p_BLEdev);
fabiombed 9:ca289bf57f52 279
fabiombed 9:ca289bf57f52 280 // Setup BLE Advertising
fabiombed 9:ca289bf57f52 281 const static char DEVICE_NAME[] = BLE_DEV_NAME;
fabiombed 9:ca289bf57f52 282 p_BLEdev->gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
fabiombed 9:ca289bf57f52 283 uint8_t dat[] = {0x01,0x80,0x00,0xFC,0x00,0x00};
fabiombed 9:ca289bf57f52 284 p_BLEdev->gap().accumulateScanResponse(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA,dat,6);
fabiombed 9:ca289bf57f52 285 p_BLEdev->gap().accumulateAdvertisingPayload(GapAdvertisingData::UNKNOWN);
fabiombed 9:ca289bf57f52 286 p_BLEdev->gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
fabiombed 9:ca289bf57f52 287 p_BLEdev->gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
fabiombed 9:ca289bf57f52 288 p_BLEdev->gap().setAdvertisingInterval(BLE_ADVERTISING_INTERVAL);
fabiombed 9:ca289bf57f52 289 p_BLEdev->gap().startAdvertising();
fabiombed 9:ca289bf57f52 290
fabiombed 14:644f9e7278e9 291 printf("Initialization Ble OK (Line %d)\r\n", __LINE__);
fabiombed 14:644f9e7278e9 292
fabiombed 14:644f9e7278e9 293 #endif
fabiombed 14:644f9e7278e9 294
fabiombed 9:ca289bf57f52 295 return true;
fabiombed 9:ca289bf57f52 296
fabiombed 9:ca289bf57f52 297 }
fabiombed 9:ca289bf57f52 298
fabiombed 8:144855fe02bd 299 /* Initialization ------------------------------------------------------------*/
fabiombed 8:144855fe02bd 300
fabiombed 8:144855fe02bd 301 bool Initialization(void)
fabiombed 8:144855fe02bd 302 {
fabiombed 11:b5e23d64d366 303
fabiombed 14:644f9e7278e9 304 dev_i2c.frequency(100000); // Default 100KHz. At 10KHz, 20KHz, 200KHz and 400KHz doesn't work
fabiombed 11:b5e23d64d366 305
fabiombed 11:b5e23d64d366 306 //----
fabiombed 14:644f9e7278e9 307
fabiombed 14:644f9e7278e9 308 #ifdef FlightSense
fabiombed 14:644f9e7278e9 309
fabiombed 14:644f9e7278e9 310 // Initializing FlightSense Component
fabiombed 14:644f9e7278e9 311 board=X_NUCLEO_6180XA1::Instance(&dev_i2c, NC, NC, NC, NC); // NC as Interrupt fixed from FlightSense library 42
fabiombed 14:644f9e7278e9 312
fabiombed 9:ca289bf57f52 313 status=board->InitBoard();
fabiombed 9:ca289bf57f52 314 if(status) VL6180x_ErrLog("Failed to init the board!\n\r");
fabiombed 8:144855fe02bd 315
fabiombed 8:144855fe02bd 316 // Put GPIO not used as Interrupt in Hi-Z
fabiombed 8:144855fe02bd 317 status_t=board->sensor_top->SetGPIOxFunctionality(1, GPIOx_SELECT_OFF);
fabiombed 14:644f9e7278e9 318 //status_b=board->sensor_botton->SetGPIOxFunctionality(1, GPIOx_SELECT_OFF); Not Present
fabiombed 8:144855fe02bd 319 status_l=board->sensor_left->SetGPIOxFunctionality(1, GPIOx_SELECT_OFF);
fabiombed 8:144855fe02bd 320 status_r=board->sensor_right->SetGPIOxFunctionality(1, GPIOx_SELECT_OFF);
fabiombed 8:144855fe02bd 321
fabiombed 8:144855fe02bd 322 // Set Babybears
fabiombed 8:144855fe02bd 323 status_l=board->sensor_left->AlsSetAnalogueGain(3);
fabiombed 8:144855fe02bd 324 status_r=board->sensor_right->AlsSetAnalogueGain(3);
fabiombed 8:144855fe02bd 325 status_l=board->sensor_left->StartMeasurement(als_continuous_polling, NULL, NULL, NULL);
fabiombed 8:144855fe02bd 326 status_r=board->sensor_right->StartMeasurement(als_continuous_polling, NULL, NULL, NULL);
fabiombed 8:144855fe02bd 327
fabiombed 14:644f9e7278e9 328 printf("Init FlightSense OK\r\n");
fabiombed 14:644f9e7278e9 329
fabiombed 14:644f9e7278e9 330 #endif
fabiombed 11:b5e23d64d366 331
fabiombed 8:144855fe02bd 332 //----
fabiombed 8:144855fe02bd 333
fabiombed 14:644f9e7278e9 334 #ifdef EasySpin
fabiombed 11:b5e23d64d366 335
fabiombed 14:644f9e7278e9 336 // Initializing EasySpin Component
fabiombed 9:ca289bf57f52 337 motor = new L6474(D2, D8, PB_2, D9, D10, dev_spi); // D7 conflict with BNRG_RST (when motor change direction 0-1 reset BLE)
fabiombed 9:ca289bf57f52 338 // Used Morpho PB_2 and made HW wiring
fabiombed 8:144855fe02bd 339 if (motor->Init(NULL) != COMPONENT_OK)
fabiombed 8:144855fe02bd 340 return false;
fabiombed 8:144855fe02bd 341
fabiombed 8:144855fe02bd 342 motor->SetStepMode(STEP_MODE_1_8); // Default is STEP_MODE_1_16
fabiombed 8:144855fe02bd 343
fabiombed 8:144855fe02bd 344 // Set defaults Motor Speed
fabiombed 8:144855fe02bd 345 motor->SetAcceleration(SET_ACC);
fabiombed 8:144855fe02bd 346 motor->SetDeceleration(SET_DEC);
fabiombed 8:144855fe02bd 347 motor->SetMaxSpeed(SET_MAX); // Variable by Light/Mems Sensors
fabiombed 8:144855fe02bd 348 motor->SetMinSpeed(SET_MIN);
fabiombed 8:144855fe02bd 349
fabiombed 14:644f9e7278e9 350 printf("Init EasySpin OK\r\n");
fabiombed 14:644f9e7278e9 351
fabiombed 14:644f9e7278e9 352 #endif
fabiombed 14:644f9e7278e9 353
fabiombed 14:644f9e7278e9 354 //----
fabiombed 14:644f9e7278e9 355
fabiombed 14:644f9e7278e9 356 #ifdef Sensors
fabiombed 11:b5e23d64d366 357
fabiombed 14:644f9e7278e9 358 // Initializing Sensors Component
fabiombed 14:644f9e7278e9 359 mems=X_NUCLEO_IKS01A1::Instance(&dev_i2c);
fabiombed 14:644f9e7278e9 360 accelerometer = mems->GetAccelerometer();
fabiombed 14:644f9e7278e9 361
fabiombed 14:644f9e7278e9 362 printf("Init Sensors OK\r\n");
fabiombed 14:644f9e7278e9 363
fabiombed 14:644f9e7278e9 364 #endif
fabiombed 14:644f9e7278e9 365
fabiombed 14:644f9e7278e9 366 printf("Initialization OK (Line %d)\r\n", __LINE__);
fabiombed 8:144855fe02bd 367 return true;
fabiombed 8:144855fe02bd 368
fabiombed 8:144855fe02bd 369 }
fabiombed 8:144855fe02bd 370
fabiombed 8:144855fe02bd 371 /* Measure_Babybear ----------------------------------------------------------*/
fabiombed 8:144855fe02bd 372
fabiombed 8:144855fe02bd 373 void Measure_Babybear(void)
fabiombed 8:144855fe02bd 374 {
fabiombed 8:144855fe02bd 375
fabiombed 14:644f9e7278e9 376 #ifdef FlightSense
fabiombed 14:644f9e7278e9 377
fabiombed 8:144855fe02bd 378 status_l=board->sensor_left->GetMeasurement(als_continuous_polling, &data_sensor_left);
fabiombed 8:144855fe02bd 379 status_r=board->sensor_right->GetMeasurement(als_continuous_polling, &data_sensor_right);
fabiombed 8:144855fe02bd 380
fabiombed 8:144855fe02bd 381 babybear = data_sensor_right.lux - data_sensor_left.lux;
fabiombed 8:144855fe02bd 382
fabiombed 14:644f9e7278e9 383 diff = babybear;
fabiombed 1:8f312c1686b6 384
fabiombed 14:644f9e7278e9 385 #endif
fabiombed 8:144855fe02bd 386
fabiombed 8:144855fe02bd 387 }
fabiombed 8:144855fe02bd 388
fabiombed 8:144855fe02bd 389 /* Measure_Accelerometer -----------------------------------------------------*/
fabiombed 8:144855fe02bd 390
fabiombed 8:144855fe02bd 391 void Measure_Accelerometer(void)
fabiombed 8:144855fe02bd 392 {
fabiombed 8:144855fe02bd 393
fabiombed 14:644f9e7278e9 394 #ifdef Sensors
fabiombed 14:644f9e7278e9 395
fabiombed 8:144855fe02bd 396 accelerometer->Get_X_Axes(acc_data);
fabiombed 8:144855fe02bd 397
fabiombed 14:644f9e7278e9 398 diff = acc_data[0];
fabiombed 8:144855fe02bd 399
fabiombed 14:644f9e7278e9 400 #endif
fabiombed 8:144855fe02bd 401
fabiombed 8:144855fe02bd 402 }
fabiombed 8:144855fe02bd 403
fabiombed 8:144855fe02bd 404 /* Control_Motor -------------------------------------------------------------*/
fabiombed 8:144855fe02bd 405
fabiombed 8:144855fe02bd 406 void Control_Motor(void)
fabiombed 8:144855fe02bd 407 {
fabiombed 8:144855fe02bd 408
fabiombed 14:644f9e7278e9 409 #ifdef EasySpin
fabiombed 14:644f9e7278e9 410
fabiombed 14:644f9e7278e9 411 diff_abs = abs(diff);
fabiombed 8:144855fe02bd 412
fabiombed 14:644f9e7278e9 413 //printf("Diff: %d lux/mems\n\r", diff_abs);
fabiombed 14:644f9e7278e9 414 motor->SetMaxSpeed(diff_abs);
fabiombed 14:644f9e7278e9 415
fabiombed 14:644f9e7278e9 416 if (diff>0) { left=0; right=1; }
fabiombed 14:644f9e7278e9 417 if (diff<0) { left=1; right=0; }
fabiombed 14:644f9e7278e9 418
fabiombed 14:644f9e7278e9 419 if (diff_abs>TOLLERANCE) {
fabiombed 14:644f9e7278e9 420 if (diff_abs <=RANGE_1)
fabiombed 8:144855fe02bd 421 {
fabiombed 8:144855fe02bd 422 if (left) { strcpy(DisplayStr,"E___"); }
fabiombed 8:144855fe02bd 423 if (right) { strcpy(DisplayStr,"___3"); }
fabiombed 8:144855fe02bd 424 }
fabiombed 14:644f9e7278e9 425 else if (diff_abs >RANGE_1 & diff_abs <=RANGE_2)
fabiombed 8:144855fe02bd 426 {
fabiombed 8:144855fe02bd 427 if (left) { strcpy(DisplayStr,"E==="); }
fabiombed 8:144855fe02bd 428 if (right) { strcpy(DisplayStr,"===3"); }
fabiombed 8:144855fe02bd 429 }
fabiombed 14:644f9e7278e9 430 else if (diff_abs >RANGE_2)
fabiombed 8:144855fe02bd 431 {
fabiombed 8:144855fe02bd 432 if (left) { strcpy(DisplayStr,"E~~~"); }
fabiombed 8:144855fe02bd 433 if (right) { strcpy(DisplayStr,"~~~3"); }
fabiombed 8:144855fe02bd 434 }
fabiombed 8:144855fe02bd 435
fabiombed 8:144855fe02bd 436 // In Case of Change Direction
fabiombed 8:144855fe02bd 437 if (left & dir==2) { changedir=1; }
fabiombed 8:144855fe02bd 438 if (right & dir==1) { changedir=1; }
fabiombed 0:becf0d313663 439
fabiombed 8:144855fe02bd 440 // Run only if Stop or Change Direction
fabiombed 14:644f9e7278e9 441 if (diff_abs>TOLLERANCE & (dir==0 | changedir==1)) {
fabiombed 8:144855fe02bd 442 if (left) { motor->Run(StepperMotor::FWD); dir=1; changedir=0; }
fabiombed 8:144855fe02bd 443 if (right) { motor->Run(StepperMotor::BWD); dir=2; changedir=0; }
fabiombed 14:644f9e7278e9 444 printf("\n\rRUN");
fabiombed 8:144855fe02bd 445 }
fabiombed 8:144855fe02bd 446 }
fabiombed 8:144855fe02bd 447
fabiombed 8:144855fe02bd 448 // Get Motor Position and Control Rotation Block
fabiombed 8:144855fe02bd 449 pos = motor->GetPosition();
fabiombed 8:144855fe02bd 450 if (pos>STOP | pos<-STOP) {
fabiombed 8:144855fe02bd 451 if (pos>0) { motor->GoTo(STOP); }
fabiombed 8:144855fe02bd 452 if (pos<0) { motor->GoTo(-STOP); }
fabiombed 14:644f9e7278e9 453 printf("\n\rGOTO");
fabiombed 8:144855fe02bd 454 }
fabiombed 1:8f312c1686b6 455
fabiombed 8:144855fe02bd 456 // Stop Motor
fabiombed 14:644f9e7278e9 457 if (diff_abs<=TOLLERANCE) {
fabiombed 8:144855fe02bd 458 arrest=1;
fabiombed 15:019b8d60c89d 459 if (display==0) { strcpy(DisplayStr,"----"); }
fabiombed 15:019b8d60c89d 460 if (display==2) { strcpy(DisplayStr,"E 3"); }
fabiombed 8:144855fe02bd 461 }
fabiombed 8:144855fe02bd 462
fabiombed 8:144855fe02bd 463 if (arrest==1 && dir!=0 ) { // Stop just one time
fabiombed 8:144855fe02bd 464 motor->HardStop();
fabiombed 8:144855fe02bd 465 dir=0;
fabiombed 8:144855fe02bd 466 changedir=0;
fabiombed 8:144855fe02bd 467 arrest=0;
fabiombed 14:644f9e7278e9 468 printf("\n\rSTOP");
fabiombed 8:144855fe02bd 469 }
fabiombed 8:144855fe02bd 470
fabiombed 14:644f9e7278e9 471 #endif
fabiombed 14:644f9e7278e9 472
fabiombed 8:144855fe02bd 473 }
fabiombed 8:144855fe02bd 474
fabiombed 8:144855fe02bd 475 /* Measure_SolarPanel --------------------------------------------------------*/
fabiombed 8:144855fe02bd 476
fabiombed 8:144855fe02bd 477 void Measure_SolarPanel(void)
fabiombed 8:144855fe02bd 478 {
fabiombed 8:144855fe02bd 479
fabiombed 8:144855fe02bd 480 // AnalogIn: 0V return 0.0 , 3.3V return 1.0
fabiombed 14:644f9e7278e9 481 measure = analog_read.read() * 3300;
fabiombed 8:144855fe02bd 482 //printf("Measure = %.0f mV\r\n", measure);
fabiombed 8:144855fe02bd 483 //board->display->DisplayDigit("A", 0);
fabiombed 8:144855fe02bd 484
fabiombed 15:019b8d60c89d 485 if (display==1) { sprintf(DisplayStr, "%d", measure); }
fabiombed 14:644f9e7278e9 486
fabiombed 8:144855fe02bd 487 }
fabiombed 1:8f312c1686b6 488
fabiombed 8:144855fe02bd 489 /* Main ----------------------------------------------------------------------*/
fabiombed 8:144855fe02bd 490
fabiombed 8:144855fe02bd 491 int main()
fabiombed 8:144855fe02bd 492 {
fabiombed 8:144855fe02bd 493
fabiombed 8:144855fe02bd 494 // Printing to the console
fabiombed 14:644f9e7278e9 495 printf("\r\n\r\nSunTracker by Fabio Brembilla\r\n\r\n");
fabiombed 11:b5e23d64d366 496
fabiombed 8:144855fe02bd 497 Initialization();
fabiombed 14:644f9e7278e9 498 BLE_Initialization();
fabiombed 7:54984d031243 499
fabiombed 8:144855fe02bd 500 mybutton.fall(&User_Button_Pressed);
fabiombed 7:54984d031243 501
fabiombed 8:144855fe02bd 502 // Loop until push User Button to Set 0 Point
fabiombed 14:644f9e7278e9 503 printf("\r\nWait PUSH Button");
fabiombed 8:144855fe02bd 504 strcpy(DisplayStr,"pusH");
fabiombed 8:144855fe02bd 505 while(start<1) {
fabiombed 14:644f9e7278e9 506 #ifdef FlightSense
fabiombed 8:144855fe02bd 507 board->display->DisplayString(DisplayStr, 4);
fabiombed 14:644f9e7278e9 508 p_BLEdev->waitForEvent();
fabiombed 8:144855fe02bd 509 //printf("%s\n\r", DisplayStr);
fabiombed 14:644f9e7278e9 510 #endif
fabiombed 8:144855fe02bd 511 }
fabiombed 4:1d3d071a4c2c 512
fabiombed 14:644f9e7278e9 513 printf("\r\n\r\nStart Main Loop");
fabiombed 6:4cbf7303b496 514
fabiombed 14:644f9e7278e9 515 #ifdef EasySpin
fabiombed 14:644f9e7278e9 516 motor->Enable(); // To put the motor on hold by execute CmdEnable
fabiombed 14:644f9e7278e9 517 #endif
fabiombed 10:d154094297ce 518
fabiombed 14:644f9e7278e9 519 #ifdef Ble
fabiombed 11:b5e23d64d366 520 static int INTLOOP=0;
fabiombed 14:644f9e7278e9 521 #endif
fabiombed 7:54984d031243 522
fabiombed 6:4cbf7303b496 523 // Main Loop
fabiombed 8:144855fe02bd 524 while(true)
fabiombed 8:144855fe02bd 525 {
fabiombed 15:019b8d60c89d 526 if (display==0 | display==1) { Measure_Babybear(); }
fabiombed 15:019b8d60c89d 527
fabiombed 15:019b8d60c89d 528 #ifndef Ble // without BLE it uses Accelerometer from SERVER, otherwise receive the value from CLIENT
fabiombed 15:019b8d60c89d 529 if (display==2) { Measure_Accelerometer(); }
fabiombed 15:019b8d60c89d 530 #endif
fabiombed 15:019b8d60c89d 531
fabiombed 8:144855fe02bd 532 Control_Motor();
fabiombed 8:144855fe02bd 533 Measure_SolarPanel();
fabiombed 14:644f9e7278e9 534
fabiombed 14:644f9e7278e9 535 #ifdef FlightSense
fabiombed 14:644f9e7278e9 536 board->display->DisplayString(DisplayStr, 4);
fabiombed 14:644f9e7278e9 537 //printf("%s\n\r", DisplayStr);
fabiombed 14:644f9e7278e9 538 #endif
fabiombed 14:644f9e7278e9 539
fabiombed 14:644f9e7278e9 540 #ifdef Ble
fabiombed 11:b5e23d64d366 541 INTLOOP++;
fabiombed 14:644f9e7278e9 542 if (INTLOOP==100)
fabiombed 15:019b8d60c89d 543 {
fabiombed 15:019b8d60c89d 544 //if (p_customcontrolservice->isControlNotificationEn()) {
fabiombed 15:019b8d60c89d 545 printf("\n\r\n\rSend BLE Display %d", display);
fabiombed 15:019b8d60c89d 546 p_customcontrolservice->sendControlState(display);
fabiombed 15:019b8d60c89d 547 //p_customcontrolservice->updateControlState(display);
fabiombed 15:019b8d60c89d 548 //}
fabiombed 15:019b8d60c89d 549 //if (p_customsensorservice->isDifferenceNotificationEn()) {
fabiombed 15:019b8d60c89d 550 printf("\n\rSend BLE Difference %d lux/mems", diff); // Send BLE diff, no diff_abs
fabiombed 15:019b8d60c89d 551 p_customsensorservice->sendEnvDifference(diff);
fabiombed 15:019b8d60c89d 552 //p_customsensorservice->updateEnvDifference(diff);
fabiombed 15:019b8d60c89d 553 //}
fabiombed 15:019b8d60c89d 554 //if (p_customsensorservice->isPositionNotificationEn()) {
fabiombed 15:019b8d60c89d 555 printf("\n\rSend BLE Position %d", pos);
fabiombed 15:019b8d60c89d 556 p_customsensorservice->sendEnvPosition(pos);
fabiombed 15:019b8d60c89d 557 //p_customsensorservice->updateEnvPosition(pos);
fabiombed 15:019b8d60c89d 558 //}
fabiombed 15:019b8d60c89d 559 //if (p_customsensorservice->isSunpanelNotificationEn()) {
fabiombed 15:019b8d60c89d 560 printf("\n\rSend BLE Sunpanel %d mV", measure);
fabiombed 15:019b8d60c89d 561 p_customsensorservice->sendEnvSunpanel(measure);
fabiombed 15:019b8d60c89d 562 //p_customsensorservice->updateEnvSunpanel(measure);
fabiombed 15:019b8d60c89d 563 //}
fabiombed 14:644f9e7278e9 564 INTLOOP=0;
fabiombed 14:644f9e7278e9 565 }
fabiombed 14:644f9e7278e9 566
fabiombed 11:b5e23d64d366 567 p_BLEdev->waitForEvent();
fabiombed 14:644f9e7278e9 568 #endif
fabiombed 8:144855fe02bd 569 }
fabiombed 4:1d3d071a4c2c 570
fabiombed 8:144855fe02bd 571 //status_l=board->sensor_left->StopMeasurement(als_continuous_polling);
fabiombed 8:144855fe02bd 572 //status_r=board->sensor_right->StopMeasurement(als_continuous_polling);
fabiombed 4:1d3d071a4c2c 573
fabiombed 14:644f9e7278e9 574 }