Stap 18: ESP8266 Code - vervolg
De definitieve code wil dit:
UIKit klasse ViewController importeren: {UIViewController} import UIKit class ViewController: UIViewController { weak var web: UIWebView! weak var label: UILabel! weak var slider: UISlider! var onURLPath = "http://192.168.4.1/?pin=ONA" var offURLPath = "http://192.168.4.1/?pin=OFFA" var on1URLPath = "http://192.168.4.1/?pin=ONB" var off1URLPath = "http://192.168.4.1/?pin=OFFB" var on2URLPath = "http://192.168.4.1/?pin=ONC" var off2URLPath = "http://192.168.4.1/?pin=OFFC" var on3URLPath = "http://192.168.4.1/?pin=OND" var off3URLPath = "http://192.168.4.1/?pin=OFFD" override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } //UP func buttonTouched(sender: UIButton) { let requestURL = NSURL(string: onURLPath+"\(label.text!)") let request = NSURLRequest(URL: requestURL!) web.loadRequest(request) print(requestURL!) } func buttonReleased(sender: UIButton) { let requestURL = NSURL(string: offURLPath) let request = NSURLRequest(URL: requestURL!) web.loadRequest(request) print(requestURL!) } //Down func buttonTouched1(sender: UIButton) { let requestURL = NSURL(string: on1URLPath+"\(label.text!)") let request = NSURLRequest(URL: requestURL!) web.loadRequest(request) print(requestURL!) } func buttonReleased1(sender: UIButton) { let requestURL = NSURL(string: off1URLPath) let request = NSURLRequest(URL: requestURL!) web.loadRequest(request) print(requestURL!) } //Left func buttonTouchedLeft(sender: UIButton) { let requestURL = NSURL(string: on2URLPath+"\(label.text!)") let request = NSURLRequest(URL: requestURL!) web.loadRequest(request) print(requestURL!) } func buttonReleasedLeft(sender: UIButton) { let requestURL = NSURL(string: off2URLPath) let request = NSURLRequest(URL: requestURL!) web.loadRequest(request) print(requestURL!) } //Right func buttonTouched3(sender: UIButton) { let requestURL = NSURL(string: on3URLPath+"\(label.text!)") let request = NSURLRequest(URL: requestURL!) web.loadRequest(request) print(requestURL!) } func buttonReleased3(sender: UIButton) { let requestURL = NSURL(string: off3URLPath) let request = NSURLRequest(URL: requestURL!) web.loadRequest(request) print(requestURL!) } //Slider func sliderValueChanged(sender: UISlider) { var currentValue = Int(sender.value) label.text = "\(currentValue)" } } var onURLPath = "http://192.168.4.1/?pin=ONA" var offURLPath = "http://192.168.4.1/?pin=OFFA" var on1URLPath = "http://192.168.4.1/?pin=ONB" var off1URLPath = "http://192.168.4.1/?pin=OFFB" var on2URLPath = "http://192.168.4.1/?pin=ONC" var off2URLPath = "http://192.168.4.1/?pin=OFFC" var on3URLPath = "http://192.168.4.1/?pin=OND" var off3URLPath = "http://192.168.4.1/?pin=OFFD" override func viewDidLoad() {super.viewDidLoad() / / Do extra instellingen na het laden van de weergave, meestal uit een nib.} overschrijven func-didReceiveMemoryWarning() {super.didReceiveMemoryWarning() / / verwijdering van bronnen die opnieuw aangemaakt kunnen worden.} //UPfunc buttonReleased(sender: UIButton) {laat requestURL = NSURL(string: offURLPath) laat verzoek = NSURLRequest (URL: requestURL!) web.loadRequest(request) print(requestURL!)} //Down func buttonTouched1(sender: UIButton) {laat requestURL = NSURL(string: on1URLPath+"\(label.text!)") laat verzoek = NSURLRequest (URL: requestURL!) web.loadRequest(request) print(requestURL!)} func buttonReleased1(sender: UIButton) {laat requestURL = NSURL(string: off1URLPath) laat verzoek = NSURLRequest (URL: requestURL!) web.loadRequest(request) print(requestURL!)} //Left func buttonTouchedLeft(sender: UIButton) {laat requestURL = NSURL(string: on2URLPath+"\(label.text!)") laat verzoek = NSURLRequest (URL: requestURL!) web.loadRequest(request) print(requestURL!)} func buttonReleasedLeft(sender: UIButton) {laat requestURL = NSURL(string: off2URLPath) laat verzoek = NSURLRequest (URL: requestURL!) web.loadRequest(request) print(requestURL!)} //Right func buttonTouched3(sender: UIButton) {laat requestURL = NSURL(string: on3URLPath+"\(label.text!)") laat verzoek = NSURLRequest (URL: requestURL!) web.loadRequest(request) print(requestURL!)} func buttonReleased3(sender: UIButton) {laat requestURL = NSURL(string: off3URLPath) laat verzoek = NSURLRequest (URL: requestURL!) web.loadRequest(request) print(requestURL!)} //Slider