Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flash Toggle Slider Update Bug Fix #2

Open
wants to merge 1 commit into
base: 6_AV_OpenCVExamples
Choose a base branch
from

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.

@OceanTrader1
Copy link

OceanTrader1 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