Permalink
Browse files

Add log for Accelerometer messages.

  • Loading branch information...
myang committed Mar 17, 2012
1 parent 10e293a commit 4141ca07ebce0b8afc0fe0273460ed8e674321ac
Showing with 37 additions and 47 deletions.
  1. +2 −0 MWKit/MWMetaWatch.h
  2. +35 −47 MWKit/MWMetaWatch.m
View
@@ -43,6 +43,8 @@
#define kMSG_TYPE_LOW_BATTERY_BT_OFF_MESSAGE 0x55
#define kMSG_TYPE_READ_BATTERY_VOLTAGE_MESSAGE 0x56
#define kMSG_TYPE_READ_BATTERY_VOLATRE_RESPONSE 0x57
+#define kMSG_TYPE_ACCELEROMETER_HOST 0xe0
+
#define kMODE_IDLE 0x00
#define kMODE_APPLICATION 0x01
View
82 MWKit/MWMetaWatch.m 100644 → 100755
@@ -120,12 +120,41 @@ -(void)connectionControllerDidCloseChannel:(MWConnectionController *)controller
[[NSNotificationCenter defaultCenter]postNotificationName:MWKitDidCloseChannelNotification object:nil];
}
--(void)connectionController:(MWConnectionController *)controller didReceiveData:(NSData *)data {
- const char* dataBytes = [data bytes];
- [self didReceiveData:dataBytes];
+-(void)connectionController:(MWConnectionController *)controller didReceiveData:(NSData *)dataObj {
+ const unsigned char* data = [dataObj bytes];
+ const unsigned char msgType = data[2];
+ NSLog(@"+++ didReceiveData: %02x length: %lu\n",data[2], [dataObj length]);
+
+ if (msgType==kMSG_TYPE_GET_DEVICE_TYPE_RESPONSE) {
+ NSLog(@"+++ Get device type response");
+ } else if (msgType==kMSG_TYPE_GET_INFORMATION_TYPE_RESPONSE) {
+ NSLog(@"+++ Get info type response");
+ } else if (msgType==kMSG_TYPE_GET_RTC_RESPONSE) {
+ NSLog(@"+++ Get RTC response");
+ } else if (msgType==kMSG_TYPE_STATUS_CHANGE_EVENT) {
+
+ } else if (msgType==kMSG_TYPE_BUTTON_EVENT_MESSAGE) {
+ self.logString = [self.logString stringByAppendingFormat:@"BUtton %@ pressed. \n",[NSNumber numberWithChar:data[4]]];
+ [[NSNotificationCenter defaultCenter]postNotificationName:MWKitDidReceivePuttonPress object:[NSNumber numberWithChar:data[4]]];
+ }else if (msgType==kMSG_TYPE_LOW_BATTERY_BT_OFF_MESSAGE) {
+
+ }else if (msgType==kMSG_TYPE_LOW_BATTERY_WARNING_MESSAGE) {
+
+ }else if (msgType==kMSG_TYPE_READ_BATTERY_VOLATRE_RESPONSE) {
+ NSNumber *voltage = [NSNumber numberWithChar:data[0]];
+ NSLog(@"didget Voltage:%@ ", voltage);
+ } else if (msgType == kMSG_TYPE_ACCELEROMETER_HOST) {
+ self.logString = @"";
+ for (int i = 0; i < [dataObj length]; i++) {
+ self.logString = [self.logString stringByAppendingFormat:@"%02x ",data[i]];
+ }
+ //self.logString = [self.logString stringByAppendingFormat:@"\n"];
+ NSLog(@"Accelerometer data: %@", self.logString);
+ }
+
+ [[NSNotificationCenter defaultCenter]postNotificationName:MWKitDidReceiveData object:nil];
}
-
//-(void)didOpenChannel {
//
//
@@ -142,48 +171,6 @@ -(void)connectionController:(MWConnectionController *)controller didReceiveData:
//
//}
--(void)didReceiveData:(const char*)data {
-
- const char msgType = data[2];
-
- if (msgType==kMSG_TYPE_GET_DEVICE_TYPE_RESPONSE) {
-
- }else if (msgType==kMSG_TYPE_GET_INFORMATION_TYPE_RESPONSE) {
-
- }else if (msgType==kMSG_TYPE_GET_RTC_RESPONSE) {
-
- }else if (msgType==kMSG_TYPE_STATUS_CHANGE_EVENT) {
-
- }else if (msgType==kMSG_TYPE_BUTTON_EVENT_MESSAGE) {
- self.logString = [self.logString stringByAppendingFormat:@"Button %@ pressed. \n",[NSNumber numberWithChar:data[4]]];
- [[NSNotificationCenter defaultCenter]postNotificationName:MWKitDidReceivePuttonPress object:[NSNumber numberWithChar:data[4]]];
- }else if (msgType==kMSG_TYPE_LOW_BATTERY_BT_OFF_MESSAGE) {
-
- }else if (msgType==kMSG_TYPE_LOW_BATTERY_WARNING_MESSAGE) {
-
- }else if (msgType==kMSG_TYPE_READ_BATTERY_VOLATRE_RESPONSE) {
- NSNumber *voltage = [NSNumber numberWithChar:data[0]];
- NSLog(@"didget Voltage:%@ ", voltage);
- }
-
- int i =0;
- for (i=0; i<(sizeof(data)/sizeof(unsigned char)); i++) {
- NSLog(@"%02x",data[i]);
- self.logString = [self.logString stringByAppendingFormat:@"%02x ",data[i]];
- }
- self.logString = [self.logString stringByAppendingFormat:@"\n"];
- [[NSNotificationCenter defaultCenter]postNotificationName:MWKitDidReceiveData object:nil];
-
-
-}
-
-
-
-
-
-
-
-
@@ -282,6 +269,7 @@ -(void)writeNotification:(NSString*)title withContent:(NSString*)text fromSource
}
-(void)writeIdleScreenWithData:(NSMutableDictionary*)dataDict {
+ [self setRTC];
NSData *data = [MWImageTools imageDataForHomeScreen:dataDict];
[self writeImage:data forMode:kMODE_IDLE];
}
@@ -328,7 +316,7 @@ -(void)writeBuffer:(unsigned char)mode row:(unsigned char)row data:(unsigned cha
memset(data, 0,12);
data[0]=row;
memcpy((data+1), inputData, 12);
- int i=0;
+// int i=0;
// for ( i=0; i<13;i++) {
// // NSLog(@"i:%i 0x%2x",i, data[i]);
// }

0 comments on commit 4141ca0

Please sign in to comment.