Skip to content

Commit

Permalink
Bumping version to 1.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Oct 30, 2019
1 parent f6387c3 commit e9f29d7
Show file tree
Hide file tree
Showing 8 changed files with 310 additions and 284 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Release Notes

## 1.8.0 - 2019-10-30
* Use GPIO from .NET Core 3

## 1.7.8 - 2019-10-30
* .NET Core 3

Expand Down
3 changes: 1 addition & 2 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@ group Pi
nuget Thoth.Json
nuget log4net
nuget Elmish
nuget Unosquare.Raspberry.IO strategy:min
nuget Unosquare.WiringPi strategy:min
nuget System.Device.Gpio
333 changes: 143 additions & 190 deletions paket.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/Client/ReleaseNotes.fs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
module internal ReleaseNotes

let Version = "1.7.8"
let Version = "1.8.0"

let IsPrerelease = false

let Notes = """
# Release Notes
## 1.8.0 - 2019-10-30
* Use GPIO from .NET Core 3
## 1.7.8 - 2019-10-30
* .NET Core 3
Expand Down
161 changes: 114 additions & 47 deletions src/PiServer/GeneralIO.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,139 @@
open System
open System.Threading.Tasks
open FSharp.Control.Tasks.ContextInsensitive
open System.Device.Gpio

open Unosquare.RaspberryIO
open Unosquare.WiringPi
open Unosquare.RaspberryIO.Abstractions


let init() =
Pi.Init<BootstrapWiringPi>()

type LED(pin:IGpioPin) =
type LED(controller:GpioController,log:log4net.ILog,pin:int) =
let mutable active = false
let mutable blinking = false
do
pin.PinMode <- GpioPinDriveMode.Output
pin.Write false
controller.OpenPin(pin, PinMode.Output)
controller.Write(pin, PinValue.Low)

with
member __.IsActive = active

member __.Activate() =
pin.Write true
controller.Write(pin, PinValue.High)
blinking <- false
active <- true

member __.Deactivate() =
pin.Write false
controller.Write(pin, PinValue.Low)
blinking <- false
active <- false

member this.Blink(times:int) = task {
blinking <- false
for _ in 0..times-1 do
this.Activate()
do! Task.Delay(300)
this.Deactivate()
do! Task.Delay(300)
}

type Button(pin:IGpioPin,onPress) =
let mutable lastChangedState = DateTime.MinValue
let bounceTimeSpan = TimeSpan.FromMilliseconds 30.
let mutable lastState = false
member this.StartBlinking() = task {
blinking <- true
while blinking do
this.Activate()
do! Task.Delay(300)
this.Deactivate()
do! Task.Delay(300)
}

member this.StopBlinking() = this.Deactivate()

type CableConnection(controller:GpioController,log:log4net.ILog,pin:int) =
let mutable onConnected = None
let mutable onDisconnected = None
let mutable lastState = None

let execute expectedState f =
match lastState with
| Some s ->
let state = controller.Read(pin) = PinValue.High
if state = expectedState && s <> state then
f()
lastState <- Some state
| None ->
let state = controller.Read(pin) = PinValue.High
if state = expectedState then
f()
lastState <- Some state

do
pin.PinMode <- GpioPinDriveMode.Input
pin.InputPullMode <- GpioPinResistorPullMode.PullUp
lastState <- pin.Read()
pin.RegisterInterruptCallback(
EdgeDetection.FallingAndRisingEdge,
fun () ->
let state = pin.Read()
let time = DateTime.UtcNow
let bounceTimeReached = lastChangedState.Add bounceTimeSpan < time
if bounceTimeReached && (not state) && lastState then
()
if bounceTimeReached && state && not lastState then
onPress()
if lastState <> state then
lastChangedState <- time
lastState <- state)

let d =
{ new IDisposable with
member __.Dispose() = () }

interface IDisposable with
member __.Dispose() = d.Dispose()

let waitForButtonPress (pin:IGpioPin) = task {
let pressed = ref false
use _button = new Button(pin,(fun _ -> pressed := true))
while not !pressed do
do! Task.Delay(100)
}
controller.OpenPin(pin, PinMode.InputPullUp)

let rising(_sender:obj) (_e:PinValueChangedEventArgs) =
log.InfoFormat("Rising - unconnected")
match onDisconnected with
| None -> ()
| Some f -> execute true f

let falling(_sender:obj) (_e:PinValueChangedEventArgs) =
log.InfoFormat("Falling - connected")
match onConnected with
| None -> ()
| Some f -> execute false f

controller.RegisterCallbackForPinValueChangedEvent(
pin,
PinEventTypes.Rising,
PinChangeEventHandler rising)

controller.RegisterCallbackForPinValueChangedEvent(
pin,
PinEventTypes.Falling,
PinChangeEventHandler falling)

member __.SetOnConnected f =
onConnected <- Some f
execute false f

member __.SetOnDisConnected f =
onDisconnected <- Some f
execute true f

type Button(controller:GpioController,log:log4net.ILog,pin:int,onPress) =
let mutable lastState = None

let execute () =
match lastState with
| Some s ->
let state = controller.Read(pin) = PinValue.High
if not state && s <> state then
lastState <- Some state
| None ->
let state = controller.Read(pin) = PinValue.High
if not state then
onPress()
lastState <- Some state

do
controller.OpenPin(pin, PinMode.InputPullUp)

let falling(_sender:obj) (_e:PinValueChangedEventArgs) =
log.InfoFormat("Falling - pressed")
execute ()

controller.RegisterCallbackForPinValueChangedEvent(
pin,
PinEventTypes.Falling,
PinChangeEventHandler falling)


type Controller(log:log4net.ILog) =
let controller = new GpioController(PinNumberingScheme.Logical)

with
member __.NewLED(pin) =
LED(controller,log,pin)

member __.NewCableConnection(pin:int) =
CableConnection(controller,log,pin)

member __.NewButton(pin:int,onPress) =
Button(controller,log,pin,onPress)

interface IDisposable with
member __.Dispose() = controller.Dispose()
24 changes: 16 additions & 8 deletions src/PiServer/PiServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ open System.Reflection
open GeneralIO
open Elmish
open Elmish.Audio
open Unosquare.RaspberryIO.Abstractions


GeneralIO.init()

let runIn (timeSpan:TimeSpan) successMsg errorMsg =
let t() = task {
Expand All @@ -36,6 +34,14 @@ let log =
log


let controller =
try
new GeneralIO.Controller(log)
with
| exn ->
log.ErrorFormat("Error during GPIO init: {0}", exn.Message)
reraise()

type MediaFile = {
FileName : string
}
Expand Down Expand Up @@ -72,12 +78,12 @@ type Msg =
let rfidLoop (dispatch,nodeServices:INodeServices) = task {
log.InfoFormat("Connecting all buttons")

use _nextButton = new Button(Unosquare.RaspberryIO.Pi.Gpio.[BcmPin.Gpio04], fun () -> dispatch NextMediaFile)
use _previousButton = new Button(Unosquare.RaspberryIO.Pi.Gpio.[BcmPin.Gpio18], fun () -> dispatch PreviousMediaFile)
use _volumeDownButton = new Button(Unosquare.RaspberryIO.Pi.Gpio.[BcmPin.Gpio26], fun () -> dispatch VolumeDown)
use _volumeUpButton = new Button(Unosquare.RaspberryIO.Pi.Gpio.[BcmPin.Gpio12], fun () -> dispatch VolumeUp)
let blueLight = GeneralIO.LED(Unosquare.RaspberryIO.Pi.Gpio.[BcmPin.Gpio20])
let yellowLight = GeneralIO.LED(Unosquare.RaspberryIO.Pi.Gpio.[BcmPin.Gpio21])
let _nextButton = controller.NewButton(4, fun () -> dispatch NextMediaFile)
let _previousButton = controller.NewButton(18, fun () -> dispatch PreviousMediaFile)
let _volumeDownButton = controller.NewButton(26, fun () -> dispatch VolumeDown)
let _volumeUpButton = controller.NewButton(12, fun () -> dispatch VolumeUp)
let blueLight = controller.NewLED(20)
let yellowLight = controller.NewLED(21)
let allLights = [| blueLight; yellowLight|]

let! _ = allLights |> Array.map (fun l -> l.Blink(2)) |> Task.WhenAll
Expand Down Expand Up @@ -306,4 +312,6 @@ let t = task { while true do do! Task.Delay 10000 }

t |> Async.AwaitTask |> Async.RunSynchronously

(controller :> IDisposable).Dispose()

log.InfoFormat("PiServer {0} is shutting down.", ReleaseNotes.Version)
61 changes: 28 additions & 33 deletions src/PiServer/PiServer.fsproj
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Client\ReleaseNotes.fs" />
<Compile Include="..\Shared\Shared.fs" />
<Compile Include="..\Server\Utils.fs" />
<Compile Include="SemVer.fs" />
<Compile Include="FirmwareUpdate.fs" />
<Compile Include="Elmish.Audio.fs" />
<Compile Include="GeneralIO.fs" />
<Compile Include="PiServer.fs" />
</ItemGroup>
<ItemGroup>
<None Include="read-tag.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

<None Include="package.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="log4net.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="PiServer">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="../Client/ReleaseNotes.fs" />
<Compile Include="../Shared/Shared.fs" />
<Compile Include="../Server/Utils.fs" />
<Compile Include="SemVer.fs" />
<Compile Include="FirmwareUpdate.fs" />
<Compile Include="Elmish.Audio.fs" />
<Compile Include="GeneralIO.fs" />
<Compile Include="PiServer.fs" />
<None Include="read-tag.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="package.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="log4net.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="PiServer">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
4 changes: 1 addition & 3 deletions src/PiServer/paket.references
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@ group Pi
Thoth.Json.Net
Thoth.Json
log4net
Unosquare.Raspberry.IO
System.Device.Gpio
Elmish
Unosquare.WiringPi

0 comments on commit e9f29d7

Please sign in to comment.