MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / onReading

Function onReading

examples/drivers/m5stickc-imu/main.js:77–109  ·  view source on GitHub ↗
(values, labelPrefix)

Source from the content-addressed store, hash-verified

75}
76
77function onReading(values, labelPrefix){
78 const { x, y, z } = values;
79 trace(`${labelPrefix}X: ${formatValue(x)} - ${labelPrefix}Y: ${formatValue(y)} - ${labelPrefix}Z: ${formatValue(z)}\n`);
80 render.begin(0, 0, width, ball.yMin);
81 render.fillRectangle(backgroundColor, 0, 0, width, height);
82
83 drawBar(`${labelPrefix}X`, x, 0, 0, width, font.height);
84 drawBar(`${labelPrefix}Y`, y, 0, font.height, width, font.height);
85 drawBar(`${labelPrefix}Z`, z, 0, font.height * 2, width, font.height);
86 render.end();
87
88 ball.vx = (ball.vx + x) * 0.98;
89 ball.vy = (ball.vy - y) * 0.98;
90 let nx = ball.x + ball.vx;
91 let ny = ball.y + ball.vy;
92 if (nx < 0) {
93 nx = -nx;
94 ball.vx = -ball.vx * 0.7;
95 }
96 else if (nx > (width - ball.width)) {
97 nx = width - ball.width;
98 ball.vx = -ball.vx * 0.7;
99 }
100 if (ny < ball.yMin) {
101 ny = ball.yMin;
102 ball.vy = -ball.vy * 0.7;
103 }
104 else if (ny > (height - ball.height)) {
105 ny = height - ball.height;
106 ball.vy = -ball.vy * 0.7;
107 }
108 moveBallTo(nx, ny)
109}
110
111
112function formatValue(value) {

Callers 1

main.jsFile · 0.70

Calls 6

formatValueFunction · 0.70
drawBarFunction · 0.70
moveBallToFunction · 0.70
beginMethod · 0.65
fillRectangleMethod · 0.65
endMethod · 0.65

Tested by

no test coverage detected