Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Commit

Permalink
Godoc for the package vrpn
Browse files Browse the repository at this point in the history
  • Loading branch information
Laremere committed Oct 3, 2013
1 parent 9cc78c8 commit 521d69e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions vrpn/analog.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,31 @@ import (
"unsafe"
)

//Analog is an analog device on the vrpn server.
type Analog struct {
c unsafe.Pointer
channels int
}

//Creates a new analog device with the given device name, and the number
//of channels which the device transmits.
func (c *Connection) NewAnalog(name string, channels int) *Analog {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return &Analog{C.vrpn_Analog_Web_New(cname, c.c, C.int(channels)), channels}
}

//Updates the values on the analog device. If there are fewer values in
//the slice than channels, only the lower channels are updated; extra
//channels are ignored.
func (a *Analog) Update(data []float64) {
for i := 0; i < len(data) && i < a.channels; i++ {
C.vrpn_Analog_Web_Update(a.c, C.double(data[i]), C.int(i))
}
}

//Mainloop must be called after providing an update to the device and
//before the connection's mainloop is called.
func (a *Analog) Mainloop() {
C.vrpn_Analog_Web_Mainloop(a.c)
}
8 changes: 8 additions & 0 deletions vrpn/button.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ import (
"unsafe"
)

//Button is an button device on the vrpn server.
type Button struct {
c unsafe.Pointer
channels int
}

//Creates a new button device with the given device name, and the number
//of channels which the device transmits.
func (c *Connection) NewButton(name string, channels int) *Button {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return &Button{C.vrpn_Button_Web_New(cname, c.c, C.int(channels)), channels}
}

//Updates the values on the button device. If there are fewer values in
//the slice than channels, only the lower channels are updated; extra
//channels are ignored.
func (b *Button) Update(data []bool) {
for i := 0; i < len(data) && i < b.channels; i++ {
var active C.char = 0
Expand All @@ -33,6 +39,8 @@ func (b *Button) Update(data []bool) {
}
}

//Mainloop must be called after providing an update to the device and
//before the connection's mainloop is called.
func (b *Button) Mainloop() {
C.vrpn_Button_Web_Mainloop(b.c)
}
12 changes: 12 additions & 0 deletions vrpn/connection.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
Package vrpn provides a wrapper around a simple vrpn server.
All types in this package wrap around the required vrpn_wrapper.dll.
It is important to know that objects are created in the C++ side, and
will not be automatically garbage collected, even if the go objects are.
*/
package vrpn

/*
Expand All @@ -11,14 +19,18 @@ import (
"unsafe"
)

//Connection represents a vrpn server.
type Connection struct {
c unsafe.Pointer
}

//Creates a new vrpn server at the given port number.
func NewConnection(port int) *Connection {
return &Connection{C.vrpn_Connection_New(C.int(port))}
}

//Mainloop must be called each loop after each device's main loop in order to
//ensure that vrpn does all it's nessisary transmissions and bookkeeping.
func (c *Connection) Mainloop() {
C.vrpn_Connection_Mainloop(c.c)
}

0 comments on commit 521d69e

Please sign in to comment.