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

Function onReading

examples/drivers/m5stack-imu/main.js:100–132  ·  view source on GitHub ↗
(values, labelPrefix)

Source from the content-addressed store, hash-verified

98}
99
100function onReading(values, labelPrefix){
101 let { x, y, z } = values;
102
103 render.begin(0, 0, width, ball.yMin);
104 render.fillRectangle(backgroundColor, 0, 0, width, height);
105
106 drawBar(labelPrefix + "X", x, 0, 0, width, font.height);
107 drawBar(labelPrefix + "Y", y, 0, font.height, width, font.height);
108 drawBar(labelPrefix + "Z", z, 0, font.height * 2, width, font.height);
109 render.end();
110
111 ball.vx = (ball.vx - y) * 0.98;
112 ball.vy = (ball.vy + x) * 0.98;
113 let nx = ball.x + ball.vx;
114 let ny = ball.y + ball.vy;
115 if (nx < 0) {
116 nx = -nx;
117 ball.vx = -ball.vx;
118 }
119 else if (nx > (width - ball.width)) {
120 nx = width - ball.width;
121 ball.vx = -ball.vx;
122 }
123 if (ny < ball.yMin) {
124 ny = ball.yMin;
125 ball.vy = -ball.vy;
126 }
127 else if (ny > (height - ball.height)) {
128 ny = height - ball.height;
129 ball.vy = -ball.vy;
130 }
131 moveBallTo(nx, ny)
132}
133
134
135function formatValue(value) {

Callers 1

main.jsFile · 0.70

Calls 5

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

Tested by

no test coverage detected