Skip to content

Conversation

@TrevorDohm
Copy link

The current implementation of the flash IBAction in ViewController.swift does not update the slider value when the flash is toggled using the button. This is due to the reliance on the return value of the toggleFlash function, which indicates the overheating status rather than the actual flashlight state. Added isFlashOn parameter and some other toggling to fix.

@skevetter
Copy link

skevetter commented Oct 24, 2023

IMO - Over-engineered functionality. Can re-factor torch to below implementation. Additional features should be implemented separately in View Controller or other section(s).

Also, implements no other Delegates or classes. Should be located in original class VisionAnalgesic or, recommended, separate Torch class. Extension is not necessary.

enum TorchState {
        case on
        case off
    }

var torch: TorchState {
    get {
        guard let device = self.videoDevice, device.hasTorch else { return .off }
        return device.torchMode == .on ? .on : .off
    }
    set {
        guard let device = self.videoDevice, device.hasTorch else { return }
        do {
            try device.lockForConfiguration()
            switch newValue {
            case .on:
                device.torchMode = .on
            case .off:
                device.torchMode = .off
            }
            device.unlockForConfiguration()
        } catch {
            Logger().error("Torch could not be used")
        }
    }
}

func torchBrightness(_ brightness: Float) {
    guard let device = self.videoDevice, device.hasTorch else { return }
    do {
        try device.lockForConfiguration()
        try device.setTorchModeOn(level: brightness)
        device.unlockForConfiguration()
    } catch {
        Logger().error("Torch could not be used")
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants