Skip to content

Commit

Permalink
Replace Sk.sense_hat_emit with config.emit
Browse files Browse the repository at this point in the history
Introduce a config object which will be the interface to/from JavaScript.
I used the same pattern for my conversion of Pygal:

trinketapp/pygal.js#12
  • Loading branch information
tuzz committed Jan 9, 2024
1 parent 601fce2 commit 14bbd1f
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions pyodide/packages/_internal_sense_hat.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/**
* Internal SenseHat Module for reading and writing values from
* JavaScript World to the Python World. This modules set ups
* the commmunication and allows to read and write pixels. If the
* "Sk.sense_hat_emit" config is present, we emit events when
* values are changed: Python -> JavaScript
* the commmunication and allows to read and write pixels.
*/

export const config = {
emit: () => {},
};

var $builtinmodule = function (name) {
var mod = {};

Expand All @@ -27,9 +30,7 @@
}

mod.init = new Sk.builtin.func(function () {
if (Sk.sense_hat_emit) {
Sk.sense_hat_emit('init');
}
config.emit('init');
});

// _fb_device specific methods
Expand Down Expand Up @@ -57,9 +58,7 @@
throw new Sk.builtin.ValueError(e.message);
}

if (Sk.sense_hat_emit) {
Sk.sense_hat_emit('setpixel', _index);
}
config.emit('setpixel', _index);
});

mod.getpixel = new Sk.builtin.func(function (index) {
Expand Down Expand Up @@ -92,9 +91,7 @@
throw new Sk.builtin.ValueError(e.message);
}

if (Sk.sense_hat_emit) {
Sk.sense_hat_emit('setpixels', _indexes);
}
config.emit('setpixels', _indexes);
});

mod.getpixels = new Sk.builtin.func(function () {
Expand All @@ -120,19 +117,15 @@
var _gamma = Sk.ffi.remapToJs(gamma);
Sk.sense_hat.gamma = _gamma;

if (Sk.sense_hat_emit) {
Sk.sense_hat_emit('setGamma');
}
config.emit('setGamma');
});

mod.setLowlight = new Sk.builtin.func(function (value) {
var _value = Sk.ffi.remapToJs(value);

Sk.sense_hat.low_light = _value;

if (Sk.sense_hat_emit) {
Sk.sense_hat_emit('changeLowlight', _value);
}
config.emit('changeLowlight', _value);
});

// RTIMU stuff
Expand Down

0 comments on commit 14bbd1f

Please sign in to comment.