Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vinymeuh committed Apr 27, 2019
0 parents commit 92d99bc
Show file tree
Hide file tree
Showing 21 changed files with 1,343 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
.vscode

coverage.out
radiogagad
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: go

go:
- 1.12.x
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 VinyMeuh

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
BINARY=radiogagad

SHELL := $(shell which bash)
ENV = /usr/bin/env

.SHELLFLAGS = -c

.ONESHELL: ;
.NOTPARALLEL: ;
.EXPORT_ALL_VARIABLES:

.PHONY: all
.DEFAULT_GOAL := help

VERSION = `git describe --tags --always`
BUILD = `date +%FT%T%z`

LDFLAGS = -ldflags "-w -s -X main.Version=${VERSION} -X main.Build=${BUILD}"


build: ## Build for current host
go build ${LDFLAGS} -o ${BINARY}

buildarm6: ## Build for Pi Zero
GOOS=linux GOARCH=arm GOARM=6 go build ${LDFLAGS} -o ${BINARY}

buildarm7: ## Build for Pi 3
GOOS=linux GOARCH=arm GOARM=7 go build ${LDFLAGS} -o ${BINARY}

clean: ## Delete binary
rm -f ${BINARY}

coverage: ## Show test coverage
go tool cover -func=coverage.out
go tool cover -html=coverage.out

help: ## Show Help
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

test: ## Run tests
go test -coverprofile=coverage.out ./...
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# radiogagad - the daemon inside my RaspDAC

[![Build Status](https://travis-ci.org/vinymeuh/radiogagad.svg?branch=master)](https://travis-ci.org/vinymeuh/radiogagad)
[![Go Report Card](https://goreportcard.com/badge/github.com/vinymeuh/radiogagad)](https://goreportcard.com/report/github.com/vinymeuh/radiogagad)

## Build and install

First you need a [Go](https://golang.org/dl/) distribution. Then on the build host, targeting a Raspberry Pi 3

```
make buildarm7
```

Install by simply copy the binary under ```/usr/local/bin``` and setup the service for the service manager used by the distribution

* For systemd: [radiogagad.service](https://github.com/vinymeuh/radiogagad/blob/master/radiogagad.service)

## Configuration

Some points are configurables using environment variables

| Variable | Usage | Defaults |
| -------- | ----- | -------- |
| RGGD_MPD_SERVER | mpd server and port to connect to | localhost:6600 |
| RGGD_STARTUP_PLAYLISTS | comma separated list of playlists to be tried to load and play at start-up | |

## Inspirations, links and references

### RaspDAC pinout

![RaspDAC pinout](https://github.com/vinymeuh/radiogagad/blob/master/public/I-SABRE-V3_FR_1_1.jpg)

### Power Button

* [Example implementations from Audiophonics](https://github.com/audiophonics/Raspberry-pwr-management)

### MPD

* [MPD Protocol Specification](https://www.musicpd.org/doc/html/protocol.html)

### Winstar OLED WEH001602A

* [HD44780U Hitachi Datasheet](https://www.sparkfun.com/datasheets/LCD/HD44780.pdf)
* [Winstar_GraphicOLED.py](https://github.com/dhrone/Raspdac-Display/blob/master/Winstar_GraphicOLED.py)
* Wikipedia article for [Hitachi HD44780 LCD controller](https://en.wikipedia.org/wiki/Hitachi_HD44780_LCD_controller)
* [Adafruit_CharacterOLED](https://github.com/ladyada/Adafruit_CharacterOLED)
* [Interfacing 16x2 LCD with Raspberry Pi using GPIO & Python](http://www.rpiblog.com/2012/11/interfacing-16x2-lcd-with-raspberry-pi.html)
122 changes: 122 additions & 0 deletions drivers/winstar/display.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Copyright 2019 VinyMeuh. All rights reserved.
// Use of the source code is governed by a MIT-style license that can be found in the LICENSE file.

// This file contains the public API of the driver
// - the singleton Display (!!no thread safe!!)
// - high level commands to control display and write text
//
// Pinout is hard coded for the I-Sabre V3 DAC from Audiophonics

package winstar

import (
"fmt"
"time"

"periph.io/x/periph/conn/gpio"
"periph.io/x/periph/conn/gpio/gpioreg"
"periph.io/x/periph/host"
)

const (
_RS = "GPIO7"
_ES = "GPIO8"
_DB4 = "GPIO25"
_DB5 = "GPIO24"
_DB6 = "GPIO23"
_DB7 = "GPIO27"
)

// LineNumber is used by WriteAt() to select the line where to write
type LineNumber int

const (
// Line1 to select first line of the display
Line1 LineNumber = iota
// Line2 to select second line of the display
Line2
)

var display *weh001602a

// Display returns the initialized driver
func Display() *weh001602a {
if display == nil {
host.Init()
display = &weh001602a{
rs: gpioreg.ByName(_RS),
es: gpioreg.ByName(_ES),
data: [4]gpio.PinIO{
gpioreg.ByName(_DB4),
gpioreg.ByName(_DB5),
gpioreg.ByName(_DB6),
gpioreg.ByName(_DB7),
},
}
display.initialize()
}
return display
}

/*********************/
/** Display Control **/
/*********************/

// Clear display writes space code 20H into all DDRAM addresses.
// It then sets DDRAM address 0 into the address counter,
// and returns the display to its original status if it was shifted.
func (w *weh001602a) Clear() {
w.sendCommand(instrClearDisplay)
time.Sleep(10 * time.Millisecond)
}

// DisplayOn turns the display on
func (w *weh001602a) DisplayOn() {
w.instrDisplayControl = w.instrDisplayControl | displayOn
fmt.Printf("%-16s %08b (%08b)\n", "DisplayOn", w.instrDisplayControl, displayOn)
w.sendCommand(w.instrDisplayControl)
}

// DisplayOff turns the display off
func (w *weh001602a) DisplayOff() {
w.instrDisplayControl = w.instrDisplayControl & displayOff
fmt.Printf("%-16s %08b (%08b)\n", "DisplayOff", w.instrDisplayControl, displayOff)
w.sendCommand(w.instrDisplayControl)
}

/********************/
/** Cursor Control **/
/********************/

// Return home sets DDRAM address 0 into the address counter,
// and returns the display to its original status if it was shifted.
// The DDRAM contents do not change.
func (w *weh001602a) Home() {
w.sendCommand(instrReturnHome)
//time.Sleep(10 * time.Millisecond)
}

/**********************/
/** Write Characters **/
/**********************/

// Send string to LCD at current position of cursor
func (w *weh001602a) Write(msg string) {
for _, char := range msg {
if char > 255 {
char = 32
}
w.sendData(uint8(char))
}
}

// Send string to LCD at start of one of the lines
func (w *weh001602a) WriteAt(line LineNumber, msg string) {
switch line {
case Line1:
w.sendCommand(addrStartLine1)
case Line2:
w.sendCommand(addrStartLine2)
}
w.Write(msg)
}
1 change: 1 addition & 0 deletions drivers/winstar/drivertest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
drivertest
7 changes: 7 additions & 0 deletions drivers/winstar/drivertest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# radiogagad - test program for the winstar oled driver

Build

```shell
GOOS=linux GOARCH=arm GOARM=7 go build
```
33 changes: 33 additions & 0 deletions drivers/winstar/drivertest/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2019 VinyMeuh. All rights reserved.
// Use of the source code is governed by a MIT-style license that can be found in the LICENSE file.

// Test program for the winstar oled driver
// Build with: GOOS=linux GOARCH=arm GOARM=7 go build

package main

import (
"time"

"github.com/vinymeuh/radiogagad/drivers/winstar"
)

func main() {
lcd := winstar.Display()

lcd.Write("All we hear is radio ga ga")
lcd.WriteAt(winstar.Line2, "Radio goo goo")
time.Sleep(3 * time.Second)

lcd.DisplayOff()
time.Sleep(3 * time.Second)

lcd.Home()
lcd.Clear()
lcd.WriteAt(winstar.Line1, "Don't stop me now")
lcd.WriteAt(winstar.Line2, "Have a good time, good time")
lcd.DisplayOn()
time.Sleep(3 * time.Second)

lcd.DisplayOff()
}
Loading

0 comments on commit 92d99bc

Please sign in to comment.