I have coded an App that can convert normal Text like : "Hello my Name is XY"
into points and strokes ( ..-. ; --.- ; . ; - ; etc etc)
Now I want to Convert these points and stroke into light flashes with the lenght of 0.3 sec for points an 0.6 seconds for strokes. also there is a pause with the length of a point after each point or stroke, a double pause after each Word, and a tripple pause/break after each sentences.
The breaks are also implied into my code.
The problem is now that the light strokes aren't different enough.
Because the Idea behind it is to convert the Light flashes via an Arduino Duo and a fototransistor back to Text.
Here is the Code Passage for the Light converting Process:
- (IBAction)send:(id)sender{
// Converting Text to morsecode etc
float needTime;
NSString *string = plotter;
for (int d = 0;d < [string length]; d++) {
NSString *punktoderstrich = [string substringWithRange:NSMakeRange(d, 1)];
if ([punktoderstrich isEqualToString:#"."]) {
needTime = needTime + 0.4f;
[self performSelector:#selector(playpunkt) withObject:nil afterDelay:needTime];
}
if ([punktoderstrich isEqualToString:#"-"]) {
needTime = needTime + 1.0f;
[self performSelector:#selector(playstrich) withObject:nil afterDelay:needTime];
}
if ([punktoderstrich isEqualToString:#" "]) {
needTime = needTime + 0.4f;
[self performSelector:#selector(playpause) withObject:nil afterDelay:needTime];
}
if ([punktoderstrich isEqualToString:#"/"]) {
needTime = needTime + 0.3f;
[self performSelector:#selector(playpause) withObject:nil afterDelay:needTime];
}
}
- (void)torchAn {
[captureDevice lockForConfiguration:nil];
[captureDevice setTorchMode:AVCaptureTorchModeOn];
[captureDevice setFlashMode:AVCaptureFlashModeOn];
[captureDevice unlockForConfiguration];
}
- (void)torchAus {
[captureDevice lockForConfiguration:nil];
[captureDevice setTorchMode:AVCaptureTorchModeOff];
[captureDevice setFlashMode:AVCaptureFlashModeOff];
[captureDevice unlockForConfiguration];
}
-(void)playstrich{
// AudioServicesPlaySystemSound (outSystemSoundID2);
[self torchAn];
//[self performSelector:#selector(torchAus) withObject:nil afterDelay:0.8f];
}
-(void)playpunkt{
//AudioServicesPlaySystemSound (outSystemSoundID1);
[self torchAn];
//[self performSelector:#selector(torchAus) withObject:nil afterDelay:0.4f];
}
- (void)playpause{
// AudioServicesPlaySystemSound (outSystemSoundID3);
[self performSelector:#selector(torchAus) /*withObject:nil afterDelay:0.4f*/];
}
Like You see I also imported sound files (short and Long) but the Main target is to give a right light signal out.
My Problems:
Short lights are mostly okay, exept the first when the LED is firstly flashing.
Long light signals aren't really longer. Sometimes I get equal results when I'm recording them.
And after a Long light should light up the following short ones aren't short as normal.. hm..
After I had commented the Part with the sounds out, the whole process became more stable.
I also moved the Part (turning LED OFF) from the sign it self to the breaks.
I hope somebody can give me some tipps or so :)
Greets from Germany!
P.S.: My divice is an iPhone 4s (with torch ^^)
Like Brad said the iPhone flash needs a few ms to turn on. If you still want to use it the only possibility would be (in my eyes) to change your protocol and give the single signals more time.
This slows down your transmission but on the receiver-side you could define some confidence intervals (like plus-minus 2 seconds). Maybe a human beeing would not understand your morse code because it could be too slow (but maybe they will), a machine like the iPhone as a receiver would be perfectly able to understand it.
You have to play around with the time intervals to find the shortest ones that are working.
Greetings from GER.
Related
I've been getting FPS lag. I've looked around and people say to use
[self schedule:#selector(gameLoop:) interval: 1/60.0f];
When I use this I get choppy lag. but when I use
[self schedule:#selector(gameLoop:)];
It's a lot smoother. Here is a snippet of my movement code.
- (void)gameLoop :(ccTime)dt
{
[self manageCannon:dt];
[self manageBullets:dt];
[self manageEnemies:dt];
[self manageAllies:dt];
}
- (void) manageEnemies :(ccTime)dt
{
enemyClass *tempEnemy;
for(int i = 0; i < [enemies count]; i++)
{
tempEnemy = [enemyClass new];
tempEnemy = [enemies objectAtIndex:i];
tempEnemy.position = ccp(tempEnemy.position.x-tempEnemy.speed*dt,tempEnemy.position.y);
if((tempEnemy.position.x - tempEnemy.range) < [wall getwally])
{
tempEnemy.speed = 0;
}
if(tempEnemy.health < 1)
{
tempEnemy.alive = false;
}
if(tempEnemy.alive == false)
{
[enemies removeObjectAtIndex:i];
[tempEnemy removeFromParentAndCleanup:true];
}
}
}
I always try to write my own code from scratch, so if you can help me out with other things that i'm doing that is incorrect that would be very helpful towards me.
It's hard to say what is slowing down your app from the information given. As LearnCocos2D suggested, you can use Instruments to figure out where the slow stuff is. Or if you want to get very granular analysis, you can always use the following macros in your code:
#define TIC start = [NSDate date]
#define TOC -[start timeIntervalSinceNow]
#define TOCP NSLog(#"TIME: %f", TOC)
Before using, be sure to declare NSDate *start in scope of use. Then just put a series of TIC/TOC or TIC/TOCP pairs in your code to print out times your code is taking in different places. You can very quickly find the bottlenecks this way.
So, I'm writing a very simple real time game center 2-player game; however, the problem is I keep getting disconnected.
The game works as follows: Each player has a text field on their device. They each enter text in the field and press enter. When both people have inputted text, the game progresses.
Now, when the users are actively playing the game (inputting text every 10 seconds or so), the game works just fine and a user has never been disconnected. However, when the game remains inactive (the user just sits and stares at the app screen) for about 30 seconds or more, at least one player gets disconnected.
I'm pretty confident that my Internet is solid and both devices appear to be connected to the Internet (via wifi).
I know this is a very vague question, I was just wondering if anyone has any ideas related to the symptoms in bold above.
EDIT:
Here's how I initialize the matchrequest and the match. However, I'm having no trouble initializing or starting the match. The only problem is when a player goes idle for some length of time
//toInvite may be nil
- (void) createMatchWithPlayersToInvite: (NSArray *) toInvite
{
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;
request.playersToInvite = toInvite;
GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithMatchRequest:request];
self.myMatchmakerVC = mmvc;
mmvc.hosted = NO;
mmvc.matchmakerDelegate = self;
[self presentViewController:mmvc animated:YES completion:nil];
}
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
{
[self dismissViewControllerAnimated:YES completion:nil];
self.myMatch = match;
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.currentMatch = self.myMatch;
if (!self.matchStarted && match.expectedPlayerCount == 0)
{
self.matchStarted = YES;
[self performSegueWithIdentifier:#"gameSegue" sender:self];
}
}
EDIT 2:
So, I've discovered that if I set a timer and send messages across the network (with [self.myMatch sendDataToAllPlayers:data withDataMode:GKMatchSendDataReliable error:&error]) every 1 second, the program works just fine. Does anyone have idea why this is or how I can fix my issue without resorting to a hacked together NSTimer?
Other notes:
1) My AppDelegate has not been changed
Looks like you have a clear hypothesis here, i.e. that Game Center connections are closed after 30 seconds idle time. I would not be surprised if this is the case. Other games almost certainly will send data within such an interval, and you may be triggering a timeout condition. To test this hypothesis and fix the problem at the same time, I would send a short blind text every five or ten seconds.
Has anyone been able to get the iPhone 5's new low light boost mode to work in their custom camera app? I tried the following code, but noticed no difference - whereas the native camera app significantly boosted the brightness.
if ([[captureManager backFacingCamera] isLowLightBoostEnabled]) {
[[captureManager backFacingCamera] automaticallyEnablesLowLightBoostWhenAvailable];
}
You need to lockForConfiguration, according to the docs (well, the header file):
if ([[self backFacingCamera] respondsToSelector:#selector(isLowLightBoostSupported)]) {
if ([[self backFacingCamera] lockForConfiguration:nil]) {
if ([self backFacingCamera].isLowLightBoostSupported)
[self backFacingCamera].automaticallyEnablesLowLightBoostWhenAvailable = YES;
[[self backFacingCamera] unlockForConfiguration];
}
}
Also, isLowLightBoostEnabled tells you whether or not the low light is actually being boosted, not whether it can be. That's the isLowLightBoostSupported selector, as above (to which only iOS 6 devices respond).
I am trying hard to emulate the basic functionality of the built in camera app. Thus far I have become stuck on the 'tap to focus' feature.
I have a UIView from which I am collecting UITouch events when a single finger is tapped on the UIView. This following method is called but the camera focus & the exposure are unchanged.
-(void)handleFocus:(UITouch*)touch
{
if( [camera lockForConfiguration:nil] )
{
CGPoint location = [touch locationInView:cameraView];
if( [camera isFocusPointOfInterestSupported] )
camera.focusPointOfInterest = location;
if( [camera isExposurePointOfInterestSupported] )
camera.exposurePointOfInterest = location;
[camera unlockForConfiguration];
[cameraView animFocus:location];
}
}
'camera' is my AVCaptureDevice & it is non-nil. Can someone perhaps tell me where I am going wrong?
Clues & boos all welcome.
M.
This snippet might help you...There is a CamDemo provided by apple floating around which allows you to focus, change exposure while tapping, set flash, swap cameras and more, it emulates the camera app pretty well, not sure if youll be able to find it since it was part of wwdc, but if u leave some email address in the comments i can email you the sample code...
- (void) focusAtPoint:(CGPoint)point
{
AVCaptureDevice *device = [[self videoInput] device];
if ([device isFocusPointOfInterestSupported] && [device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {
NSError *error;
if ([device lockForConfiguration:&error]) {
[device setFocusPointOfInterest:point];
[device setFocusMode:AVCaptureFocusModeAutoFocus];
[device unlockForConfiguration];
} else {
id delegate = [self delegate];
if ([delegate respondsToSelector:#selector(acquiringDeviceLockFailedWithError:)]) {
[delegate acquiringDeviceLockFailedWithError:error];
}
}
}
}
I am looking to persistently display a game score in an iPhone app using cocos2d. Going off the code that cocos2d shows the FPS the app is running at:
-(void) showFPS
{
frames++;
accumDt += dt;
if ( accumDt > 0.1) {
frameRate = frames/accumDt;
frames = 0;
accumDt = 0;
}
NSString *str = [NSString stringWithFormat:#"%.1f",frameRate];
[FPSLabel setString:str];
[FPSLabel draw];
}
I can get the score to display properly, but it flickers, even though the app is running at faster that 60 FPS... Any ideas?
For anyone who might be interested, I ended up using a cocos2d Label as so:
scoreLabel = [Label labelWithString: [NSString stringWithFormat:#"%d", score] dimensions: CGSizeMake(180, 20) alignment: UITextAlignmentRight fontName:#"Arial" fontSize: 20];
[scoreLabel setPosition: cpv(100,100)];
[self add: scoreLabel];
Hopefully this can help someone else.
Try using LabelAtlas instead. It is faster (it consumes much less CPU).
See the AtlasDemo that comes with the cocos2d distribution to see how to use it.