<commit_before>﻿open Trik

let model = new Model(ObjectSensorConfig = Ports.VideoSource.USB)

let sensor = model.ObjectSensor
sensor.Start()

let buttons = new ButtonPad()
buttons.Start()


let sensorOutput = sensor.ToObservable()

let targetStream = sensorOutput  
                    |> Observable.choose (fun o -> o.TryGetTarget) 


let colorStream = targetStream 
                  |> Observable.map (fun x -> printfn "print from colorStream %s" <| x.ToString(); (x.Hue, x.Value, x.Saturation))

let ledstripeDisposable = colorStream.Subscribe model.LedStripe

let setterDisposable = targetStream |> Observable.subscribe sensor.SetDetectTarget


let locationStream = sensorOutput  
                     |> Observable.choose (fun o -> o.TryGetLocation) 
                     |> Observable.map (fun x -> x.X)

let motorDispose = locationStream.Subscribe model.Motor.["M1"] 

let downButtonDispose = buttons.ToObservable() 
                        |> Observable.filter (fun x -> ButtonEventCode.Down = x.Button) 
                        |> Observable.subscribe (fun _ -> printfn "Detect by pressing Down";sensor.Detect())

let timerSetterDisposable = Observable.Interval(System.TimeSpan.FromSeconds 7.0) 
                            |> Observable.subscribe (fun _ -> printfn "Usual Detect by timer"; sensor.Detect())

printfn "press any key to detect"

while buttons.Read().Button <> ButtonEventCode.Up do
    printfn """Press "Up" to stop """<commit_msg>Small change in chameleon demo<commit_after>﻿open Trik
open System.Threading

[<EntryPoint>]
let main _ =
    let model = new Model(ObjectSensorConfig = Ports.VideoSource.USB)
    let sensor = model.ObjectSensor
    sensor.Start()

    let buttons = new ButtonPad()
    buttons.Start()

    let sensorOutput = sensor.ToObservable()

    let targetStream = sensorOutput  
                        |> Observable.choose (fun o -> o.TryGetTarget) 

    let colorStream = targetStream 
                      |> Observable.map (fun x -> printfn "print from colorStream %s" <| x.ToString(); (x.Hue, x.Value, x.Saturation))

    use ledstripeDisposable = colorStream.Subscribe model.LedStripe

    use setterDisposable = targetStream |> Observable.subscribe sensor.SetDetectTarget

    let locationStream = sensorOutput  
                         |> Observable.choose (fun o -> o.TryGetLocation) 
                         |> Observable.map (fun x -> x.X)

    use motorDispose = locationStream.Subscribe model.Motor.["M1"] 


    use downButtonDispose = buttons.ToObservable() 
                            |> Observable.filter (fun x -> ButtonEventCode.Down = x.Button) 
                            |> Observable.subscribe (fun _ -> printfn "Detect by pressing Down";sensor.Detect())
    
    use upButtonDispose = buttons.ToObservable()
                            |> Observable.filter (fun x -> ButtonEventCode.Up = x.Button)
                            |> Observable.subscribe (fun _ -> printfn "Exiting..."; System.Environment.Exit 0)

    use timerSetterDisposable = Observable.Interval(System.TimeSpan.FromSeconds 7.0) 
                                |> Observable.subscribe (fun _ -> printfn "Usual Detect by timer"; sensor.Detect())
    Thread.Sleep Timeout.Infinite
    0
{'fraction_non_alphanumeric': 0.10223048327137546, 'fraction_numerical': 0.0024783147459727386, 'mean_word_length': 2.4832793959007553, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4645177', 'n_tokens_mistral': 926, 'n_tokens_neox': 845, 'n_words': 225}