pixelit

package module
v0.0.0-...-99b7a08 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2023 License: MIT Imports: 10 Imported by: 0

README

PixelIt CLI

Status GitHub tag (latest SemVer) GitHub GoDoc Go Report Card

PixelIt is an ESP8266/ESP32 and WS2812B LED Matrix based PixelArt display

You can find details for the project on their documentation page or their github repository

The project supports an HTTP REST-based interface; an MQTT interface; and has a node-red node for interactivity.

This repository contains two additional components for use with that PixelIt Matrix Display:

Note: It is still a work in progress.

Command Line Interface (CLI)

cli

Features

The CLI currently provides the ability to send the following supported screens to your PixelIt display:

  • Clock - currently only default options (more options to come)
  • Text - currently text only (more options to come)
  • Bitmap - currently only default bitmap (more options to come)
  • Social - see below

The social command currently supports the following sub-commands in order to display follower counts for the supplied username:

  • Instagram - send follow count for given instagram username
  • TikTok - send follow count for given tiktok username
Installation

You can get started with the CLI by downloading an executable for your platform from the releases page.

Alternatively if you have Go installed, you can use the following command to get started:

$ go install github.com/darrenparkinson/pixelit-go/cmd/pixelit-cli
Usage

You can get help with the CLI by using the --help option:

$ pixelit-cli --help

PixelIt CLI is used to interact with the PixelIt API.

Usage:
  pixelit-cli [command]

Available Commands:
  bitmap      Send a bitmap to PixelIt by ID or as data
  clock       Send a clock to PixelIt
  help        Help about any command
  serve       Read configuration and perform timed actions
  social      Send social network follower counts to PixelIt
  text        Send text to PixelIt

Flags:
      --config string   config file (default $HOME/.pixelit.json)
  -h, --help            help for pixelit-cli
      --host string     host name or ip of your PixelIt (default "192.168.86.25")
  -v, --verbose         provide verbose output
      --version         version for pixelit-cli

Use "pixelit-cli [command] --help" for more information about a command.

You are then able to run commands such as the following:

  • Send a standard clock:
$ ./pixelit-cli clock
  • Send bitmap by ID:
$ ./pixelit-cli bitmap --id 878
  • Send text:
$ ./pixelit-cli text "PixelIt is Awesome!"
  • Send instagram follower count for apple:
$ ./pixelit-cli social instagram --username apple 
  • Send tiktok follower count for apple
$ ./pixelit-cli social tiktok --username apple 

Go Library

The Go library currently provides the ability to send any screen type to your PixelIt, along with some helper functions that support the CLI.

Usage

You can install the library in the usual way as follows:

$ go get github.com/darrenparkinson/pixelit-go

In your code, import the library:

import "github.com/darrenparkinson/pixelit-go"

You can then construct a new PixelIt client, and use the various methods on the client to access different parts of the API. For example:

pxc, _ := pixelit.NewClient("192.168.86.25", nil)
pxc.SendInstagramFollowers(username)

You can also send raw "Screens" to your PixelIt which should cover all the options you need, e.g.:

pxc, _ := pixelit.NewClient("192.168.86.25", nil)
s := pixelit.Screen{
		Clock: &pixelit.Clock{
			Show:         pixelit.Bool(true),
			SwitchAktiv:  pixelit.Bool(true),
			WithSeconds:  pixelit.Bool(false),
			SwitchSec:    pixelit.Int(7),
			DrawWeekDays: pixelit.Bool(true),
			Color: &pixelit.Color{
				R: 255,
				G: 255,
				B: 255,
			},
		},
	}
	pxc.SendScreen(&s)

See the go docs to see all available fields.

You will notice the use of some helper functions, such as pixelit.Bool and pixelit.Int. These allow distinguishing between unset fields and those set to a zero value. This can cause challenges when retrieving fields since you may encounter a panic if you access a nil pointer. Clearly this isn't a very nice user experience, so where appropriate, "getter" accessor functions are generated automatically for structs with pointer fields to enable you to safely retrieve values:

clock := s.GetClock()

TODO

  • Add configuration options for clock command
  • Add configuration options for bitmap command
  • Add configuration options for text command
  • Add options to send text with bitmap

Documentation

Overview

Package pixelit provides a client for using the PixelIt API.

Usage:

import "github.com/darrenparkinson/pixelit-go"

client := pixelit.NewClient(host, nil)

Copyright 2021 The pixelit-go AUTHORS. All rights reserved.

Use of this source code is governed by an MIT-style license that can be found in the LICENSE file. Code generated by gen-accessors; DO NOT EDIT.

Index

Constants

View Source
const (
	ErrBadRequest    = Err("pixelit: bad request")
	ErrUnauthorized  = Err("pixelit: unauthorized request")
	ErrForbidden     = Err("pixelit: forbidden")
	ErrNotFound      = Err("pixelit: not found")
	ErrInternalError = Err("pixelit: internal error")
	ErrUnknown       = Err("pixelit: unexpected error occurred")
)

Error Constants

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func Float64

func Float64(v float64) *float64

Float64 is a helper routine that allocates a new Float64 value to store v and returns a pointer to it.

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int value to store v and returns a pointer to it.

func Int64

func Int64(v int64) *int64

Int64 is a helper routine that allocates a new int64 value to store v and returns a pointer to it.

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

Types

type Bitmap

type Bitmap struct {
	Data     []int     `json:"data,omitempty"`     // Required
	Position *Position `json:"position,omitempty"` // Required
	Size     *Size     `json:"size,omitempty"`     // Required
}

func (*Bitmap) GetPosition

func (b *Bitmap) GetPosition() *Position

GetPosition returns the Position field.

func (*Bitmap) GetSize

func (b *Bitmap) GetSize() *Size

GetSize returns the Size field.

type BitmapAnimation

type BitmapAnimation struct {
	Data           [][]int `json:"data"`           //Required. Only 8x8 BMPs are supported here!
	AnimationDelay int     `json:"animationDelay"` // Required. Higher is a slower animation
	Rubberbanding  bool    `json:"rubberbanding"`  // Should the animation run back and forth
	LimitLoops     int     `json:"limitLoops"`     // If the repetition is to be limited
}

type Client

type Client struct {
	// BaseURL for PixelIt Display.  Set using `pixelit.NewClient()` automatically via the host parameter, or set directly.
	BaseURL string

	// Host IP for PixelIt Display.  Set using `pixelit.NewClient()`, or set directly.
	Host string

	//HTTP Client to use for making requests, allowing the user to supply their own if required.
	HTTPClient *http.Client
}

Client is the main pixelit client for interacting with the library. It can be created using NewClient

func NewClient

func NewClient(host string, client *http.Client) (*Client, error)

NewClient is a helper function that returns a new pixelit client given a host name or IP. Optionally you can provide your own http client or use nil to use the default. This is done to ensure you're aware of the decision you're making to not provide your own http client.

func (*Client) SendClock

func (c *Client) SendClock() error

func (*Client) SendInstagramFollowers

func (c *Client) SendInstagramFollowers(username string) error

func (*Client) SendScreen

func (c *Client) SendScreen(screen *Screen) error

func (*Client) SendText

func (c *Client) SendText(text string) error

func (*Client) SendTiktokFollowers

func (c *Client) SendTiktokFollowers(username string) error

type Clock

type Clock struct {
	Show         *bool  `json:"show,omitempty"`         // Required
	SwitchAktiv  *bool  `json:"switchAktiv,omitempty"`  // Switch clock / date
	WithSeconds  *bool  `json:"withSeconds,omitempty"`  // Show seconds
	SwitchSec    *int   `json:"switchSec,omitempty"`    // Switch clock / date in seconds. Required when SwitchAktiv is true
	DrawWeekDays *bool  `json:"drawWeekDays,omitempty"` // Draw weekday blocks at the bottom
	Color        *Color `json:"color,omitempty"`        // Color of clock
	HexColor     string `json:"hexColor,omitempty"`     // Alternative to Color, e.g. #FFFFFF
}

func (*Clock) GetColor

func (c *Clock) GetColor() *Color

GetColor returns the Color field.

func (*Clock) GetDrawWeekDays

func (c *Clock) GetDrawWeekDays() bool

GetDrawWeekDays returns the DrawWeekDays field if it's non-nil, zero value otherwise.

func (*Clock) GetShow

func (c *Clock) GetShow() bool

GetShow returns the Show field if it's non-nil, zero value otherwise.

func (*Clock) GetSwitchAktiv

func (c *Clock) GetSwitchAktiv() bool

GetSwitchAktiv returns the SwitchAktiv field if it's non-nil, zero value otherwise.

func (*Clock) GetSwitchSec

func (c *Clock) GetSwitchSec() int

GetSwitchSec returns the SwitchSec field if it's non-nil, zero value otherwise.

func (*Clock) GetWithSeconds

func (c *Clock) GetWithSeconds() bool

GetWithSeconds returns the WithSeconds field if it's non-nil, zero value otherwise.

type Color

type Color struct {
	R int `json:"r"`
	G int `json:"g"`
	B int `json:"b"`
}

type Err

type Err string

Err implements the error interface so we can have constant errors.

func (Err) Error

func (e Err) Error() string

type Position

type Position struct {
	X int `json:"x"`
	Y int `json:"y"`
}

type Screen

type Screen struct {
	SleepMode       *bool            `json:"sleepMode,omitempty"`
	Brightness      *bool            `json:"brightness,omitempty"`
	Text            *Text            `json:"text,omitempty"`
	SwitchAnimation *SwitchAnimation `json:"switchAnimation,omitempty"`
	Clock           *Clock           `json:"clock,omitempty"`
	Bitmap          *Bitmap          `json:"bitmap,omitempty"`
	Bitmaps         []Bitmap         `json:"bitmaps,omitempty"` // When displaying multiple bitmaps, animated bitmaps, scrolling or text are not supported!
	BitmapAnimation *BitmapAnimation `json:"bitmapAnimation,omitempty"`
}

func (*Screen) GetBitmap

func (s *Screen) GetBitmap() *Bitmap

GetBitmap returns the Bitmap field.

func (*Screen) GetBitmapAnimation

func (s *Screen) GetBitmapAnimation() *BitmapAnimation

GetBitmapAnimation returns the BitmapAnimation field.

func (*Screen) GetBrightness

func (s *Screen) GetBrightness() bool

GetBrightness returns the Brightness field if it's non-nil, zero value otherwise.

func (*Screen) GetClock

func (s *Screen) GetClock() *Clock

GetClock returns the Clock field.

func (*Screen) GetSleepMode

func (s *Screen) GetSleepMode() bool

GetSleepMode returns the SleepMode field if it's non-nil, zero value otherwise.

func (*Screen) GetSwitchAnimation

func (s *Screen) GetSwitchAnimation() *SwitchAnimation

GetSwitchAnimation returns the SwitchAnimation field.

func (*Screen) GetText

func (s *Screen) GetText() *Text

GetText returns the Text field.

type Size

type Size struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

type SwitchAnimation

type SwitchAnimation struct {
	Aktiv     *bool   `json:"aktiv,omitempty"`
	Animation *string `json:"animation,omitempty"`
	Data      *[]int  `json:"data,omitempty"`
	Width     *int    `json:"width,omitempty"`
}

func (*SwitchAnimation) GetAktiv

func (s *SwitchAnimation) GetAktiv() bool

GetAktiv returns the Aktiv field if it's non-nil, zero value otherwise.

func (*SwitchAnimation) GetAnimation

func (s *SwitchAnimation) GetAnimation() string

GetAnimation returns the Animation field if it's non-nil, zero value otherwise.

func (*SwitchAnimation) GetData

func (s *SwitchAnimation) GetData() []int

GetData returns the Data field if it's non-nil, zero value otherwise.

func (*SwitchAnimation) GetWidth

func (s *SwitchAnimation) GetWidth() int

GetWidth returns the Width field if it's non-nil, zero value otherwise.

type Text

type Text struct {
	TextString      *string   `json:"textString,omitempty"`      // Required. Displayed Text.
	BigFont         *bool     `json:"bigFont,omitempty"`         // Required. Big Font.
	CenterText      *bool     `json:"centerText,omitempty"`      // Required.
	ScrollText      *string   `json:"scrollText,omitempty"`      // One of true, false or auto.
	ScrollTextDelay *int      `json:"scrollTextDelay,omitempty"` // Required if ScrollText is set. 1-9999.
	Position        *Position `json:"position,omitempty"`        // Required.
	Color           *Color    `json:"color,omitempty"`           // Required unless hex color specified.
	HexColor        *string   `json:"hexColor,omitempty"`        // Alternative to Color.
}

func (*Text) GetBigFont

func (t *Text) GetBigFont() bool

GetBigFont returns the BigFont field if it's non-nil, zero value otherwise.

func (*Text) GetCenterText

func (t *Text) GetCenterText() bool

GetCenterText returns the CenterText field if it's non-nil, zero value otherwise.

func (*Text) GetColor

func (t *Text) GetColor() *Color

GetColor returns the Color field.

func (*Text) GetHexColor

func (t *Text) GetHexColor() string

GetHexColor returns the HexColor field if it's non-nil, zero value otherwise.

func (*Text) GetPosition

func (t *Text) GetPosition() *Position

GetPosition returns the Position field.

func (*Text) GetScrollText

func (t *Text) GetScrollText() string

GetScrollText returns the ScrollText field if it's non-nil, zero value otherwise.

func (*Text) GetScrollTextDelay

func (t *Text) GetScrollTextDelay() int

GetScrollTextDelay returns the ScrollTextDelay field if it's non-nil, zero value otherwise.

func (*Text) GetTextString

func (t *Text) GetTextString() string

GetTextString returns the TextString field if it's non-nil, zero value otherwise.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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