• Enter email to sit in the first row

How to use BBMagic sensors


All we need to use data from BBMagic sensors is couple lines of code:

#include <stdio.h>
#include <stdlib.h>
#include "bbmagic_lib.h"
int main(void)
{
    unsigned char bbm_buf[100] ;
    int i, bbm_id ;
    i =bbm_bt_open(0, 0, 0, LIB_SHOW_CONFIG) ;
    if(i) exit(1) ;
    do
    {
        bbm_id = bbm_bt_read(bbm_buf) ;
        if( bbm_id == BBMAGIC_M_BUTTON)
        {
            printf("Button: ") ;
            if(bbm_buf[BBM_BUTTON_BUTTON_FUNCTION] == BBM_BUTTON_FN_SINGLE_CLICK)
                printf("SINGLE CLICK") ;
            else if(bbm_buf[BBM_BUTTON_BUTTON_FUNCTION] == BBM_BUTTON_FN_DOUBLE_CLICK)
                printf("DOUBLE CLICK") ;
            else if(bbm_buf[BBM_BUTTON_BUTTON_FUNCTION] == BBM_BUTTON_FN_HOLDING)
                printf("HOLDING") ;
            printf("\n\r") ;
        }
        if( bbm_id == BBMAGIC_M_MAGNETO)
        {
            printf("Window: ") ;
            if(bbm_buf[BBM_MAGNETO_FLAGS] & BBM_MAGNETO_MAGNET_MASK) printf(" CLOSED") ;
            else printf(" OPEN") ;
            printf("\n\r") ;
        }
        bbm_sleep_ms(100) ;
    }while(bbm_id != -1) ;
    bbm_bt_close() ;
    exit(0) ;
}

And here is how it goes:
BBMagic sesnor screen example

bbm_buf[100]
Its a little buffer for data received from BBMagic sensors.

bbm_bt_open(0, 0, 0, LIB_SHOW_CONFIG)
This function opens BBMagic Bluetooth Smart communication. For more see ‘bbmagic_lib.h’ file.

bbm_bt_read(bbm_buf)
Function for reading modules data. For more see ‘bbmagic_lib.h’ file.

if( bbm_id == BBMAGIC_M_BUTTON)
If there is data from BBMagic BUTTON module lets check it out: single button click, double button click or button holding.

if( bbm_id == BBMAGIC_M_MAGNETO)
If there is data from BBMagic MAGNETO lets print its state.

bbm_sleep_ms(100)
It stops mains application loop for 100 milliseconds. Use it instead of usleep(), sleep(), etc.

bbm_bt_close()
This function closes BBMagic Bluetooth Smart communication.

Do It Yourself

‘bbmagic_sensor_test’ is more complex example application. It receives data from such sensors:

  • BBair
  • BBMagic BUTTON
  • BBMagic MOTION
  • BBMagic METEO
  • BBMagic MAGNETO
  • BBMagic FLOOD

To get, unzip and install type:

wget http://bbmagic.net/download/src_2/bbmagic_sensor_test.tar.gz
tar -zxvf bbmagic_sensor_test.tar.gz
cd bbmagic_sensor_test
sudo ./bbmagic_sensor_test

BBMagic sesnor test app get
And how it deals with BUTTON, MAGNETO, MOTION and BBair sensors:
BBMagic sesnor test app
BBMagic sesnor test app BBair

Tagged , , . Bookmark the permalink.

Comments are closed.