Per Pradal sensore prossimità con display

Dependencies:   X_NUCLEO_6180XA1 mbed

Fork of HelloWorld_6180XA1_AppExample_1 by 3FEN

Files at this revision

API Documentation at this revision

Comitter:
Davidroid
Date:
Mon Mar 13 19:14:32 2017 +0000
Parent:
3:d3719ebf51c4
Commit message:
Aligned to ARM coding style.

Changed in this revision

X_NUCLEO_6180XA1.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r d3719ebf51c4 -r 84dfc00ae7b3 X_NUCLEO_6180XA1.lib
--- a/X_NUCLEO_6180XA1.lib	Fri Mar 03 15:11:39 2017 +0000
+++ b/X_NUCLEO_6180XA1.lib	Mon Mar 13 19:14:32 2017 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/ST/code/X_NUCLEO_6180XA1/#a37f407230ca
+http://developer.mbed.org/teams/ST/code/X_NUCLEO_6180XA1/#fa4c622b04a7
diff -r d3719ebf51c4 -r 84dfc00ae7b3 main.cpp
--- a/main.cpp	Fri Mar 03 15:11:39 2017 +0000
+++ b/main.cpp	Mon Mar 13 19:14:32 2017 +0000
@@ -1,25 +1,34 @@
+/*
+   This VL6180X Expansion board test application performs a range measurement
+   and an als measurement in interrupt mode on the onboard embedded top sensor. 
+   The board red slider selects on the flight the measurement type as ALS or
+   RANGE; the measured data is diplayed on the on bord 4digits display.
+
+   User Blue button allows to stop current measurement and the entire program
+   releasing all the resources.
+   Reset button is used to restart the program.
+
+   Polling operating modes don`t require callback function that handles IRQ 
+   callbacks. IRQ functions are used only for measures that require interrupts.
+
+   Notes:
+   + get_measurement() is asynchronous! It returns NOT_READY if the measurement
+     value is not ready to be read from the corresponding register. So you need
+     to wait for the result to be ready.\
+*/
+
+
+/* Includes ------------------------------------------------------------------*/
+
 #include "mbed.h"
-#include "x_nucleo_6180xa1.h"
+#include "XNucleo6180XA1.h"
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <assert.h>
 
-/* This VL6180X Expansion board test application performs a range measurement and an als measurement in interrupt mode
-   on the onboard embedded top sensor. 
-   The board red slider select on the flight the measurement type as ALS or RANGE; the measured data is diplayed on the 
-   on bord 4digits display.
 
-   User Blue button allows to stop current measurement and the entire program releasing all the resources.
-   Reset button is used to restart the program. */
-
-/* Polling operating modes don`t require callback function that handles IRQ 
-   Callback IRQ functions are used only for measure that require interrupt. */
-
-/* GetMeasurement is asynchronous! It returns NOT_READY if the measurement value 
-   is not ready to be read from the corresponding register. So you need to wait
-   for the result to be ready. */
-
+/* Definitions ---------------------------------------------------------------*/
 
 #define VL6180X_I2C_SDA   D14 
 #define VL6180X_I2C_SCL   D15 
@@ -30,34 +39,45 @@
 #define DELAY 2000  // 2Sec
 
 
+/* Types ---------------------------------------------------------------------*/
+
+/* Operating mode */
+operating_mode_t operating_mode, prev_operating_mode;
+enum op_mode_int_poll_t {
+    PollMeasure,
+    IntMeasure
+};
+
+
+/* Variables -----------------------------------------------------------------*/
+
 /* Expansion board */
-static X_NUCLEO_6180XA1 *board = NULL;
+static XNucleo6180XA1 *board = NULL;
 
 /* Measure data */
-MeasureData_t data_sensor_top;
+measure_data_t data_sensor_top;
 
-/* Operating mode */
-OperatingMode operating_mode, prev_operating_mode;
-enum OpModeIntPoll_t{ PollMeasure, IntMeasure };
-    
 /* Flags that handle interrupt request */
 bool int_sensor_top = false, int_stop_measure = false;  
 
+
+/* Functions -----------------------------------------------------------------*/
+
 /* ISR callback function of the sensor_top */
-void SensorTopIRQ(void)
+void sensor_top_irq(void)
 {
     int_sensor_top = true;
-    board->sensor_top->DisableInterruptMeasureDetectionIRQ();
+    board->sensor_top->disable_interrupt_measure_detection_irq();
 }
 
 /* ISR callback function of the user blue button to stop program */
-void StopMeasureIRQ(void)
+void stop_measure_irq(void)
 {
     int_stop_measure = true;
 }
 
 /* On board 4 digit local display refresh */
-void DisplayRefresh(OperatingMode op_mode)
+void display_refresh(operating_mode_t op_mode)
 {
     char str[5];
 
@@ -74,16 +94,16 @@
             sprintf(str,"%s","----");
         }
     }
-    board->display->DisplayString(str, strlen(str));       
+    board->display->display_string(str, strlen(str));       
 }
 
 /* On board red slider position check */
-OperatingMode CheckSlider(enum OpModeIntPoll_t OpMode)
+operating_mode_t check_slider(enum op_mode_int_poll_t op_mode)
 {
-    OperatingMode ret;
-    int measure = board->RdSwitch();
+    operating_mode_t ret;
+    int measure = board->rd_switch();
 
-    switch (OpMode) {
+    switch (op_mode) {
         case PollMeasure:
             if (measure==RANGE) {
                 ret = range_continuous_polling;
@@ -102,8 +122,8 @@
     return ret;      
 }
 
-/* Print on USB Serial the started OperatingMode */
-void PrintStartMessage(OperatingMode op_mode)
+/* Print on USB Serial the started operating_mode_t */
+void print_start_message(operating_mode_t op_mode)
 {
     if (op_mode==range_continuous_interrupt) {
         printf("\nStarted range continuous interrupt measure\n\r");
@@ -112,8 +132,8 @@
     }
 }
 
-/* Print on USB Serial the stopped OperatingMode */
-void PrintStopMessage(OperatingMode op_mode)
+/* Print on USB Serial the stopped operating_mode_t */
+void print_stop_message(operating_mode_t op_mode)
 {
     if (op_mode==range_continuous_interrupt) {
         printf("Stopped range continuous interrupt measure\n\r");
@@ -123,7 +143,7 @@
 }
 
 /* Print on board 4 Digit display the indicated message <= 4 char */
-void DisplayMsg(const char * msg)
+void display_msg(const char * msg)
 {
     Timer timer;
     char str[5];
@@ -132,86 +152,85 @@
     for (int i=0; i<DELAY; i=timer.read_ms())
     {
         sprintf(str,"%s",msg);
-        board->display->DisplayString(str, strlen(str));
+        board->display->display_string(str, strlen(str));
     }
     timer.stop();
 }
 
 /* Handle continuous ALS or Range measurement. */
-void IntContinousALSorRangeMeasure (DevI2C *device_i2c) {
+void int_continous_als_or_range_measure (DevI2C *device_i2c) {
     int status;
 
     /* Creates the 6180XA1 expansion board singleton obj */
 #ifdef TARGET_STM32F429
-    board = X_NUCLEO_6180XA1::Instance(device_i2c, A5, A2, D13, D2);
+    board = XNucleo6180XA1::instance(device_i2c, A5, A2, D13, D2);
 #else
-    board = X_NUCLEO_6180XA1::Instance(device_i2c, A3, A2, D13, D2);
+    board = XNucleo6180XA1::instance(device_i2c, A3, A2, D13, D2);
 #endif
-    DisplayMsg("INT");
+    display_msg("INT");
     
     /* Init the 6180XA1 expansion board with default values */
-    status = board->InitBoard();
+    status = board->init_board();
     if (status) {
         printf("Failed to init board!\n\r");
     }
 
     /* Check the red slider position for ALS/Range measure */
-    operating_mode=CheckSlider(IntMeasure);
+    operating_mode=check_slider(IntMeasure);
 
     /* Start the measure on sensor top */
-    status = board->sensor_top->StartMeasurement(operating_mode, SensorTopIRQ, NULL, NULL);
+    status = board->sensor_top->start_measurement(operating_mode, sensor_top_irq, NULL, NULL);
     if (!status) {
         prev_operating_mode=operating_mode;
-        PrintStartMessage(operating_mode);
+        print_start_message(operating_mode);
         while (true) {
             if (int_sensor_top) { /* 6180 isr was triggered */
                 int_sensor_top = false;
-                status = board->sensor_top->HandleIRQ(operating_mode, &data_sensor_top); /* handle the isr and read the meaure */
-                DisplayRefresh(operating_mode);
+                status = board->sensor_top->handle_irq(operating_mode, &data_sensor_top); /* handle the isr and read the meaure */
+                display_refresh(operating_mode);
             }
             if (int_stop_measure) { /* Blue Button isr was triggered */
-                status = board->sensor_top->StopMeasurement(prev_operating_mode); /* stop the measure and exit */
+                status = board->sensor_top->stop_measurement(prev_operating_mode); /* stop the measure and exit */
                 if (!status) {
-                    PrintStopMessage(prev_operating_mode);
+                    print_stop_message(prev_operating_mode);
                 }
                 int_stop_measure = false;
                 printf("\nProgram stopped!\n\n\r");
                 break;
             }
-            operating_mode = CheckSlider(IntMeasure); /* check if red slider was moved */
+            operating_mode = check_slider(IntMeasure); /* check if red slider was moved */
             if (operating_mode!=prev_operating_mode) {
-                DisplayRefresh(prev_operating_mode);
-                status = board->sensor_top->StopMeasurement(prev_operating_mode); /* stop the running measure */
+                display_refresh(prev_operating_mode);
+                status = board->sensor_top->stop_measurement(prev_operating_mode); /* stop the running measure */
                 if (!status) {
-                    PrintStopMessage(prev_operating_mode);
+                    print_stop_message(prev_operating_mode);
                 }
                 prev_operating_mode = operating_mode;
-                status = board->sensor_top->StartMeasurement(operating_mode, SensorTopIRQ, NULL, NULL); /* start the new measure */
+                status = board->sensor_top->start_measurement(operating_mode, sensor_top_irq, NULL, NULL); /* start the new measure */
                 if (!status) {
-                    PrintStartMessage(operating_mode);
+                    print_start_message(operating_mode);
                 }
             } else {
-                DisplayRefresh(operating_mode);
+                display_refresh(operating_mode);
             }
         }
     }
-    DisplayMsg("BYE");
+    display_msg("BYE");
 }
 
 /*=================================== Main ==================================
  Move the VL6180X Expansion board red slider to switch between ALS or Range
  measures.
- Press the blue user button to stop the measurements in progress    
+ Press the blue user button to stop the measurements in progress.   
 =============================================================================*/
 int main()
 {   
 #if USER_BUTTON==PC_13  // Cross compiling for Nucleo-F401
     InterruptIn stop_button (USER_BUTTON);
-    stop_button.rise (&StopMeasureIRQ);  
+    stop_button.rise (&stop_measure_irq);  
 #endif   
     DevI2C *device_i2c = new DevI2C(VL6180X_I2C_SDA, VL6180X_I2C_SCL);     
 
     /* Start continous measures Interrupt based */
-    IntContinousALSorRangeMeasure (device_i2c);
+    int_continous_als_or_range_measure (device_i2c);
 }
-