PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
accel_shaken.c
1 
2 #include "simpletools.h"
3 #include "badgetools.h"
4 
5 void ee_init();
6 void init_MMA7660FC(void);
7 int raw2g100(char gRaw);
8 
11 //volatile int bt_accelInitFlag = 0;
12 volatile int eei2cLock;
13 volatile int eei2cLockFlag;
14 
15 int accel_shaken(void)
16 {
17  if(!st_eeInitFlag) ee_init();
18  unsigned char axis = 3; // TILT status reg
19  unsigned char val = 0;
20  while(lockset(eei2cLock));
21  i2c_in (st_eeprom, MMA7660_I2C,
22  axis, 1, &val, 1);
24  lockclr(eei2cLock);
25  //print("val = %08b, ", val);
26  val >>= 7; // TILT reg SHAKEN bit
27  val &= 1;
28  return val;
29 }
30 
31 /*
32  TERMS OF USE: MIT License
33 
34  Permission is hereby granted, free of charge, to any person obtaining a
35  copy of this software and associated documentation files (the "Software"),
36  to deal in the Software without restriction, including without limitation
37  the rights to use, copy, modify, merge, publish, distribute, sublicense,
38  and/or sell copies of the Software, and to permit persons to whom the
39  Software is furnished to do so, subject to the following conditions:
40 
41  The above copyright notice and this permission notice shall be included in
42  all copies or substantial portions of the Software.
43 
44  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
47  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
49  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
50  DEALINGS IN THE SOFTWARE.
51 */
52 
i2c_in
HUBTEXT int i2c_in(i2c *busID, int i2cAddr, int memAddr, int memAddrCount, unsigned char *data, int dataCount)
Receive data from device using I2C protocol.
Definition: i2c_in.c:20
st_eeprom
i2c * st_eeprom
The busID for the Propeller Activity Board's EEPROM bus.
Definition: accel_shaken.c:9
i2c_stop
HUBTEXT void i2c_stop(i2c *bus)
Send Signal i2c stop condition on bus.
Definition: simplei2c.c:78
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
lockset
#define lockset(lockid)
Set a lock.
Definition: propeller.h:163
i2c_st
Definition: simplei2c.h:25
lockclr
#define lockclr(lockid)
Clear lock.
Definition: propeller.h:170
badgetools.h
This library provides convenient functions for a variety of Parallax eBadge operations.
st_eeInitFlag
int st_eeInitFlag
Initialization flag used by ee_ functions.
Definition: accel_shaken.c:10
accel_shaken
int accel_shaken(void)
Check if accelerometer was shaken recently, within the last half second.
Definition: accel_shaken.c:15