Ignore:
Timestamp:
Aug 11, 2006, 10:58:14 PM (16 years ago)
Author:
livings124
Message:

Scheduler is now more automatic.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r750 r752  
    306306                    name: @"RatioGlobalChange" object: nil];
    307307   
     308    [nc addObserver: self selector: @selector(autoSpeedLimit:)
     309                    name: @"AutoSpeedLimitChange" object: nil];
     310   
    308311    [nc addObserver: self selector: @selector(autoImportChange:)
    309312                    name: @"AutoImportSettingChange" object: nil];
     
    352355   
    353356    //timer to auto toggle speed limit
     357    [self autoSpeedLimit: nil];
    354358    fSpeedLimitTimer = [NSTimer scheduledTimerWithTimeInterval: AUTO_SPEED_LIMIT_SECONDS target: self
    355359        selector: @selector(autoSpeedLimit:) userInfo: nil repeats: YES];
     
    12521256}
    12531257
    1254 - (void) autoSpeedLimit: (NSTimer *) timer
    1255 {
    1256     BOOL autoOn, autoOff;
    1257     if (!(autoOn = [fDefaults boolForKey: @"SpeedLimitAutoOn"])
    1258             && !(autoOff = [fDefaults boolForKey: @"SpeedLimitAutoOff"]))
     1258- (void) autoSpeedLimit: (id) sender
     1259{
     1260    if (![fDefaults boolForKey: @"SpeedLimitAuto"])
    12591261        return;
    12601262 
     
    12621264    int onHour, offHour;
    12631265    if ((onHour = [fDefaults integerForKey: @"SpeedLimitAutoOnHour"])
    1264             == (offHour = [fDefaults integerForKey: @"SpeedLimitAutoOffHour"]) && autoOn && autoOff)
     1266            == (offHour = [fDefaults integerForKey: @"SpeedLimitAutoOffHour"]))
    12651267        return;
    12661268   
    1267     NSCalendarDate * currentDate = [NSCalendarDate calendarDate];
    1268     //toggle if within first few seconds of hour
    1269     if ([currentDate minuteOfHour] == 0 && [currentDate secondOfMinute] < AUTO_SPEED_LIMIT_SECONDS
    1270             && [currentDate hourOfDay] == (fSpeedLimitEnabled ? offHour : onHour))
     1269    BOOL rangeForOn = onHour < offHour;
     1270    int min, max;
     1271    if (rangeForOn)
     1272    {
     1273        min = onHour;
     1274        max = offHour;
     1275    }
     1276    else
     1277    {
     1278        min = offHour;
     1279        max = onHour;
     1280    }
     1281   
     1282    int hour = [[NSCalendarDate calendarDate] hourOfDay];
     1283    BOOL inRange = hour >= min && hour < max;
     1284   
     1285    if ((!fSpeedLimitEnabled && (rangeForOn == inRange)) || (fSpeedLimitEnabled && (rangeForOn != inRange)))
    12711286    {
    12721287        [self toggleSpeedLimit: nil];
Note: See TracChangeset for help on using the changeset viewer.