|
|||||||||
|
|||||||||
|
||||
|
I have been asked whether the UIAccelerometer code of HelloSensor.app (post 13) can be run on SDK API or not ?
So here this is the modified version (with 3 files below) for the iPhone SDK API. And I have tested this on the SDK beta 3. The original version that run in firmware 1.x with open toolchain API is from Erica Sadun. Code:
//
// main.m
// SensorSDK3
//
#import <UIKit/UIKit.h>
int main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"SensorSDK3AppDelegate");
[pool release];
return retVal;
}
Code:
//
// SensorSDK3AppDelegate.h
// SensorSDK3
//
#import <UIKit/UIKit.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#define kUpdateFrequency 10 // Hz
@interface SensorSDK3AppDelegate : NSObject <UIAccelerometerDelegate> {
UIWindow *window;
UITextView *textView;
UIImageView *xarrow;
}
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) UITextView *textView;
@property (nonatomic, retain) UIImageView *xarrow;
- (void)acceleratedInX:(float)xx Y:(float)yy Z:(float)zz;
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration;
@end
Code:
//
// SensorSDK3AppDelegate.m
// SensorSDK3
//
#import "SensorSDK3AppDelegate.h"
UIImage *createImageWithText(CGSize imageSize, NSString *text);
@implementation SensorSDK3AppDelegate
@synthesize window;
@synthesize textView;
@synthesize xarrow;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.textView = [[UITextView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]];
self.textView.font = [UIFont systemFontOfSize:24];
self.textView.editable = NO;
self.textView.textAlignment = UITextAlignmentLeft;
UIImage *img = createImageWithText(CGSizeMake(85,40),@"-->");
self.xarrow = [[UIImageView alloc] initWithImage:img];
self.xarrow.center=self.textView.center;
self.xarrow.clearsContextBeforeDrawing = NO;
[textView addSubview:xarrow];
// Show window
[window addSubview:textView];
[window makeKeyAndVisible];
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(20.0 / kUpdateFrequency)];
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
}
/*
The meaning of X, Y, Z by Erica Sadun (with modification for the range from -1.0 to 1.0 for firmware 2.0)
X = Roll X corresponds to roll, or rotation around the axis that runs from your home button to your earpiece.
Values vary from 1.0 (rolled all the way to the left) to -1.0 (rolled all the way to the right).
Y = Pitch. Place your iPhone on the table and mentally draw a horizontal line about half-way down the screen.
That's the axis around which the Y value rotates.
Values go from 1.0 (the headphone jack straight down) to -1.0 (the headphone jack straight up).
Z = Face up/face down. I expected the Z value to correspond to yaw. And it does not.
It refers to whether your iPhone is face up (-1.0) or face down (1.0).
When placed on it side, either the side with the volume controls and ringer switch, or the side directly opposite
, the Z value equates to 0.0.
*/
- (void)acceleratedInX:(float)xx Y:(float)yy Z:(float)zz
{
// Create Status feedback string
NSString *xstring = [NSString stringWithFormat:
@"X (roll, %4.1f%%): %f\nY (pitch %4.1f%%): %f\nZ (%4.1f%%) : %f",
100.0 - (xx + 1.0) * 100.0, xx,
100.0 - (yy + 1.0) * 100.0, yy,
100.0 - (zz + 1.0) * 100.0, zz
];
self.textView.text = xstring;
// Revert Arrow and then rotate to new coords
float angle = atan2(xx, yy);
angle += M_PI / 2.0;
CGAffineTransform affineTransform = CGAffineTransformIdentity;
affineTransform = CGAffineTransformConcat( affineTransform, CGAffineTransformMakeRotation(angle));
self.xarrow.transform = affineTransform;
}
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
[self acceleratedInX:acceleration.x Y:acceleration.y Z:acceleration.z];
}
- (void)dealloc {
[textView release];
[xarrow release];
[window release];
[super dealloc];
}
@end
// Returns an image of the given size containing the given string
UIImage *createImageWithText(CGSize imageSize, NSString *text) {
// Create a bitmap graphics context of the given size
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, imageSize.width, imageSize.height, 8, imageSize.width*4, colorSpace, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
if (context== NULL) {
return nil;
}
// Custom CGContext coordinate system is flipped with respect to UIView, so transform, then push
CGContextTranslateCTM(context, 0, imageSize.height);
CGContextScaleCTM(context, 1.0, -1.0);
UIGraphicsPushContext(context);
// Inset the text rect then draw the text
CGRect textRect = CGRectMake(4, 2, imageSize.width - 8, imageSize.height - 8);
UIFont *font = [UIFont boldSystemFontOfSize:24];
[[UIColor blackColor] set];
[text drawInRect:textRect withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];
// Create and return the UIImage object
CGImageRef cgImage = CGBitmapContextCreateImage(context);
UIImage *uiImage = [[UIImage alloc] initWithCGImage:cgImage];
UIGraphicsPopContext();
CGContextRelease(context);
CGImageRelease(cgImage);
return uiImage;
}
|
|
||||
|
Interface Builder for Open Toolchain Template
Some of sample applications from SDK have used Interface Builder file (*.xib) in the project. In order to use the IB file, the local UIKit.h header is enhanced and a new Xcode template is created. It is called "Window-Based Toolchain" and is added to the first post Xcode template of this thread. The MainWindow.xib of this template has only one window as IBOutlet. I have tested this new Window-Based Toolchain template to build the SimpleTableViewApp of SDK3 and in order to build under open toolchain header, the sample code of this app should be amended as below Code:
#ifdef ASPEN
#import "UIKit.h"
#import "SimpleTableViewAppDelegate.h"
#else
#import <UIKit/UIKit.h>
#endif
int main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
#ifdef ASPEN
int retVal = UIApplicationMain(argc, argv, [SimpleTableViewAppDelegate class]);
#else
int retVal = UIApplicationMain(argc, argv, nil, @"SimpleTableViewAppDelegate");
#endif
[pool release];
return retVal;
}
Code:
/*
File: SimpleTableViewAppDelegate.h
*/
#ifdef ASPEN
#import "UIKit.h"
#else
#import <UIKit/UIKit.h>
#endif
#import "RootViewController.h"
#ifdef ASPEN
@interface SimpleTableViewAppDelegate : UIApplication <UITextFieldDelegate, UISearchBarDelegate>
#else
@interface SimpleTableViewAppDelegate : NSObject <UIApplicationDelegate,UITextFieldDelegate, UISearchBarDelegate>
#endif
{
IBOutlet UIWindow *window;
UINavigationController *navigationController;
NSMutableArray *list;
}
Code:
/* File: RootViewController.h */ #ifdef ASPEN #import "UIKit.h" #else #import <UIKit/UIKit.h> #endif There is also a Makefile in the xcode template, so that you can compile the xib to nib file and package it and manual install to /Applications folder of iPhone by scp, in addition to "build and go" in Xcode environment. To get the updated version "UIKit.h" and Makefile, you can install the version 2.1 of the Xcode Template Please refer to the first post on how to install this Xcode Template This Xcode template has been tested on pwned iPhone (build 5a240d) and iPhone SDK beta 3
Last edited by javacom; 06-19-2008 at 04:29 PM. |
|
|||
|
It appears Itunes 7.7 breaks the ability to deploy to a beta 3 iphone. Xcode reports the error "No provisioned iPhone OS device is connected." The Organizer won't detect it either.
|
| Sponsored links Remove advertisements | |
|
|
|
|
|
|||
|
Hi javacom,
Nice stuff, works good. I have one question. When there will be jailbreak for official 2.0, how will i compile apps i compiled for beta 3 using your method? Will it work? you use toolchain headers in this special way. will it be possible to compile using those headers for official 2.0? I'm just afraid i'll have to change all my code in the end just to compile for official 2.0... |
|
||||
|
Quote:
We will have to wait for the upgrade of the open toolchain headers to see what can be done. The dev team is the expert on this. |
| Sponsored links Remove advertisements | |
|
|
|
|
|
|||
|
I'm trying to compile an app using the open toolchain.
I've found that you need to use erica sadun's utility "launch" to run the program going into the Applications/yourApp.app directory and running ./yourApp doesn't work any more. I've got NSLog statements in my code but when I ssh into the iphone and "launch" the program I don't see the messages displayed. I'm trying to debug my code as I go.. Have others experienced this? thanks |
|
|||
|
I'm trying to port a 1.1.4 application i've made to 2.0 using your xcode patch/template.
Well I got it to compile but when I run it, it gets stuck in UIApplicationMain... It never reaches appDidFinishLaunching method in my app controller class... I'm not sure but could it be because i use .mm for my app controller class? (i use c++ code and other external classes) It's weird the whole program compiled fine... |
|
||||
|
I do not code c++ / objective c++, so I have nothing to comment on this.
But I think we all need to wait for pwnage tools and the upgrade of toolchain from the dev team in order to port app to firmware 2.0 (not beta) |
| Sponsored links Remove advertisements | |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|