Last-Fi

1,272 views
1,164 views

Published on

Last-Fi - an F# powered Raspberry Pi internet radio

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,272
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
7
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • BCM2835 - 700mhz ARM chip, and VideoCore, 1080p HD Encode / Decode. 512mb.
  • Last-Fi

    1. 1. Last-FI Ross McKinlay 2013
    2. 2. Me @pezi_pink www.pinksquirrellabs.com
    3. 3. fsharp.org
    4. 4. Last-Fi!
    5. 5. Raspberry Pi & F# • You want the SOFT float version of the Raspbian Linux distro! Save yourself lots of headaches! • Fully update your Pi (apt-get update, apt-get upgrade) • Ensure the SSH server starts when your Pi boots • apt-get mono-complete • Develop your projects on another machine, and use WinSCP / PuTTY (or similar) to transfer
    6. 6. Access to the GPIO pins http://www.airspayce.com/mikem/bcm2835/ # tar -zxf bcm2835-1.3.tar.gz # cd bcm2835-1.3/src # make libbcm2835.a # cc -shared bcm2835.o -o libbcm2835.so • You will need to download and build the bcm2835 library on the Pi which will enable you to access the pins • In order to interop with .NET / Mono you must use a shared object (so) against a statically linked binary. • You are now able to reference the .so file like any normal .dll file for interop using the [<DllImport>] attribute
    7. 7. LCD Screen! • Almost all these displays use the Hitachi HD44780 LCD Controller • Can be operated in 8 bit or 4 bit mode and either way they take up a ton of IO pins ! • After the initialization, the general usage is to shift a bunch of bits onto the data lines that will instruct the LCD what do to, then pulse the E line to indicate it should look at and act on the data. • Reading and writing data is almost identical except you hold the RS line high between writing text in ASCII binary
    8. 8. LCD Screen!
    9. 9. LCD Screen! • Using agents to isolate state and provide timing. It’s a self contained async system that can only be changed via safe messaging • Messing about with low-level timing and bit shifting • Cunning use of TryReceive to provide overrideable temporary text and text scrolling
    10. 10. NES Pad! • A NES pad is nothing more than a 8-bit parallel to serial shift register! • Simply hold LATCH low (Write/Shift in this diagram) and then each successive pulse on the CLOCK line will shift the state of the next button onto the DATA line (Q in this diagram)
    11. 11. NES Pad! • Low-Level signal manipulation • Reading values using functional techniques such as list folding • Isolating state and providing safe asynchronous operation for both manual and interval polling via message passing • Use of active patterns to determine internal state • Using first-class events to trigger on patterns • Use of active patterns to provide the consumer an elegant way of expressing the matching of button depressing, depress durations and history sequence
    12. 12. Last.Fm API • Unfortunately does not have any metadata associated with it such as a WSDL or an Odata endpoint which means I cannot use a type provider ! :’( Boo, Hiss • There are .NET libraries consisting of large object hierarchies to access Last.Fm but I’m only interested in small portion of the API and don’t really want to use one of these…
    13. 13. MPC / MPD and the “Player” • Music Player Deamon is the linux software I am using to play the music. It is capable of streaming from an internet address. • MPC is the command-line interface to the deamon which allows control via the command line • The “Player” object provides access to the user’s Last.Fm station via MPC and raises events to show stuff that’s happening
    14. 14. The core program… • ServiceStack is used to host a webservice that can provide information about what’s playing and perform some control functions, via the Player object • NES / LCD /Player objects are initalized and various events hooked up between them • GO!! Everything at this point is async, the main program thread just sits there doing nothing (and more importantly, not blockng anything!)
    15. 15. The Website! • The website uses Funscript, which is a F# to JavaScript compiler and a TypeScript type provider that allows direct access to JS libraries with F# code • Funscript also hosts its own webserver, so I don’t need to mess about with ASP.NET linux equivalents

    ×