Skip to content

Instantly share code, notes, and snippets.

@iainnash
Created February 14, 2020 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iainnash/ba462d5b3bca730122d59965b9cb7591 to your computer and use it in GitHub Desktop.
Save iainnash/ba462d5b3bca730122d59965b9cb7591 to your computer and use it in GitHub Desktop.
let Max2719SPI = {
_create: ffi("void *mgos_max7219_create(void *, int)"),
_set_devices: ffi("bool mgos_max7219_set_num_devices(void *, int)"),
_set_mode: ffi("bool mgos_max7219_set_mode(void *, bool)"),
_write_digit: ffi("bool mgos_max7219_write_digit(void *, int, int, int)"),
create: function(spi) {
let obj = Object.create(Max2719SPI._proto);
obj.driver = Max2719SPI._create(spi.spi);
return driver;
},
_proto: {
setDevices: function(number) {
return Max2719SPI._set_devices(this.driver, number);
},
setMode: function(isRaw) {
return Max2719SPI._set_mode(this.driver, !isRaw);
},
writeDigit: function(digit, value, device) {
if (!device) {
device = 0;
}
return Max2719SPI._write_digit(this.driver, device, digit, value);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment