Sensorian
1.0
C API Reference Guide Library
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
main.c
Go to the documentation of this file.
1
/****************************************************************************
2
* Copyright (C) 2015 Sensorian
3
* *
4
* This file is part of Sensorian. *
5
* *
6
* Sensorian is free software: you can redistribute it and/or modify it *
7
* under the terms of the GNU Lesser General Public License as published *
8
* by the Free Software Foundation, either version 3 of the License, or *
9
* (at your option) any later version. *
10
* *
11
* Sensorian is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Lesser General Public License for more details. *
15
* *
16
* You should have received a copy of the GNU Lesser General Public *
17
* License along with Sensorian. *
18
* If not, see <http://www.gnu.org/licenses/>. *
19
****************************************************************************/
20
30
#include <stdio.h>
31
#include "
Utilities.h
"
32
#include "
FXOS8700CQ.h
"
33
#include "
i2c.h
"
34
35
int
main
(
int
argc,
char
**argv)
36
{
37
char
orienta = 0;
38
39
I2C_Initialize
(
FXOS8700CQ_ADDRESS
);
//Initialize I2C and setup chip address
40
FXOS8700CQ_Initialize
();
//Setup chip in hybrid mode
41
FXOS8700CQ_StandbyMode
();
42
FXOS8700CQ_WriteByte
(
SYSMOD
,0x01);
//Set to wake up
43
FXOS8700CQ_ActiveMode
();
44
char
id
=
FXOS8700CQ_ReadByte
(
PL_BF_ZCOMP
);
45
printf(
"PL_BF_ZCOMP: 0x%02X. \r\n"
,
id
);
46
47
FXOS8700CQ_ConfigureOrientation
();
48
49
unsigned
char
mode = 0;
50
while
(1)
51
{
52
if
(
FXOS8700CQ_ReadStatusReg
() & 0x80)
53
{
54
orienta =
FXOS8700CQ_GetOrientation
();
55
printf(
"\r\nRegister: %02X \r\n"
, orienta);
56
57
mode = (orienta >> 1) & 0x03;
//mask the rets of the bits
58
59
switch
(mode)
60
{
61
case
0:
62
printf(
"Landscape right.\r\n"
);
63
break
;
64
case
1:
65
printf(
"Landscape left. \r\n"
);
66
break
;
67
case
2:
68
printf(
"Portrait down.\r\n"
);
69
break
;
70
case
3:
71
printf(
"Portrait up.\r\n"
);
72
break
;
73
default
:
74
printf(
"Nothing here"
);
75
break
;
76
}
77
delay_ms
(500);
78
}
79
}
80
81
printf(
"Shutting down"
);
82
I2C_Close
();
//Return I2C pins to default status
83
84
return
0;
85
}
FXOS8700CQ_ConfigureOrientation
void FXOS8700CQ_ConfigureOrientation(void)
Configure Orientation mode.
Definition:
FXOS8700CQ.c:328
Utilities.h
Utilities driver header.
SYSMOD
#define SYSMOD
Definition:
MemoryMap.h:41
FXOS8700CQ_ADDRESS
#define FXOS8700CQ_ADDRESS
Definition:
FXOS8700CQ.h:35
I2C_Close
void I2C_Close(void)
Closes the I2C peripheral.
Definition:
i2c.c:174
FXOS8700CQ_ActiveMode
void FXOS8700CQ_ActiveMode(void)
Starts up the sensor in Active mode.
Definition:
FXOS8700CQ.c:69
FXOS8700CQ.h
I2C_Initialize
void I2C_Initialize(unsigned char address)
Initializes the I2C peripheral.
Definition:
i2c.c:36
FXOS8700CQ_ReadStatusReg
char FXOS8700CQ_ReadStatusReg(void)
Return the value of the status register.
Definition:
FXOS8700CQ.c:60
FXOS8700CQ_Initialize
void FXOS8700CQ_Initialize(void)
Initialize FXOS8700CQ, configure for an output rate of 200Hz with a +/- 2g scale. ...
Definition:
FXOS8700CQ.c:42
i2c.h
I2C driver header.
main
int main(int argc, char **argv)
Definition:
main.c:34
FXOS8700CQ_ReadByte
char FXOS8700CQ_ReadByte(char reg)
Starts up the sensor in Active mode.
Definition:
FXOS8700CQ.c:539
delay_ms
void delay_ms(unsigned int ms)
Delay in ms.
Definition:
Utilities.c:39
FXOS8700CQ_GetOrientation
char FXOS8700CQ_GetOrientation(void)
Returns current mode of the chip.
Definition:
FXOS8700CQ.c:318
FXOS8700CQ_WriteByte
void FXOS8700CQ_WriteByte(char reg, char value)
Writes a value to a register.
Definition:
FXOS8700CQ.c:517
PL_BF_ZCOMP
#define PL_BF_ZCOMP
Definition:
MemoryMap.h:49
FXOS8700CQ_StandbyMode
char FXOS8700CQ_StandbyMode(void)
Starts up the sensor in Active mode.
Definition:
FXOS8700CQ.c:79
FXOS8700CQR1
Example2
main.c
Generated on Sun Jul 12 2015 20:25:27 for Sensorian by
1.8.9.1