Skip to content

Commit

Permalink
Bumping version to 0.1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Oct 8, 2018
1 parent f3992bf commit a97663b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 55 deletions.
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release Notes

## 0.1.10 - 2018-10-08
## 0.1.11 - 2018-10-08

* Stream from Azure Blob Storage

Expand Down
4 changes: 2 additions & 2 deletions src/Client/ReleaseNotes.fs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module internal ReleaseNotes

let Version = "0.1.10"
let Version = "0.1.11"

let IsPrerelease = false

let Notes = """
# Release Notes
## 0.1.10 - 2018-10-08
## 0.1.11 - 2018-10-08
* Stream from Azure Blob Storage
Expand Down
38 changes: 30 additions & 8 deletions src/PiServer/PiServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ open Microsoft.Extensions.DependencyInjection
open Giraffe
open Saturn
open FSharp.Control.Tasks.ContextInsensitive

open System
open Microsoft.AspNetCore.NodeServices
open System.Runtime.InteropServices
open Thoth.Json.Net
open ServerCore.Domain

open System.Threading.Tasks
open System.Threading
open System.Diagnostics

let tagServer = "https://audio-hub.azurewebsites.net"
// let tagServer = "http://localhost:8085"
Expand All @@ -21,6 +22,7 @@ let port = 8086us

let isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
let cts = new CancellationTokenSource()
let mutable runningProcess = null

let play (nodeServices : INodeServices) (cancellationToken:CancellationToken) (uri:string) = task {
use webClient = new System.Net.WebClient()
Expand All @@ -36,6 +38,7 @@ let play (nodeServices : INodeServices) (cancellationToken:CancellationToken) (u
else
printfn "Playing %s" uri
let p = new System.Diagnostics.Process()
runningProcess <- p
let s = System.Diagnostics.ProcessStartInfo()
p.EnableRaisingEvents <- true
let tcs = new TaskCompletionSource<obj>()
Expand All @@ -61,6 +64,12 @@ let stop (nodeServices : INodeServices) = task {
let! r = nodeServices.InvokeExportAsync<string>("./play-audio", "stop")
return r
else
printfn "trying to kill"
let processes = Process.GetProcessesByName("omxplayer.bin")
for p in processes do
if not p.HasExited then
printfn "kill"
p.Kill()
cts.Cancel()
return "Test"
}
Expand Down Expand Up @@ -178,15 +187,28 @@ let nodeServices = app.Services.GetService(typeof<INodeServices>) :?> INodeServi
let startupTask = executeStartupActions nodeServices
startupTask.Wait()

printfn "%A" startupTask.Result

let mutable running = null
let rec rfidLoop() = task {
let! token = nodeServices.InvokeExportAsync<string>("./read-tag", "read", "tag")

if String.IsNullOrEmpty token then
let! _ = Task.Delay(TimeSpan.FromSeconds 0.5)
()
else
printfn "Read: %s" token
running <- executeTag nodeServices token
printfn "Waiting for remove"
let! _ = nodeServices.InvokeExportAsync<string>("./read-tag", "removed", token)
let! _ = stop nodeServices
()
return! rfidLoop()
}

if isWindows then
()
else
let r = nodeServices.InvokeExportAsync<string>("./read-tag", "read", "tag")
r.Wait()
let token = r.Result
let r = executeTag nodeServices token
r.Wait()

printfn "%A" startupTask.Result
rfidLoop().Wait()

System.Console.ReadKey() |> ignore
2 changes: 1 addition & 1 deletion src/PiServer/PiServer.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<None Update="play-audio.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="play-audiostream.js">
<None Update="read-tag.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="cmdmp3.exe">
Expand Down
59 changes: 16 additions & 43 deletions src/PiServer/read-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,23 @@ const mfrc522 = require("mfrc522-rpi");
//# Init WiringPi with SPI Channel 0
mfrc522.initWiringPi(0);

//# This loop keeps checking for chips. If one is near it will get the UID and authenticate
console.log("scanning...");
console.log("Please put chip or keycard in the antenna inductive zone!");
console.log("Press Ctrl-C to stop.");
exports.read = function (callback, lastTag) {
mfrc522.reset();

let response = mfrc522.findCard();
if (!response.status) {
callback(null, "");
return;
}

exports.read = function (callback, fileName) {
var lastTag = "";
var readInterval = setInterval(function(){
mfrc522.reset();

let response = mfrc522.findCard();
if (!response.status) {
return;
}
//# Get the UID of the card
response = mfrc522.getUid();
if (!response.status) {
console.log("UID Scan Error");
return;
}

clearInterval(readInterval);

//# Get the UID of the card
response = mfrc522.getUid();
if (!response.status) {
console.log("UID Scan Error");
return;
}
//# If we have the UID, continue
const uid = response.data;
var data = uid.map(x => x.toString(16)).join('');
if(lastTag != data) {
lastTag = data;
console.log("Card read UID: %s", data);
callback(null, data);
}
}, 500);
const uid = response.data;
var data = uid.map(x => x.toString(16)).join('');
callback(null, data);
}

exports.removed = function (callback, lastTag) {
var readInterval = setInterval(function(){
mfrc522.reset();

let response = mfrc522.findCard();
if (!response.status) {
clearInterval(readInterval);
callback(null, "");
return;
}
}, 500);
}

0 comments on commit a97663b

Please sign in to comment.