Home User CP Donate Chat Register Today!  
  Get New posts Faq / Help?
   


Go Back   Hackint0sh > Projects and Hacks > iPhone > Applications & Development > iPhone Developer Exchange

Reply
 
LinkBack Thread Tools Display Modes
  #21 (permalink)  
Old 06-13-2008, 12:31 PM
javacom's Avatar
javacom
Status: Offline
Developer
 
Join Date: Mar 2008
Posts: 304
Rep Power: 23
javacom will become famous soon enoughjavacom will become famous soon enough
Default HelloSensor.app for SDK API

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;
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #22 (permalink)  
Old 06-19-2008, 12:07 PM
javacom's Avatar
javacom
Status: Offline
Developer
 
Join Date: Mar 2008
Posts: 304
Rep Power: 23
javacom will become famous soon enoughjavacom will become famous soon enough
Default Interface Builder for Open Toolchain Template

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
For this sample app, it is possible to add the UISearchBar in this and this works very well. Please refer to here for the required code amendment.

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #23 (permalink)  
Old 07-11-2008, 11:13 AM
zebrum
Status: Offline
Senior Member
 
Join Date: Mar 2007
Posts: 147
Rep Power: 0
zebrum is an unknown quantity at this point
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Sponsored links Remove advertisements
Advertisement
Advertisement

  #24 (permalink)  
Old 07-11-2008, 04:34 PM
javacom's Avatar
javacom
Status: Offline
Developer
 
Join Date: Mar 2008
Posts: 304
Rep Power: 23
javacom will become famous soon enoughjavacom will become famous soon enough
Default

It is very likely that the dev team will update the toolchain and gcc compiler after jailbreak the firmware 2.0, as you can see there are Cydia, Installer, BootNeuter in their jailbroken iPhone.

If iTunes 7.7 breaks the deployment, we might need to wait for the update from dev team.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #25 (permalink)  
Old 07-13-2008, 08:20 PM
Kingstone
Status: Offline
Junior Member
 
Join Date: Jan 2008
Posts: 3
Rep Power: 0
Kingstone is on a distinguished road
Default

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...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #26 (permalink)  
Old 07-14-2008, 05:33 AM
javacom's Avatar
javacom
Status: Offline
Developer
 
Join Date: Mar 2008
Posts: 304
Rep Power: 23
javacom will become famous soon enoughjavacom will become famous soon enough
Default

Quote:
Originally Posted by Kingstone View Post
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...
I think most of us want to have one source code compiled for both open toolchain header and official sdk header. At present, I only use conditional compiler directive #ifdef #else #endif. But it is only for UIKit headers only.

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Sponsored links Remove advertisements
Advertisement
Advertisement

  #27 (permalink)  
Old 07-17-2008, 07:36 PM
itouchhak0r
Status: Offline
Junior Member
 
Join Date: Apr 2008
Posts: 3
Rep Power: 0
itouchhak0r is on a distinguished road
Default debugging code

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #28 (permalink)  
Old 07-17-2008, 07:36 PM
Kingstone
Status: Offline
Junior Member
 
Join Date: Jan 2008
Posts: 3
Rep Power: 0
Kingstone is on a distinguished road
Default

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...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #29 (permalink)  
Old 07-18-2008, 05:47 AM
javacom's Avatar
javacom
Status: Offline
Developer
 
Join Date: Mar 2008
Posts: 304
Rep Power: 23
javacom will become famous soon enoughjavacom will become famous soon enough
Default

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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Sponsored links Remove advertisements
Advertisement
Advertisement

  #30 (permalink)  
Old 07-20-2008, 05:56 PM
zebrum
Status: Offline
Senior Member
 
Join Date: Mar 2007
Posts: 147
Rep Power: 0
zebrum is an unknown quantity at this point
Default

Any chance of an update to the template for the final sdk? Also please could you add in IOKit framework support? It has the extremely necessary power management functions.

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +2. The time now is 04:25 PM.



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2 Ad Management by RedTyger
follow us on Twitter!

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105