Files
mowesta/ios-app/app/Arduino/ArduinoState.swift
T
Marcus Handte 2c788e3329
LocationBasedServices/mowesta/pipeline/head This commit looks good
Add weather station configuration to ios app.
2022-11-03 16:47:26 +01:00

72 lines
1.7 KiB
Swift

//
// ArduinoState.swift - The state object to store the state of the arduino process.
//
// Created by Marcus Handte on 03.11.22.
//
import Foundation
import NetworkExtension
/// The state to track the progress of the arduino configuration
class ArduinoState: ObservableObject {
var phase = ArduinoPhase.configure { willSet { objectWillChange.send() }}
var failure: ArduinoPhase?
var network = "" { willSet { objectWillChange.send() }}
var password = "" { willSet { objectWillChange.send() }}
var model = "Arduino" { willSet { objectWillChange.send() }}
var longitude = "" { willSet { objectWillChange.send() }}
var latitude = "" { willSet { objectWillChange.send() }}
var lon: Double? {
return Double(longitude)
}
var lat: Double? {
return Double(latitude)
}
init() {
updateNetwork()
}
func updateNetwork() {
guard network.count == 0 else {
return
}
NEHotspotNetwork.fetchCurrent(completionHandler: { net in
if let n = net {
if self.network.count == 0 {
self.network = n.ssid
}
}
})
}
func reset() {
if phase == .failure || phase == .success{
failure = nil
phase = .configure
}
}
func isExecutable() -> Bool {
return phase == .configure &&
network.count > 0 &&
password.count >= 8 &&
model.count > 0 &&
lat != nil &&
lon != nil
}
}
/// The phases of the configuration process
enum ArduinoPhase {
case configure
case register
case connect
case transfer
case success
case failure
}