// // ClientViewController.m // SimpleConfig // // Created by Realsil on 14/11/13. // Copyright (c) 2014年 Realtek. All rights reserved. // #import "ClientViewController.h" @interface ClientViewController () @end @implementation ClientViewController @synthesize sharedData; @synthesize pin_label, pinLabel, qrcode_btn, m_qrscan_line; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. m_controller = [[Controller alloc] init]; if (sharedData!=nil) { struct dev_info dev; [sharedData getValue:&dev]; NSLog(@"dev->require_pin=%@", (dev.require_pin==1)?@"YES":@"NO"); if(0x0a==dev.extra_info[0]) [_name_label setText:@"Untitled"]; else [_name_label setText:[NSString stringWithUTF8String:(const char *)dev.extra_info]]; _ip_label.text = [NSString stringWithFormat:@"%d.%d.%d.%d", 0xFF&(dev.ip>>24), 0xFF&(dev.ip>>16), 0xFF&(dev.ip>>8), 0xFF&dev.ip]; _mac_label.text = [NSString stringWithFormat:@"%02x:%02x:%02x:%02x:%02x:%02x", dev.mac[0], dev.mac[1], dev.mac[2], dev.mac[3], dev.mac[4], dev.mac[5]]; if(!dev.require_pin){ [pinLabel setHidden:true]; [pin_label setHidden:true]; [qrcode_btn setHidden:true]; }else{ [pinLabel setHidden:false]; [pin_label setHidden:false]; [qrcode_btn setHidden:false]; pin_label.text = @""; [pin_label addTarget:self action:@selector(textFieldDoneEditing:) forControlEvents:UIControlEventEditingDidEndOnExit]; } } pin_label.text = @""; [pin_label addTarget:self action:@selector(textFieldDoneEditing:) forControlEvents:UIControlEventEditingDidEndOnExit]; [_name_label addTarget:self action:@selector(textFieldDoneEditing:) forControlEvents:UIControlEventEditingDidEndOnExit]; m_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerHandler:) userInfo:nil repeats:YES]; m_mode = MODE_INIT; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // 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. } */ - (void)dealloc { #ifdef ARC [_name_label release]; [_ip_label release]; [_mac_label release]; [_delete_btn release]; [_rename_btn release]; [pin_label release]; [_name_label release]; [pin_label release]; [pinLabel release]; [qrcode_btn release]; [super dealloc]; #endif } /* Hide the keyboard when pushing "enter" */ - (BOOL)textFieldDoneEditing:(UITextField *)sender { NSLog(@"textFieldDoneEditing, Sender is %@", sender); UITextField *target = sender; return [target resignFirstResponder]; } - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { if([text isEqualToString:@"\n"]) { [textView resignFirstResponder]; return NO; } return YES; } - (void)viewDidDisappear:(BOOL)animated { // Must release simpleConfig, so that its asyncUDPSocket delegate won't receive data NSLog(@"close control socket"); [m_controller rtk_sc_close_sock]; [super viewDidDisappear:animated]; } - (void)viewWillAppear:(BOOL)animated { NSLog(@"reopen control socket"); [m_controller rtk_sc_reopen_sock]; } /* Button Delegate */ -(IBAction)delete_profile:(id)sender { // generate data NSString *pin = pin_label.text; unsigned int ip = [m_controller rtk_sc_convert_host_to_ip:_ip_label.text]; if (pin_label.isHidden==false && [pin isEqualToString:@""]) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:SC_UI_ALERT_TITLE_ERROR message:SC_UI_ALERT_INPUT_PIN delegate:self cancelButtonTitle:SC_UI_ALERT_OK otherButtonTitles:nil, nil]; [alert show]; return; }else if(pin_label.isHidden==true) pin = PATTERN_DEF_PIN; NSLog(@"pin=%@, ip=%x", pin, ip); [m_controller rtk_sc_gen_control_data:RTK_SC_CONTROL_DELETE pin:pin name:nil]; m_mode = MODE_CONTROL; // send data for (int i=0; i scan button finished"); //[text_pincode setText:m_pin_code]; } -(void)qrcode_animation { int maxScreen_width = [[UIScreen mainScreen] bounds].size.width; if (m_upOrdown == NO) { m_num ++; m_qrscan_line.frame = CGRectMake(20, 20+2*m_num, maxScreen_width-40*2, 1); if (2*m_num >= (maxScreen_width-30*2)) { m_upOrdown = YES; } } else { m_num --; m_qrscan_line.frame = CGRectMake(20, 20+2*m_num, maxScreen_width-40*2, 1); if (m_num <= 0) { m_upOrdown = NO; } } } /* Parse QRCode */ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { id results = [info objectForKey:ZBarReaderControllerResults]; ZBarSymbol *symbol = nil; for(symbol in results) break; NSLog(@"Got QRCode: %@", symbol.data); [pin_label setText:symbol.data]; //self.imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage]; [picker dismissViewControllerAnimated:YES completion:nil]; } @end