Changeset 756


Ignore:
Timestamp:
Aug 12, 2006, 8:13:25 PM (15 years ago)
Author:
livings124
Message:

More improvements to the way speed limit scheduling works.

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r752 r756  
    149149
    150150- (void) toggleSpeedLimit: (id) sender;
    151 - (void) autoSpeedLimit: (id) sender;
     151- (void) autoSpeedLimitChange: (NSNotification *) notification;
     152- (void) autoSpeedLimit: (NSTimer *) timer;
    152153
    153154- (void) setLimitGlobalEnabled: (id) sender;
  • trunk/macosx/Controller.m

    r754 r756  
    306306                    name: @"RatioGlobalChange" object: nil];
    307307   
    308     [nc addObserver: self selector: @selector(autoSpeedLimit:)
     308    [nc addObserver: self selector: @selector(autoSpeedLimitChange:)
    309309                    name: @"AutoSpeedLimitChange" object: nil];
    310310   
     
    355355   
    356356    //timer to auto toggle speed limit
    357     [self autoSpeedLimit: nil];
     357    [self autoSpeedLimitChange: nil];
    358358    fSpeedLimitTimer = [NSTimer scheduledTimerWithTimeInterval: AUTO_SPEED_LIMIT_SECONDS target: self
    359359        selector: @selector(autoSpeedLimit:) userInfo: nil repeats: YES];
     
    12561256}
    12571257
    1258 - (void) autoSpeedLimit: (id) sender
     1258- (void) autoSpeedLimitChange: (NSNotification *) notification
    12591259{
    12601260    if (![fDefaults boolForKey: @"SpeedLimitAuto"])
     
    12751275   
    12761276    if (fSpeedLimitEnabled != shouldBeOn)
     1277        [self toggleSpeedLimit: nil];
     1278}
     1279
     1280- (void) autoSpeedLimit: (NSTimer *) timer
     1281{
     1282    BOOL autoOn, autoOff;
     1283    if (!(autoOn = [fDefaults boolForKey: @"SpeedLimitAutoOn"])
     1284            && !(autoOff = [fDefaults boolForKey: @"SpeedLimitAutoOff"]))
     1285        return;
     1286 
     1287    //do nothing if time to turn on and off are equal
     1288    int onHour, offHour;
     1289    if ((onHour = [fDefaults integerForKey: @"SpeedLimitAutoOnHour"])
     1290            == (offHour = [fDefaults integerForKey: @"SpeedLimitAutoOffHour"]) && autoOn && autoOff)
     1291        return;
     1292   
     1293    NSCalendarDate * currentDate = [NSCalendarDate calendarDate];
     1294    //toggle if within first few seconds of hour
     1295    if ([currentDate minuteOfHour] == 0 && [currentDate secondOfMinute] < AUTO_SPEED_LIMIT_SECONDS
     1296            && [currentDate hourOfDay] == (fSpeedLimitEnabled ? offHour : onHour))
    12771297    {
    12781298        [self toggleSpeedLimit: nil];
Note: See TracChangeset for help on using the changeset viewer.