This repository has been archived by the owner on Apr 18, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
John Boiles
committed
Oct 14, 2010
1 parent
eca49bb
commit 10611ae
Showing
20 changed files
with
1,017 additions
and
20 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,6 @@ | |
#import "KBUserView.h" | ||
#import "KBChalkLabel.h" | ||
|
||
|
||
@class KBApplicationDelegate; | ||
|
||
/*! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// KBFlowIndicator.h | ||
// | ||
// Created by John Boiles on 10/13/10. | ||
// Copyright 2010 Yelp. All rights reserved. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
@interface KBFlowIndicator : UIView { | ||
UIImageView *needleView_; | ||
UIImageView *fillView_; | ||
UILabel *volumeLabel_; | ||
UILabel *flowLabel_; | ||
|
||
double _minimumFlowRate; | ||
double _maximumFlowRate; | ||
double _minimumAngle; | ||
double _maximumAngle; | ||
double _flowRate; | ||
|
||
double _minimumVolume; | ||
double _maximumVolume; | ||
double _minimumTopY; | ||
double _maximumTopY; | ||
double _volume; | ||
|
||
NSTimer *_simulationTimer; | ||
BOOL _simulatedValueIncreasing; | ||
} | ||
|
||
@property (nonatomic, retain) IBOutlet UIImageView *needleView; | ||
@property (nonatomic, retain) IBOutlet UIImageView *fillView; | ||
@property (nonatomic, retain) IBOutlet UILabel *volumeLabel; | ||
@property (nonatomic, retain) IBOutlet UILabel *flowLabel; | ||
|
||
- (void)setFlowRate:(double)flowRate animated:(BOOL)animated; | ||
|
||
- (void)setVolume:(double)volume animated:(BOOL)animated; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// | ||
// KBFlowIndicator.m | ||
// | ||
// Created by John Boiles on 10/13/10. | ||
// Copyright 2010 Yelp. All rights reserved. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
#import "KBFlowIndicator.h" | ||
#import "KBKegProcessing.h" | ||
#import "KBNotifications.h" | ||
#import "KBTypes.h" | ||
|
||
@implementation KBFlowIndicator | ||
|
||
@synthesize needleView=needleView_, fillView=fillView_, volumeLabel=volumeLabel_, flowLabel=flowLabel_; | ||
|
||
- (void)awakeFromNib { | ||
_minimumFlowRate = 0; | ||
_maximumFlowRate = 1; | ||
_minimumAngle = -0.41 * M_PI; | ||
_maximumAngle = 0.41 * M_PI; | ||
_flowRate = 0; | ||
|
||
_minimumVolume = 0; | ||
_maximumVolume = 16; | ||
_minimumTopY = 306; | ||
_maximumTopY = 210; | ||
_volume = 0; | ||
|
||
[self setFlowRate:0 animated:NO]; | ||
[self setVolume:0 animated:NO]; | ||
//[self simulateValues]; | ||
|
||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_onUpdatePourNotification:) name:KBUpdatePourNotification object:nil]; | ||
} | ||
|
||
- (void)setRotationRadians:(CGFloat)radians animated:(BOOL)animated { | ||
if (animated) { | ||
[UIView beginAnimations:nil context:nil]; | ||
[UIView setAnimationCurve:UIViewAnimationCurveLinear]; | ||
[UIView setAnimationDuration:0.1]; | ||
[UIView setAnimationBeginsFromCurrentState:YES]; | ||
CGAffineTransform transform = CGAffineTransformRotate(CGAffineTransformIdentity, radians); | ||
needleView_.transform = CGAffineTransformTranslate(transform, 0, -71); | ||
[UIView commitAnimations]; | ||
} else { | ||
CGAffineTransform transform = CGAffineTransformRotate(CGAffineTransformIdentity, radians); | ||
needleView_.transform = CGAffineTransformTranslate(transform, 0, -71); | ||
[needleView_ setNeedsDisplay]; | ||
} | ||
} | ||
|
||
- (void)setFlowRate:(double)flowRate animated:(BOOL)animated { | ||
[flowLabel_ setText:[NSString stringWithFormat:@"%0.1f", flowRate]]; | ||
if (flowRate > _maximumFlowRate) flowRate = _maximumFlowRate; | ||
if (flowRate < _minimumFlowRate) flowRate = _minimumFlowRate; | ||
_flowRate = flowRate; | ||
double fraction = (flowRate - _minimumFlowRate) / (_maximumFlowRate - _minimumFlowRate); | ||
double angle = fraction * (_maximumAngle - _minimumAngle) + _minimumAngle; | ||
[[self gh_proxyOnMainThread] setRotationRadians:angle animated:animated]; | ||
} | ||
|
||
- (void)setTopY:(CGFloat)topY animated:(BOOL)animated { | ||
if (animated) { | ||
[UIView beginAnimations:nil context:nil]; | ||
[UIView setAnimationCurve:UIViewAnimationCurveLinear]; | ||
[UIView setAnimationDuration:0.1]; | ||
[UIView setAnimationBeginsFromCurrentState:YES]; | ||
fillView_.frame = CGRectMake(fillView_.frame.origin.x, topY, fillView_.frame.size.width, fillView_.frame.size.height); | ||
[UIView commitAnimations]; | ||
} else { | ||
fillView_.frame = CGRectMake(fillView_.frame.origin.x, topY, fillView_.frame.size.width, fillView_.frame.size.height); | ||
[fillView_ setNeedsDisplay]; | ||
} | ||
} | ||
|
||
- (void)setVolume:(double)volume animated:(BOOL)animated { | ||
[volumeLabel_ setText:[NSString stringWithFormat:@"%0.1f", volume]]; | ||
if (volume > _maximumVolume) volume = _maximumVolume; | ||
if (volume < _minimumVolume) volume = _minimumVolume; | ||
_volume = volume; | ||
double fraction = (volume - _minimumVolume) / (_maximumVolume - _minimumVolume); | ||
CGFloat topY = fraction * (_maximumTopY - _minimumTopY) + _minimumTopY; | ||
[[self gh_proxyOnMainThread] setTopY:topY animated:animated]; | ||
} | ||
|
||
- (void)simulateValues { | ||
_simulationTimer = [[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(setSimulatedValue) userInfo:nil repeats:YES] retain]; | ||
_simulatedValueIncreasing = YES; | ||
} | ||
|
||
- (void)setSimulatedValue { | ||
double interval = (_maximumFlowRate - _minimumFlowRate) / 20; | ||
double interval2 = (_maximumVolume - _minimumVolume) / 20; | ||
if (_simulatedValueIncreasing) { | ||
_flowRate += interval; | ||
_volume += interval2; | ||
if (_flowRate > _maximumFlowRate) { | ||
_simulatedValueIncreasing = NO; | ||
} | ||
} else { | ||
_flowRate -= interval; | ||
_volume -= interval2; | ||
if (_flowRate < _minimumFlowRate) { | ||
_simulatedValueIncreasing = YES; | ||
} | ||
} | ||
[self setVolume:_volume animated:YES]; | ||
[self setFlowRate:_flowRate animated:YES]; | ||
} | ||
|
||
- (void)_onUpdatePourNotification:(NSNotification *)notification { | ||
KBKegProcessing *kegProcessing = (KBKegProcessing *)[notification object]; | ||
[self setVolume:kegProcessing.pourVolume * kLitersToOunces animated:YES]; | ||
[self setFlowRate:kegProcessing.flowRate * kLitersToOunces animated:YES]; | ||
} | ||
|
||
@end |
Oops, something went wrong.
10611ae
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im going to try and get this flow reading working in KegCop very soon :)