Commit 1565f860 authored by Timo Tegtmeier's avatar Timo Tegtmeier

Improved code a bit

parent 99b8b74a
......@@ -424,17 +424,16 @@
goto error;
// buf[0] enthält nun den NEUEN Wert der Ruhestromabschaltung
if(buf[0] != AUTOPOWEROFF_ENABLED) {
[self setAutoPowerOffEnabled: YES];
} else {
[self setAutoPowerOffEnabled: NO];
}
_powerOffState = buf[0] != AUTOPOWEROFF_ENABLED;
[self setAutoPowerOffEnabled: _powerOffState];
// alten Status wiederherstellen
if(!(okay = DiagQuery (CMD_TOGGLE_AUTOPOWEROFF, CMD_TOGGLE_AUTOPOWEROFF_LEN, buf)))
goto error;
}
} else {
_powerOffState = YES;
[self setAutoPowerOffEnabled: _powerOffState];
}
//
// Fertig; Noch schnell ein paar Stati setzen,
......@@ -449,7 +448,6 @@
[self setRpm: 0];
[self setRevTime: 0];
_powerOffState = YES;
[self startMonitor];
return nil;
......@@ -660,25 +658,21 @@ error:
//
//
unsigned char buf;
bool state = [self autoPowerOffEnabled];
if(_powerOffState == state)
return nil;
unsigned char buf;
if(!(DiagQuery (CMD_TOGGLE_AUTOPOWEROFF, CMD_TOGGLE_AUTOPOWEROFF_LEN, &buf))) {
[self setLastError: [ECUError errorWithQueryError: @"applyAutoPowerOffEnabled"]];
return [self lastError];
}
if(_powerOffState != state) {
if(!(DiagQuery (CMD_TOGGLE_AUTOPOWEROFF, CMD_TOGGLE_AUTOPOWEROFF_LEN, &buf))) {
[self setLastError: [ECUError errorWithQueryError: @"applyAutoPowerOffEnabled"]];
return [self lastError];
}
}
if(buf == AUTOPOWEROFF_ENABLED) {
_powerOffState = TRUE;
} else {
_powerOffState = FALSE;
}
_powerOffState = buf == AUTOPOWEROFF_ENABLED;
if(state != _powerOffState) {
// NSLog (@"Something went wrong with autopoweroff; retrying to set!");
NSLog (@"Something went wrong with autopoweroff; retrying to set!");
[self applyAutoPowerOffEnabled];
}
return nil;
......
......@@ -43,7 +43,7 @@
if(noSerial)
return nil;
ret = GetPorts (&str, 128);
ret = GetPorts (str, 128);
if(ret) {
return [NSString stringWithCString:str encoding:NSASCIIStringEncoding];
} else {
......
......@@ -264,7 +264,7 @@
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1120;
LastUpgradeCheck = 1130;
};
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "TTRCom" */;
compatibilityVersion = "Xcode 3.0";
......@@ -406,7 +406,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD)";
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
......@@ -445,7 +444,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD)";
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
......
......@@ -31,7 +31,7 @@
#define CONTEXT_ERR (void*)"com"
@interface UIController : NSObject {
@interface UIController : NSObject <NSToolbarDelegate> {
//
// -- Über IB gebundene Objekte --
//
......
......@@ -23,7 +23,6 @@
//
// Trennen/Verbinden
// Status:
//
-(void) connect: (id) sender {
//
......@@ -98,7 +97,8 @@
if([[NSUserDefaults standardUserDefaults] boolForKey: @"resetECUOnConnect"])
[ECU reset: self];
}
-(void) disconnect: (id) sender {
-(void) disconnect:(id) sender {
//
// Verbindung trennen
// Status: Fertig; es können noch Observer dazukommen
......@@ -118,7 +118,7 @@
// Fehlerspeicherfunktionen
// Status: Fertig, Errorhandling eingebaut
//
-(IBAction) readOutErrors: (id) sender {
-(IBAction) readOutErrors:(id) sender {
//
// Den Fehlerspeicher auslesen und anschließend
// in das zugehörige Feld schreiben
......@@ -129,7 +129,8 @@
[tableErrors reloadData];
}
-(IBAction) clearErrors: (id) sender {
-(IBAction) clearErrors:(id) sender {
//
// Den Fehlerspeicher löschen
// Im Anschluß wird der Fehlerspeicher neu eingelesen,
......@@ -150,14 +151,16 @@
// Hiermit observieren wir Statusänderungen
// Status: Fertig, überprüfen
//
-(void) observeValueForKeyPath: (NSString *)keyPath ofObject: (id)object
change: (NSDictionary *)change context: (void *)context {
-(void) observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
if (context == CONTEXT_ERR) { // asynchroner Fehler
[self handleECUError];
}
}
-(void) handleECUError {
-(void) handleECUError {
ECUError *err = [ECU lastError];
if(err == nil)
return;
......@@ -190,9 +193,9 @@
}
//
// Toolbargeschichten
// Toolbar
//
-(bool) validateToolbarItem: (NSToolbarItem *)item {
-(BOOL) validateToolbarItem:(NSToolbarItem *)item {
if([[item itemIdentifier] isEqual: @"Connect"])
return YES;
......@@ -202,11 +205,12 @@
return NO;
}
}
-(void) addToolbarItem: (NSString *)identifier
label:(NSString *)label
content:(id)content paletteLabel:(NSString *)pLabel
toolTip:(NSString *)toolTip
target:(id)target action:(SEL)action {
-(void) addToolbarItem:(NSString *)identifier
label:(NSString *)label
content:(id)content paletteLabel:(NSString *)pLabel
toolTip:(NSString *)toolTip
target:(id)target action:(SEL)action {
// Toolbaritem hinzufügen
NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier: identifier];
[item setLabel:label];
......@@ -219,12 +223,14 @@
[toolbarItems setObject:item forKey:identifier];
}
-(NSToolbarItem *) toolbar: (NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag {
-(NSToolbarItem *) toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag {
return [toolbarItems objectForKey:itemIdentifier];
}
-(NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar*)toolbar {
-(NSArray *) toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar {
return [NSArray arrayWithObjects:
@"OpenParameters",
@"OpenErrors",
......@@ -236,7 +242,8 @@
@"Connect",
nil];
}
-(NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar*)toolbar {
-(NSArray *) toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar {
return [NSArray arrayWithObjects:
@"OpenParameters",
@"OpenErrors",
......@@ -248,7 +255,8 @@
NSToolbarFlexibleSpaceItemIdentifier,
nil];
}
-(void) setUpToolbar {
-(void) setUpToolbar {
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier: @"ttrmacToolbar"];
[self addToolbarItem:@"OpenParameters"
......@@ -305,7 +313,7 @@
//
// Methoden zur Initialisierung der UI
//
-(void) cleanUpUI {
-(void) cleanUpUI {
[labelCommState setStringValue: NSLocalizedString (@"not connected", @"String to be shown when not connected")];
[indicatorComm setDisplayedWhenStopped: FALSE];
[indicatorRecording setDisplayedWhenStopped: FALSE];
......@@ -320,10 +328,10 @@
if(drawerErrors != nil)
[drawerErrors close];
}
-(void) awakeFromNib {
-(void) awakeFromNib {
//
// Vorbereiten aller Daten; Alle Bindings sind durchgeführt
// Status: Nochmal überdenken, ob alle Anzeigen so in Ordnung sind
//
[self loadInterfaces: self];
[self cleanUpUI];
......@@ -338,9 +346,8 @@
//
// Valide Interfaces bestimmen
// Status: Fertig
//
-(IBAction) loadInterfaces: (id) sender {
-(IBAction) loadInterfaces: (id) sender {
NSMutableArray *list = [[NSMutableArray alloc] init];
NSString *path;
......@@ -353,9 +360,8 @@
//
// Nach Steuergeräten suchen
// Status: Experimentell
//
-(IBAction) detectECU: (id) sender {
-(IBAction) detectECU: (id) sender {
NSMutableArray *list = [[NSMutableArray alloc] init];
NSString *path;
......@@ -376,31 +382,35 @@
//
// Eventhandler
//
-(IBAction) saveRecordAs: (id) sender {
-(IBAction) saveRecordAs: (id) sender {
NSSavePanel *saveDlg = [NSSavePanel savePanel];
[saveDlg setCanCreateDirectories: TRUE];
[saveDlg setRequiredFileType: @"csv"];
[saveDlg setAllowedFileTypes:[NSArray arrayWithObject:@"csv"]];
[saveDlg setExtensionHidden: FALSE];
[saveDlg setMessage: NSLocalizedString (@"Select filename for the log", @"Log path")];
if ([saveDlg runModal] == NSFileHandlingPanelOKButton) {
[[NSUserDefaults standardUserDefaults] setObject:[saveDlg filename] forKey:@"recordingPath"];
[[NSUserDefaults standardUserDefaults] setObject:[[saveDlg URL] path] forKey:@"recordingPath"];
}
}
-(IBAction) toggleParameters: (id)sender {
-(IBAction) toggleParameters:(id)sender {
[drawerParameters toggle: self];
[showParameters setState: ![showParameters state]];
}
-(IBAction) toggleErrors: (id)sender {
-(IBAction) toggleErrors:(id)sender {
[drawerErrors toggle: self];
[showErrors setState: ![showErrors state]];
}
-(IBAction) toggleMaintenance: (id)sender {
-(IBAction) toggleMaintenance: (id)sender {
[drawerMaintenance toggle: self];
[showMaintenance setState: ![showMaintenance state]];
}
-(IBAction) toggleConnect: (id)sender {
-(IBAction) toggleConnect:(id)sender {
if([ECU connected]) {
if([ECU recording])
[self toggleRecording: self];
......@@ -413,7 +423,7 @@
"tooltip for toolbar item: connect")];
} else {
[self connect: self];
[self connect:self];
if([ECU connected]) {
[[toolbarItems objectForKey: @"Connect"] setLabel:
......@@ -427,7 +437,8 @@
}
}
}
-(IBAction) toggleRecording: (id)sender {
-(IBAction) toggleRecording:(id)sender {
if([ECU recording]) {
[ECU stopRecording];
[[toolbarItems objectForKey: @"Record"] setLabel:
......@@ -452,13 +463,16 @@
}
}
}
-(IBAction) submitOptions: (id) sender { [ECU submit: self]; }
-(IBAction) resetOptions: (id) sender { [ECU reset: self]; }
-(IBAction) submitOptions:(id) sender {
[ECU submit: self];
}
-(IBAction) resetOptions:(id) sender {
[ECU reset: self];
}
//
// Initialisierung
// Status: Fertig bis auf weiteres
//
-(UIController *) init {
self = [super init];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment