Hello world for bm1383glv on mbed classic. Sets up treshold interrupts and makes measurements. Depends on rohm-sensor-hal and rohm-bm1383-glv.

Dependencies:   mbed rohm-bm1383-glv rohm-sensor-hal

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main_classic.cpp Source File

main_classic.cpp

00001 /*   Copyright 2016 Rohm Semiconductor
00002 
00003    Licensed under the Apache License, Version 2.0 (the "License");
00004    you may not use this file except in compliance with the License.
00005    You may obtain a copy of the License at
00006 
00007        http://www.apache.org/licenses/LICENSE-2.0
00008 
00009    Unless required by applicable law or agreed to in writing, software
00010    distributed under the License is distributed on an "AS IS" BASIS,
00011    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012    See the License for the specific language governing permissions and
00013    limitations under the License.
00014 */
00015 
00016 #include "rohm-sensor-hal/rohm-sensor-hal/rohm_hal.h"       //mbed.h, types, DEBUG_print*
00017 #include "rohm-sensor-hal/rohm-sensor-hal/I2CCommon.h"
00018 
00019 #include "rohm-bm1383-glv/rohm-bm1383-glv/bm1383_driver.h"
00020 #include "rohm-bm1383-glv/rohm-bm1383-glv/bm1383glv.h"
00021 
00022 Serial pc(USBTX, USBRX);
00023 
00024 
00025 void printTreshodRegStatus(){
00026     if(bm1383_is_treshold_high_crossed()){
00027         pc.printf("TresHighReg INT");
00028         }
00029     else{
00030         pc.printf("TresHighReg NO INT");
00031         }
00032     pc.printf("\r\n");
00033     if(bm1383_is_treshold_low_crossed()){
00034         pc.printf("TresLowReg  INT");
00035         }
00036     else{
00037         pc.printf("TresLowReg  NO INT");
00038         }
00039     pc.printf("\r\n");
00040   }
00041  
00042     
00043 void bm1383_init_and_setup(){
00044     pc.printf("\nBM1383 library test program.\n\r");
00045     I2CCommonBegin();
00046 
00047     bm1383_wait_until_found();
00048     pc.printf("\nSensor found.\n\r");
00049     bm1383_mode_poweroff2reset();
00050     wait(1);
00051     bm1383_mode_reset2standby();
00052 
00053     //setup bm1383 if needed
00054     bm1383_set_low_treshold(100);
00055     bm1383_enable_interrupt_latching();
00056     //bm1383_disable_interrupt_pullup();  //Pullup doesn't work on Japan-shield? Int line stays low(triggered).
00057     bm1383_enable_treshold_interrupts();
00058     bm1383_clear_interrupt();
00059 }
00060     
00061 void bm1383_read_previous_measurement_and_start_new_one(){
00062     float pressure;
00063     static uint16_t treshold = 0;
00064 
00065     //waitActiveLowInterrupt(INTPIN);
00066 
00067     pressure = bm1383_read_pressure();
00068     pc.printf("Pressure: %f\n\r", pressure);
00069 
00070     printTreshodRegStatus();
00071     pc.printf("Clear int command\n\r");
00072     pc.printf("\r\n");
00073     bm1383_clear_interrupt();
00074     //waitActiveLowInterruptClear(INTPIN);
00075 
00076     treshold = treshold + 1000;    
00077     pc.printf("Treshold: %d \n\r", treshold);
00078     pc.printf("Start meas. - ");
00079     bm1383_set_high_treshold(treshold);
00080     bm1383_start_measurement_oneshot();
00081 }
00082 
00083 
00084 int main() {
00085     while(1){
00086         bm1383_read_previous_measurement_and_start_new_one();
00087         wait(0.5);
00088         }
00089     }
00090