Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit bd50080c3362ff36a5b1ac5393c90b8fc34b449f Gregoire Tronel committed Apr 23, 2012
Showing 737 changed files with 137,667 additions and 0 deletions.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 0
+
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 0
+
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 0
+
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 0
+
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 0
+
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 1
+*
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 0
+
+END
@@ -0,0 +1,5 @@
+K 14
+svn:executable
+V 0
+
+END
@@ -0,0 +1,42 @@
+//
+// HelloWorldLayer.h
+// HelloWorldcocos2D
+//
+// Created by Gregoire Tronel on 10/7/11.
+// Copyright __MyCompanyName__ 2011. All rights reserved.
+//
+
+
+// When you import this file, you import all the cocos2d classes
+#import "cocos2d.h"
+#import "TokClock.h"
+
+
+// HelloWorldLayer
+@interface Accelerometer : NSObject <UIAccelerometerDelegate>
+{
+ float frameRate;
+ int numTapped;
+ BOOL air;
+ float kFilteringFactor;
+
+ CCLayer * delegate;
+
+
+ UIAccelerationValue accelX;
+ UIAccelerationValue accelY;
+ UIAccelerationValue accelZ;
+
+ UIAccelerationValue rawAccelX;
+ UIAccelerationValue rawAccelY;
+ UIAccelerationValue rawAccelZ;
+ BOOL calibrated;
+}
+
+
+
+// returns a CCScene that contains the HelloWorldLayer as the only child
+-(void) smoothAccelerometerData;
+-(id) initWithDelegate : (CCLayer *) layer;
+
+@end
@@ -0,0 +1,141 @@
+#import "Accelerometer.h"
+
+@implementation Accelerometer
+
+#define STATE1 YES
+#define STATE2 NO
+#define kFilteringFactor 0.5
+
+BOOL AIR = NO;
+BOOL previousState = STATE1;
+
+BOOL debounceFlag = YES;
+float dt = 1.0f / 60.0f;
+int c = 0;
+double sumX=0, sumY=0, sumZ=0;
+double calibX, calibY, calibZ;
+double thresh = 0.01;
+double count = 0;
+int countFrame = 0;
+
+
+-(id) initWithDelegate : (CCLayer *) layer
+{
+ self = [super init];
+
+ // always call "super" init
+ // Apple recommends to re-assign "self" with the "super" return value
+ if( self) {
+ calibrated = YES; // by setting calibrated = NO ,it will start calibation
+ delegate = layer;
+ frameRate = dt;
+ numTapped = 0;
+ air = NO;
+ UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer];
+ accel.delegate = self;
+ accel.updateInterval = frameRate;
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(statCalibrate:)
+ name:@"start_calibration"
+ object:nil ] ;
+ }
+ return self;
+
+}
+
+-(void) statCalibrate: (NSNotification *) notification{
+ calibrated =NO;
+ NSLog(@"calibration will start soon!");
+}
+
+- (void) accelerometer: (UIAccelerometer *) accelerometer didAccelerate: (UIAcceleration *) acceleration
+{
+
+ countFrame++;
+ if (countFrame > 10)
+ debounceFlag = YES;
+
+//CALIBRATION
+ accelX = 0.0;
+ accelY = 0.0;
+ accelZ = 0.0;
+ if ( calibrated == NO ){
+
+ if ( fabs(rawAccelX - acceleration.x) >= thresh || fabs(rawAccelY - acceleration.y) >= thresh || fabs(rawAccelZ - acceleration.z) >= thresh )
+ {
+ // init calibration
+ sumX = sumY = sumZ = 0;
+ count = 0;
+ }
+ count++;
+ sumX += acceleration.x;
+ sumY += acceleration.y;
+ sumZ += acceleration.z;
+ if (count == 30){
+ calibX = sumX/count;
+ calibY = sumY/count;
+ calibZ = sumZ/count;
+ calibrated = YES;
+ NSLog(@"%f\t %f\t %f", calibX, calibY, calibZ);
+ //startTime = [[NSDate date] timeIntervalSince1970];
+ NSLog(@"calibration finished!");
+ }
+ }
+
+ rawAccelX = acceleration.x;
+ rawAccelY = acceleration.y;
+ rawAccelZ = acceleration.z;
+
+ accelX = rawAccelX * kFilteringFactor + accelX * (1.0 - kFilteringFactor);
+ accelY = rawAccelY * kFilteringFactor + accelY * (1.0 - kFilteringFactor);
+ accelZ = rawAccelZ * kFilteringFactor + accelZ * (1.0 - kFilteringFactor);
+ [self smoothAccelerometerData];
+
+}
+
+int k = 0;
+int averageCount = 5;
+int q = 0;
+double arr[5] = {0};
+UIAccelerationValue points[480] = {0};
+
+
+-(void) smoothAccelerometerData{
+
+ double threshold = 0.03;
+
+ double sum = 0;
+ BOOL currentState = STATE1;
+ arr[q] = rawAccelY;
+
+ for ( int j=0; j < averageCount; j++)
+ sum += arr[j];
+
+ double avg = sum/averageCount;
+ if (avg >= calibY + threshold || avg <= calibY - threshold){
+ currentState = STATE2;
+ }
+ if (previousState == STATE2 && currentState == STATE1 && debounceFlag)
+ {
+ c++;
+ debounceFlag = NO;
+ countFrame = 0;
+ [[TokClock sharedClock] computeAccuracy];
+ }
+
+ NSString * string2 = [NSString stringWithFormat:@"%i", c];
+ previousState = currentState;
+
+ q++;
+ q=q%averageCount;
+}
+
+
+// on "dealloc" you need to release all your retained objects
+- (void) dealloc
+{
+
+ [super dealloc];
+}
+@end
@@ -0,0 +1,47 @@
+//
+// Bluetooth.h
+// tok
+//
+// Created by Sang Won Lee on 10/21/11.
+// Copyright 2011 Stanford. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <GameKit/GameKit.h>
+#import "cocos2d.h"
+#import "Environment.h"
+#import "TokClock.h"
+//#import "tokAppDelegate.h"
+
+
+@interface Bluetooth : NSObject<GKSessionDelegate> {
+
+ GKSession * currentSession;
+ NSString * mySelfPeerID;
+ NSMutableDictionary * peerList;
+ NSMutableDictionary * connectedPeerList;
+ BOOL master;
+ int syncState; // 1 = Not called by master; 2 = already called by master; 0 = On call right now.
+ int TotalPeers;
+ int TotalPeersSynced;
+ NSMutableArray * connectedPeerArray;
+}
+
+@property (retain, nonatomic) NSMutableDictionary * peerList;
+@property (retain, nonatomic) NSMutableDictionary * connectedPeerList;
+@property int syncState;
+
++(Bluetooth *) sharedInstance;
+-(NSMutableDictionary *) searchPeers;
+-(void) connectWithPeer: (NSString *) peerID;
+-(void) startSync;
+-(void) sendMessage:(NSString *) msgID withDataArray:(NSArray*) Data;
+-(void) sendMessage:(NSString *) msgID withData:(NSString*) Data;
+-(NSTimeInterval) sendSyncMessage:(NSString *) msgID;
+-(void) sendSyncMessage;
+-(void) syncDone;
+-(void) sendRemoveCoinAt:(GridPoint)point;
+-(void) sendAddCoinTo:(GridPoint) destination;
+-(void) sendMoveCoinFrom:(GridPoint) source To: (GridPoint) destination;
+
+@end
Oops, something went wrong.

0 comments on commit bd50080

Please sign in to comment.