ZStar .NET library FreeFallEventEnableAll(UInt EnableMask);

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ZStar .NET library FreeFallEventEnableAll(UInt EnableMask);

Jump to solution
1,951 Views
Epokh
Contributor I

Hi guys,

I was coding an application to detect the freefall condition of the zstar node modifying the pre-existing ZStarLib_example.

 

The code is quite simple:

 //Event that occur if a free fall condition is detected
            theZStar.OnFreeFall+=new ZStar3.OnFreeFallHandler(theZStar_OnFreeFall);

Now the problem is that I need to enable:

  theZStar.FreeFallEventEnableAll(1);

I have put a 1 and is working, but I would like to know how the EnableMask is defined.

Is it a kind of bitmask where every bit is the index address of every ZStar node?

 

        void theZStar_OnFreeFall(object sender, byte sensor)
        {
            // Are these data from our sensor 0
            if (sensor == 0)
            {       // Update labels with values of actual acceleration for all axes
                lb_Status.Text = "FreeFall!";
                MessageBox.Show("Fall detected!", "ZStarLib", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

 

 

Is it possible to get the source code also of the DemoApplication so that a developer can see how all the functions are used?

Labels (1)
0 Kudos
1 Solution
424 Views
Gargy
NXP Employee
NXP Employee

Hi,

I red your queations and answers are very simple. I first case the bit mask for all common fuction is in format 16-bit unsigned integer and each bit represents one sensor.

 

And for buttons - button are stored in Buttons property in sensor class. There are used only first three bits to store last state of buttons. To update this property burst read or full read must be done.

Example of code to read button status:

 

cb_ZstarBtn1.Checked = ((theSensor.Buttons & 0x01) == 0) ? false : true;
cb_ZstarBtn2.Checked = ((theSensor.Buttons & 0x02) == 0) ? false : true;
cb_ZstarBtn3.Checked = ((theSensor.Buttons & 0x04) == 0) ? false : true;

 

Have a nice day

View solution in original post

0 Kudos
4 Replies
424 Views
Epokh
Contributor I

Hi there I'm also unable to find the documentation for the definition of the byte mask relative to the Buttons property of the ZStar class.

I only managed so far to detect the first button:

ZStar.Buttons & 1

but the others are not correct

ZStar.Buttons & 2

ZStar.Buttons & 4

is the source code of the ZLib available in some way?

cheers.

 

0 Kudos
425 Views
Gargy
NXP Employee
NXP Employee

Hi,

I red your queations and answers are very simple. I first case the bit mask for all common fuction is in format 16-bit unsigned integer and each bit represents one sensor.

 

And for buttons - button are stored in Buttons property in sensor class. There are used only first three bits to store last state of buttons. To update this property burst read or full read must be done.

Example of code to read button status:

 

cb_ZstarBtn1.Checked = ((theSensor.Buttons & 0x01) == 0) ? false : true;
cb_ZstarBtn2.Checked = ((theSensor.Buttons & 0x02) == 0) ? false : true;
cb_ZstarBtn3.Checked = ((theSensor.Buttons & 0x04) == 0) ? false : true;

 

Have a nice day

0 Kudos
424 Views
Epokh
Contributor I

Hi Gargy,

thanks a lot it works.

Can you also explain to me how to use the GSelect method?

For instance I have the sensor whose sensibility is 2g 4g 8g.

When I get the GSelectList it gives me an integer=3.

Then suppose i want to select 8g i was thinking just to put 3,

but the method returns me an invalid operation.

I suppose there should be another byte mask but I cannot find it:

i tried 0x01, 0x03,0x02,0x04 but it didn't work.

 

Cheers.:robothappy:

 

0 Kudos
424 Views
Gargy
NXP Employee
NXP Employee

Hi ,

 you are near, but not exactly right. The GSelect List returns the count of g ranges of current connected sensor. And if you get 3 for MMA7456L device, that library supports 3 ranges!!

Index - range

0 - 8g

1 - 2g

2 - 4g

 

This order is not random but it reflect the order in datasheet for each accelerometer.

 

Good Luck

0 Kudos