Skip to content

Commit

Permalink
Added convenience method for raw data.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrukh committed Feb 25, 2012
1 parent 942117e commit 467ecb5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/streamer/streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"
)

const SERIAL_PORT = "/dev/tty.MindBand"
const SERIAL_PORT = "/dev/tty.MindBand2"

func main() {
data := make(chan int16)
Expand Down
21 changes: 21 additions & 0 deletions goneuro.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import (
"os"
)

// Approx the number of data points to be
// coming in from the device per second
const WINDOW_SIZE = 512

// MAX_PAYLOAD_LENGTH is the maximum number of
// bytes that can be contained in the payload
// message, not including SYNC, PLENGTH and
Expand Down Expand Up @@ -132,6 +136,23 @@ func Connect(serialPort string, listener *ThinkGearListener) (disconnect chan<-
return
}

// ConnectRaw streams just the raw data on a channel;
// this is provided as a convenience method
func ConnectRaw(serialPort string) (disconnect chan<- bool, data <-chan float64, err error) {
ch := make(chan float64, WINDOW_SIZE)
listener := &ThinkGearListener{
RawSignal: func(a, b byte) {
ch <- float64(int16(a)<<8 | int16(b))
},
}
disconnect, err = Connect(serialPort, listener)
if err != nil {
return
}
data = ch
return
}

// thinkGearParse parses the TG byte stream
func thinkGearParse(device io.ReadCloser, listener *ThinkGearListener, disconnect <-chan bool) {
reader := bufio.NewReader(device)
Expand Down

0 comments on commit 467ecb5

Please sign in to comment.