SettingsViewController.m 3.96 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
//
//  SettingsViewController.m
//  PLUCdraft
//
//  Created by PLUC SeniorDesign on 2/17/15.
//  Copyright (c) 2015 Alexander W. Moore. All rights reserved.
//

#import "SettingsViewController.h"
#import "ScanBookViewController.h"

@interface SettingsViewController ()
@property (weak, nonatomic) IBOutlet UISwitch *switchContScan;

- (IBAction)switchContScanChange:(id)sender;


@property BOOL contScan;
@property int volume;

@end

@implementation SettingsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
28
    [self initializeSettings];    
29 30 31 32 33 34 35
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

36
#pragma mark - Navigation
37

38 39 40 41 42 43 44 45
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    ScanBookViewController *dest = [segue destinationViewController];
  
    dest.contScan = _contScan;
  
46 47
}

48 49 50 51 52 53 54 55 56
#pragma mark - Helper Functions


- (void)initializeSettings {
    NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
    [self.switchContScan setOn:[preferences boolForKey:@"switchOnOff"]];
    
    BatteryStatus battery_status = [[Captuvo sharedCaptuvoDevice] getBatteryStatus];
    [self displayBatteryStatusIcon:battery_status];
57 58
}

59
- (void)displayBatteryStatusIcon:(BatteryStatus)battery_status {
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
    switch (battery_status) {
        case BatteryStatus0Of4Bars: {
            self.batteryView.image  = [UIImage imageNamed:@"battery_discharging_000.png"];
            break;
        }
        case BatteryStatus1Of4Bars: {
            self.batteryView.image  = [UIImage imageNamed:@"battery_discharging_020.png"];
            break;
        }
        case BatteryStatus2Of4Bars: {
            self.batteryView.image  = [UIImage imageNamed:@"battery_discharging_060.png"];
            break;
        }
        case BatteryStatus3Of4Bars: {
            self.batteryView.image  = [UIImage imageNamed:@"battery_discharging_080.png"];
            break;
        }
        case BatteryStatus4Of4Bars: {
            self.batteryView.image  = [UIImage imageNamed:@"battery_discharging_100.png"];
            break;
        }
        case BatteryStatusPowerSourceConnected: {
82 83 84
            ChargeStatus charge_status = [[Captuvo sharedCaptuvoDevice] getChargeStatus];
            [self displayChargeStatusIcon:charge_status];
            //self.batteryView.image  = [UIImage imageNamed:@"battery_charging_100.png"];
85 86 87 88 89 90 91 92 93
            break;
        }
        case BatteryStatusUndefined: {
            self.batteryView.image  = [UIImage imageNamed:@"laptop_nobattery_klaptopdaemon.png"];
            break;
        }
    }
}

94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
-(void) displayChargeStatusIcon:(ChargeStatus)charge_status {
    switch (charge_status) {
        case ChargeStatusNotCharging:
            self.batteryView.image = [UIImage imageNamed:@"battery_charging_000.png"];
            break;
        case ChargeStatusCharging:
            self.batteryView.image = [UIImage imageNamed:@"battery_charging_060.png"];
            break;
        case ChargeStatusChargeComplete:
            self.batteryView.image = [UIImage imageNamed:@"battery_charging_100.png"];
            break;
        case ChargeStatusUndefined:
            self.batteryView.image = [UIImage imageNamed:@"laptop_nobattery_klaptopdaemon.png"];
            break;
        default:
            break;
    }
}

113
#pragma mark - UI Buttons
114 115

- (IBAction)switchContScanChange:(id)sender {
Alex Moore's avatar
Alex Moore committed
116 117 118 119
    //_contScan = _switchContScan.on;
    NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
    [preferences setBool:self.switchContScan.isOn forKey:@"switchOnOff"];
    [preferences synchronize];
120 121
}

122 123 124
- (IBAction)backBtnPressed:(id)sender {
    [self performSegueWithIdentifier:@"segueSettingsToScan" sender:nil];
}
125 126

@end