/
Neopixel.jun
99 lines (81 loc) · 3.79 KB
/
Neopixel.jun
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
module Neopixel
open(Prelude)
include("<Adafruit_NeoPixel.h>")
type neoPixelStrip = { ptr : pointer }
type color = { r : uint8; g : uint8; b : uint8; w : uint8 }
fun make(numPixels : uint16, pinNumber : uint8, neoPixelType : uint16) : neoPixelStrip = (
let p = null;
#p.set((void*) new Adafruit_NeoPixel(numPixels, pinNumber, neoPixelType));#;
neoPixelStrip { ptr = p }
)
fun setPixelColor(n : uint16, c : color, strip : neoPixelStrip) : unit = (
let p = strip.ptr;
let r = c.r;
let g = c.g;
let b = c.b;
let w = c.w;
#((Adafruit_NeoPixel*) p.get())->setPixelColor(n, r, g, b, w);#
)
fun makeColor(r : uint8, g : uint8, b : uint8) : color =
color {r = r; g = g; b = b; w = 0}
fun getPixelColor(n : uint16, strip : neoPixelStrip) : color = (
let numRep : uint32 = 0;
let p = strip.ptr;
#numRep = ((Adafruit_NeoPixel*) p.get())->getPixelColor(n);#;
color { r = numRep >>> 16; g = numRep >>> 8; b = numRep; w = 0 }
)
fun setBrightness(level : uint8, strip : neoPixelStrip) : unit = (
let p = strip.ptr;
#((Adafruit_NeoPixel*) p.get())->setBrightness(level);#)
fun getBrightness(strip : neoPixelStrip) : uint8 = (
let ret : uint8 = 0;
let p = strip.ptr;
#ret = ((Adafruit_NeoPixel*) p.get())->getBrightness();#;
ret
)
fun begin(strip : neoPixelStrip) : unit = (
let p = strip.ptr;
#((Adafruit_NeoPixel*) p.get())->begin();#)
fun show(strip : neoPixelStrip) : unit = (
let p = strip.ptr;
#((Adafruit_NeoPixel*) p.get())->show();#)
fun clear(strip : neoPixelStrip) : unit = (
let p = strip.ptr;
#((Adafruit_NeoPixel*) p.get())->clear();#)
fun canShow(strip : neoPixelStrip) : bool = (
let p = strip.ptr;
let ret = false;
#ret = ((Adafruit_NeoPixel*) p.get())->canShow();#;
ret
)
let RGB : uint16 = (let ret : uint16 = 0; #ret = NEO_RGB;#; ret)
let RBG : uint16 = (let ret : uint16 = 0; #ret = NEO_RBG;#; ret)
let GRB : uint16 = (let ret : uint16 = 0; #ret = NEO_GRB;#; ret)
let GBR : uint16 = (let ret : uint16 = 0; #ret = NEO_GBR;#; ret)
let BRG : uint16 = (let ret : uint16 = 0; #ret = NEO_BRG;#; ret)
let BGR : uint16 = (let ret : uint16 = 0; #ret = NEO_BGR;#; ret)
let WRGB : uint16 = (let ret : uint16 = 0; #ret = NEO_WRGB;#; ret)
let WRBG : uint16 = (let ret : uint16 = 0; #ret = NEO_WRBG;#; ret)
let WGRB : uint16 = (let ret : uint16 = 0; #ret = NEO_WGRB;#; ret)
let WGBR : uint16 = (let ret : uint16 = 0; #ret = NEO_WGBR;#; ret)
let WBRG : uint16 = (let ret : uint16 = 0; #ret = NEO_WBRG;#; ret)
let WBGR : uint16 = (let ret : uint16 = 0; #ret = NEO_WBGR;#; ret)
let RWGB : uint16 = (let ret : uint16 = 0; #ret = NEO_RWGB;#; ret)
let RWBG : uint16 = (let ret : uint16 = 0; #ret = NEO_RWBG;#; ret)
let RGWB : uint16 = (let ret : uint16 = 0; #ret = NEO_RGWB;#; ret)
let RGBW : uint16 = (let ret : uint16 = 0; #ret = NEO_RGBW;#; ret)
let RBWG : uint16 = (let ret : uint16 = 0; #ret = NEO_RBWG;#; ret)
let RBGW : uint16 = (let ret : uint16 = 0; #ret = NEO_RBGW;#; ret)
let GWRB : uint16 = (let ret : uint16 = 0; #ret = NEO_GWRB;#; ret)
let GWBR : uint16 = (let ret : uint16 = 0; #ret = NEO_GWBR;#; ret)
let GRWB : uint16 = (let ret : uint16 = 0; #ret = NEO_GRWB;#; ret)
let GRBW : uint16 = (let ret : uint16 = 0; #ret = NEO_GRBW;#; ret)
let GBWR : uint16 = (let ret : uint16 = 0; #ret = NEO_GBWR;#; ret)
let GBRW : uint16 = (let ret : uint16 = 0; #ret = NEO_GBRW;#; ret)
let BWRG : uint16 = (let ret : uint16 = 0; #ret = NEO_BWRG;#; ret)
let BWGR : uint16 = (let ret : uint16 = 0; #ret = NEO_BWGR;#; ret)
let BRWG : uint16 = (let ret : uint16 = 0; #ret = NEO_BRWG;#; ret)
let BRGW : uint16 = (let ret : uint16 = 0; #ret = NEO_BRGW;#; ret)
let BGWR : uint16 = (let ret : uint16 = 0; #ret = NEO_BGWR;#; ret)
let BGRW : uint16 = (let ret : uint16 = 0; #ret = NEO_BGRW;#; ret)
let KHZ800 : uint16 = (let ret : uint16 = 0; #ret = NEO_KHZ800;#; ret)