unicornpaint

A web-based painting app for raspberry PI and pimoroni Unicorn Hat HD
Log | Files | Refs | README

Actions.js (1198B)


      1 const NO_OP = 'NO_OP'
      2 const SET_PIXEL = 'SET_PIXEL'
      3 const CLEAR = 'CLEAR'
      4 const SAVE = 'SAVE'
      5 const LOAD = 'LOAD'
      6 const ADD_FRAME = "ADD_FRAME"
      7 const REMOVE_FRAME = "REMOVE_FRAME"
      8 
      9 function sendAction(websocket, action) {
     10   let actionStr = JSON.stringify(action)
     11   websocket.send(actionStr)
     12 }
     13 
     14 function save(websocket, saveName) {
     15   sendAction(websocket, {
     16     type: SAVE,
     17     saveName: saveName
     18   })
     19 }
     20 
     21 function load(websocket, saveName) {
     22   sendAction(websocket, {
     23     type: LOAD,
     24     saveName: saveName
     25   })
     26 }
     27 
     28 function setPixel(websocket, x, y, r, g, b, frame) {
     29   sendAction(websocket, {
     30     type: SET_PIXEL,
     31     x: x,
     32     y: y,
     33     r: r, 
     34     g: g,
     35     b: b,
     36     frame: frame
     37   })
     38 }
     39 
     40 function clear(websocket) {
     41   sendAction(websocket, { type: CLEAR })
     42 }
     43 
     44 function noop(websocket) {
     45   sendAction(websocket, { type: NO_OP })
     46 }
     47 
     48 function addFrame(websocket, frame = 1, delay = 50) {
     49   sendAction(websocket, { 
     50     type: ADD_FRAME, 
     51     frame: frame, 
     52     delay: delay
     53   })
     54 }
     55 
     56 function removeFrame(websocket, frame = 1) {
     57   sendAction(websocket, {
     58     type: REMOVE_FRAME, 
     59     frame: frame
     60   })
     61 }
     62 
     63 export {
     64     setPixel, 
     65     clear, 
     66     noop,
     67     save,
     68     load,
     69     addFrame,
     70     removeFrame
     71 }