scratchgo

package module
v0.0.0-...-19cb6c9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2015 License: MIT Imports: 7 Imported by: 2

README

Scratchgo

The Remote Sensors Protocol can be used to connect golang to Scratch.

Install Go lang

Refer to golang.org

Install scratchgo

go get github.com/135yshr/scratchgo

Enable Remote Sensor Connections

In your Scratch project, right click on one of the sensor tiles and click "enable remote sensor connections".

New Functions

Scratchub

scratchub is a class that was to be manipulated from Scratch by connecting multiple external devices. (such as Sphero and Hue)

Sample client program

package main

import (
	"fmt"
	"scratchgo"
)

func main() {
	conn, err := scratchgo.NewDefaultConnect()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	defer conn.Close()

	// A global variable is changed
	err := conn.SensorUpdate("intX", "1")
	err = conn.SensorUpdate("intY", "1")

	// A broadcast is sent
	err = conn.BroadCast("update_pos")

	// receive the updated value
	// sensor-update - map[key:value]
	// broadcast - map["command":message]
	msg, err := conn.Recv()
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(*msg) // {sensor-update map[scratch_value:1]}
}

Revistion History

release 1.1

  • Fixed a bug of the sample program

release 1.0

  • Fixed a problem that can not be sent two or more of the parameters.

beta 2.0

  • added a new function scratchub

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hub

type Hub struct {
	Ports []Port
}

func NewHub

func NewHub(ports []Port) *Hub

func (*Hub) Action

func (self *Hub) Action(msg *Message) error

type Message

type Message struct {
	Type      string // sensor-update | broadcast
	Variables map[string]string
}

func ParseMessage

func ParseMessage(message string) *Message

func (*Message) GetNames

func (self *Message) GetNames() []string

type Port

type Port interface {
	Action(*Message) error
}

type RspConn

type RspConn struct {
	net.Conn
}

func NewConnect

func NewConnect(host string, port int) (*RspConn, error)

func NewDefaultConnect

func NewDefaultConnect() (*RspConn, error)

func (*RspConn) BroadCast

func (self *RspConn) BroadCast(value string) error

func (*RspConn) Recv

func (self *RspConn) Recv() (*Message, error)

func (*RspConn) SensorUpdate

func (self *RspConn) SensorUpdate(value map[string]interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL