mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-24 04:43:36 +00:00
fix compare of null pointer timers
This commit is contained in:
parent
cdafc86b64
commit
e5304ee6d1
1
TODO.txt
1
TODO.txt
@ -1,7 +1,6 @@
|
||||
/* new todo file for BTstack */
|
||||
|
||||
NEXT:
|
||||
- redo status bar icon. it's too dark.
|
||||
- check why BT does not shut off after a while of inactivity on iPhone
|
||||
- WiiMote Demo
|
||||
- upside down is not shown correctly
|
||||
|
@ -58,28 +58,41 @@ WiiMoteOpenGLDemoAppDelegate * theMainApp;
|
||||
@synthesize inqViewControl;
|
||||
|
||||
#define SIZE 5
|
||||
int counter;
|
||||
static void bt_data_cb(uint8_t x, uint8_t y, uint8_t z){
|
||||
// NSLog(@"BT data: %u %u %u", x , y ,z);
|
||||
// [[theMainApp status] setText:[NSString stringWithFormat:@"X:%03u Y:%03u Z:%03u", x, y, z]];
|
||||
float ax = x - 128;
|
||||
float ay = y - 128;
|
||||
float az = z - 128;
|
||||
|
||||
#if 0
|
||||
// normalize
|
||||
float sum = ax + ay + az;
|
||||
ax /= sum;
|
||||
ay /= sum;
|
||||
az /= sum;
|
||||
#endif
|
||||
|
||||
int roll = atan2(ax, sqrt(ay*ay+az*az)) * 180 / M_PI;
|
||||
int pitch = atan2(ay, sqrt(ax*ax+az*az)) * 180 / M_PI;
|
||||
int theta = atan2(sqrt(ax*ax+ay*ay), az) * 180 / M_PI;
|
||||
if (az < 0) {
|
||||
// roll = 180 - roll;
|
||||
// pitch = 180 - pitch;
|
||||
pitch = 180 - pitch;
|
||||
}
|
||||
NSLog(@"BT data: %f %f %f: pitch %i, roll %i", ax , ay ,az, pitch, roll);
|
||||
if ( (++counter & 15) == 0)
|
||||
NSLog(@"BT data: %f %f %f: pitch %i, roll %i, yaw %i", ax , ay ,az, pitch, roll, theta);
|
||||
|
||||
#if 1
|
||||
// moving average of size SIZE
|
||||
static int pos = 0;
|
||||
static int historyRoll[SIZE];
|
||||
static int historyPitch[SIZE];
|
||||
static int historyTheta[SIZE];
|
||||
|
||||
historyRoll[pos] = roll;
|
||||
historyPitch[pos] = pitch;
|
||||
historyTheta[pos] = theta;
|
||||
pos++;
|
||||
if (pos==SIZE) pos = 0;
|
||||
|
||||
@ -88,9 +101,11 @@ static void bt_data_cb(uint8_t x, uint8_t y, uint8_t z){
|
||||
for (i=0;i<SIZE;i++){
|
||||
roll += historyRoll[i];
|
||||
pitch += historyPitch[i];
|
||||
theta += historyTheta[i];
|
||||
}
|
||||
roll = roll / SIZE;
|
||||
pitch = pitch / SIZE;
|
||||
theta = theta / SIZE;
|
||||
#endif
|
||||
[[theMainApp glView] setRotationX:-pitch Y:roll Z:0];
|
||||
}
|
||||
|
@ -94,6 +94,7 @@
|
||||
9C88500D0FBF6702004980E4 /* l2cap.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = l2cap.h; path = src/l2cap.h; sourceTree = "<group>"; };
|
||||
9C994B8E106BEEB700C70311 /* rfcomm.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = rfcomm.c; path = example/rfcomm.c; sourceTree = "<group>"; };
|
||||
9CA3C0900FB8B3C4005F48DE /* TODO.txt */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = TODO.txt; sourceTree = "<group>"; };
|
||||
9CBE154810A354FF00597802 /* package.sh */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text.script.sh; path = package.sh; sourceTree = "<group>"; };
|
||||
9CC152C61009052100223347 /* config.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
|
||||
9CC813A10FFC0774002816F9 /* btstack.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = btstack.c; path = src/btstack.c; sourceTree = "<group>"; };
|
||||
9CC813A40FFC0A51002816F9 /* daemon.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = daemon.c; path = src/daemon.c; sourceTree = "<group>"; };
|
||||
@ -131,6 +132,7 @@
|
||||
08FB7794FE84155DC02AAC07 /* project */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9CBE154810A354FF00597802 /* package.sh */,
|
||||
9CEB4B7510715DC200DD5720 /* include */,
|
||||
9C77E4AD10634E3100F39DCF /* 3rdparty */,
|
||||
9C78A049103C671D003B2950 /* Resources */,
|
||||
|
@ -141,7 +141,7 @@ void run_loop_set_timer(timer_t *a, int timeout_in_ms){
|
||||
// compare timers - NULL is assumed to be before the Big Bang
|
||||
// pre: 0 <= tv_usec < 1000000
|
||||
int run_loop_timeval_compare(struct timeval *a, struct timeval *b){
|
||||
if (!a || !b) return 0;
|
||||
if (!a && !b) return 0;
|
||||
if (!a) return -1;
|
||||
if (!b) return 1;
|
||||
|
||||
@ -166,7 +166,7 @@ int run_loop_timeval_compare(struct timeval *a, struct timeval *b){
|
||||
// compare timers - NULL is assumed to be before the Big Bang
|
||||
// pre: 0 <= tv_usec < 1000000
|
||||
int run_loop_timer_compare(timer_t *a, timer_t *b){
|
||||
if (!a || !b) return 0;
|
||||
if (!a && !b) return 0;
|
||||
if (!a) return -1;
|
||||
if (!b) return 1;
|
||||
return run_loop_timeval_compare(&a->timeout, &b->timeout);
|
||||
|
Loading…
x
Reference in New Issue
Block a user