Code Monkey home page Code Monkey logo

go-opc's Introduction

   __     ___              ___   _____     ___   
 /'_ `\  / __`\  _______  / __`\/\ '__`\  /'___\ 
/\ \L\ \/\ \L\ \/\______\/\ \L\ \ \ \L\ \/\ \__/ 
\ \____ \ \____/\/______/\ \____/\ \ ,__/\ \____\
 \/___L\ \/___/           \/___/  \ \ \/  \/____/
   /\____/                         \ \_\         
   \_/__/                           \/_/         

Build Status

what

A golang implementation of the Open Pixel Control protocol.

open pixel control

Open Pixel Control is a protocol that is used to control arrays of RGB lights like Total Control Lighting (http://www.coolneon.com/) and Fadecandy devices (https://github.com/scanlime/fadecandy).

documentation

You can read the documentation here: (http://godoc.org/github.com/kellydunn/go-opc)

usage

package main

import("github.com/kellydunn/go-opc")

func main {
     // Setup a new server
     s := opc.NewServer()

     // Register your devices (where r is an implementation of opc.Device)
     s.RegisterDevice(r)

     // Listen for incoming messages and serve them accordingly
     go s.ListenOnPort("tcp", "7890")
     go s.Process()

     // Create a client
     c := opc.NewClient("tcp", "localhost:7890")

     // Make a message!
     // This creates a message to send on channel 0
     // Or according to the OPC spec, a Broadcast Message.
     m := opc.NewMessage(0)  

     // Set pixel #1 to white.
     m.SetPixelColors(1, 255, 255, 255)
     
     // Send the message!
     c.Send(m)

     // The first pixel of all registered devices should be white!
}    

design

The applications of OPC are not currently tied to any single communication model, and it is currently unclear if there is any canonical method of dispatching OPC messages. So, when using this library, it is encouraged to implement the opc.Device interface such that you can further define the details of your devices and how they should be written to.

A very simple implementation of the opc.Device interface could be the following:

type DummyDevice struct {
     conn net.Conn
     channel uint8
}

// Simple write behavior.  Write the OPC Message over a network connection.
func (d *DummyDevice) Write(m *opc.Message) error {
     _, err := conn.Write(m.byteArray)
     if err != nil {
        return err
     }
     
     return nil
}

// Simple Channel getter.  Return the channel in which to associate this device.
func (d *DummyDevice) Channel() uint8 {
     return channel
}

Here's a video of go-opc interacting with the default OPC client provided by openpixelcontrol.org : (https://vine.co/v/hIqiZewthIh)

related work

go-opc's People

Contributors

evq avatar kellydunn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.