Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HCSR04 X_NUCLEO_6180XA1 mbed
Fork of HelloWorld_6180XA1 by
Diff: main.cpp
- Revision:
- 43:f03152407731
- Parent:
- 42:ee8c5b1f2e1d
- Child:
- 44:3c68d5aa842e
diff -r ee8c5b1f2e1d -r f03152407731 main.cpp
--- a/main.cpp Wed Jun 15 11:57:24 2016 +0000
+++ b/main.cpp Mon Sep 12 09:19:46 2016 +0000
@@ -31,14 +31,7 @@
OperatingMode operating_mode, prev_operating_mode;
/* flags that handle interrupt request */
-bool int_sensor_top=false, int_stop_measure=false;
-
-/* ISR callback function of the sensor_top */
-void SensorTopIRQ(void)
-{
- int_sensor_top=true;
- board->sensor_top->DisableInterruptMeasureDetectionIRQ();
-}
+int int_stop_measure=false;
/* ISR callback function of the user blue button to stop program */
void StopMeasureIRQ(void)
@@ -51,9 +44,9 @@
{
char str[5];
- if(op_mode==range_continuous_interrupt || op_mode==range_continuous_polling)
+ if(op_mode==range_continuous_interrupt || op_mode==range_single_shot_polling)
{
- if(data_sensor_top.range_mm!=0xFFFFFFFF)
+ if(data_sensor_top.range_mm!=255)
{
sprintf(str,"%d",data_sensor_top.range_mm);
}
@@ -62,7 +55,7 @@
sprintf(str,"%s","----");
}
}
- else if(op_mode==als_continuous_interrupt || op_mode==als_continuous_polling)
+ else if(op_mode==als_continuous_interrupt || op_mode==als_single_shot_polling)
{
if(data_sensor_top.lux!=0xFFFFFFFF)
{
@@ -87,9 +80,9 @@
switch (OpMode) {
case PollMeasure:
if(measure==RANGE)
- ret = range_continuous_polling;
+ ret = range_single_shot_polling;
else if(measure==ALS)
- ret = als_continuous_polling;
+ ret = als_single_shot_polling;
break;
case IntMeasure:
@@ -99,25 +92,49 @@
ret = als_continuous_interrupt;
break;
}
- return ret;
+ return ret;
}
/* Print on USB Serial the started OperatingMode */
void PrintStartMessage(OperatingMode op_mode)
{
- if(op_mode==range_continuous_interrupt)
- printf("\nStarted range continuous interrupt measure\n\r");
- else if(prev_operating_mode==als_continuous_interrupt)
- printf("\nStarted als continuous interrupt measure\n\r");
+ switch (op_mode) {
+ case range_single_shot_polling:
+ printf("\nStarted range single shot polling measure\n\r");
+ break;
+ case als_single_shot_polling:
+ printf("\nStarted als single shot polling measure\n\r");
+ break;
+ case range_continuous_interrupt:
+ printf("\nStarted range continuous interrupt measure\n\r");
+ break;
+ case als_continuous_interrupt:
+ printf("\nStarted als continuous interrupt measure\n\r");
+ break;
+ default:
+ break;
+ }
}
/* Print on USB Serial the stopped OperatingMode */
void PrintStopMessage(OperatingMode op_mode)
{
- if(op_mode==range_continuous_interrupt)
- printf("Stopped range continuous interrupt measure\n\r");
- else if(prev_operating_mode==als_continuous_interrupt)
- printf("Stopped als continuous interrupt measure\n\r");
+ switch (op_mode) {
+ case range_single_shot_polling:
+ printf("\nStopped range single shot polling measure\n\r");
+ break;
+ case als_single_shot_polling:
+ printf("\nStopped als single shot polling measure\n\r");
+ break;
+ case range_continuous_interrupt:
+ printf("\nStopped range continuous interrupt measure\n\r");
+ break;
+ case als_continuous_interrupt:
+ printf("\nStopped als continuous interrupt measure\n\r");
+ break;
+ default:
+ break;
+ }
}
/* Print on board 4 Digit display the indicated message <= 4 char */
@@ -137,54 +154,33 @@
}
-void IntContinousALSorRangeMeasure (DevI2C *device_i2c) {
+void PollSingleALSorRangeMeasure (DevI2C *device_i2c) {
int status;
/* creates the 6180XA1 expansion board singleton obj */
board=X_NUCLEO_6180XA1::Instance(device_i2c, A3, A2, D13, D2);
- DisplayMsg ("INT");
+ DisplayMsg ("pOLL");
/* init the 6180XA1 expansion board with default values */
status=board->InitBoard();
- if(status)
- printf("Failed to init board!\n\r");
+ if(status) printf("Failed to init board!\n\r");
/* check the red slider position for ALS/Range measure */
- operating_mode=CheckSlider(IntMeasure);
- /* start the measure on sensor top */
- status=board->sensor_top->StartMeasurement(operating_mode, SensorTopIRQ, NULL, NULL);
- if(!status)
+ operating_mode=CheckSlider(PollMeasure);
+ PrintStartMessage(operating_mode);
+ while(1)
{
- prev_operating_mode=operating_mode;
- PrintStartMessage(operating_mode);
- while(1)
+ if(int_stop_measure) /* Blue Button isr was triggered */
{
- 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);
- }
- if(int_stop_measure) /* Blue Button isr was triggered */
- {
- status=board->sensor_top->StopMeasurement(prev_operating_mode); /* stop the measure and exit */
- if(!status)
- PrintStopMessage(prev_operating_mode);
- int_stop_measure = false;
- printf("\nProgram stopped!\n\n\r");
- break;
- }
- operating_mode=CheckSlider(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 */
- if(!status)
- PrintStopMessage(prev_operating_mode);
- prev_operating_mode=operating_mode;
- status=board->sensor_top->StartMeasurement(operating_mode, SensorTopIRQ, NULL, NULL); /* start the new measure */
- if(!status)
- PrintStartMessage(operating_mode);
- } else
- DisplayRefresh(operating_mode);
+ PrintStopMessage(prev_operating_mode);
+ int_stop_measure = false;
+ printf("\nProgram stopped!\n\n\r");
+ break;
}
+ operating_mode=CheckSlider(PollMeasure); /* check if red slider was moved */
+ if (operating_mode == range_single_shot_polling) {
+ board->sensor_top->GetDistance(&data_sensor_top.range_mm);
+ } else if (operating_mode == als_single_shot_polling) {
+ board->sensor_top->GetLux(&data_sensor_top.lux);
+ }
+ DisplayRefresh(operating_mode);
}
DisplayMsg("BYE");
}
@@ -195,13 +191,14 @@
Press the blue user button to stop the measurements in progress
=============================================================================*/
int main()
-{
+{
+
#if USER_BUTTON==PC_13 // we are cross compiling for Nucleo-f401
InterruptIn stop_button (USER_BUTTON);
stop_button.rise (&StopMeasureIRQ);
#endif
DevI2C *device_i2c =new DevI2C(VL6180X_I2C_SDA, VL6180X_I2C_SCL);
- IntContinousALSorRangeMeasure (device_i2c); // start continous measures Interrupt based
+ PollSingleALSorRangeMeasure (device_i2c); // start continous measures Interrupt based
}
