MCPcopy Create free account
hub / github.com/SiddhantSilwal/RaspberryPi-GPIO-Web-Controller / init

Function init

AppData/static/js/graph.js:110–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

108 const playBtn = document.getElementById("playBtn");
109
110 function init() {
111 window.addEventListener("resize", resize);
112 resize();
113
114 // Manual Graph trigger
115 document.getElementById("graphBtn").onclick = updateEquation;
116
117 // "ENTER" Key functionality added here
118 eqnInput.onkeydown = (e) => {
119 if (e.key === "Enter") {
120 updateEquation();
121 eqnInput.blur(); // Remove focus so graph is the priority
122 }
123 };
124
125 document.getElementById("resetBtn").onclick = () => {
126 state.scanPos = 0;
127 updateEquation();
128 };
129 document.getElementById("exampleSelect").onchange = (e) => {
130 eqnInput.value = e.target.value;
131 updateEquation();
132 };
133 playBtn.onclick = () => {
134 state.isScanning = !state.isScanning;
135 playBtn.innerText = state.isScanning ? "Pause" : "Play";
136 };
137
138 let isDragging = false;
139 const handleDial = (e) => {
140 if (!isDragging) return;
141 const rect = speedDial.getBoundingClientRect();
142 const clientY = e.touches ? e.touches[0].clientY : e.clientY;
143 const val = Math.max(
144 MIN_PWM_HZ,
145 Math.min(
146 MAX_PWM_HZ,
147 state.scanFreq + (rect.top + rect.height / 2 - clientY) * 0.05,
148 ),
149 );
150 setFreq(val);
151 };
152 speedDial.onmousedown = speedDial.ontouchstart = () =>
153 (isDragging = true);
154 window.onmouseup = window.ontouchend = () => (isDragging = false);
155 window.onmousemove = window.ontouchmove = handleDial;
156 speedInput.onchange = (e) => setFreq(parseFloat(e.target.value));
157
158 eqnInput.value = state.eq;
159 setFreq(1.0);
160 updateEquation();
161 requestAnimationFrame(animate);
162 }
163
164 function setFreq(v) {
165 state.scanFreq = Math.max(MIN_PWM_HZ, Math.min(MAX_PWM_HZ, v || 0));

Callers 1

graph.jsFile · 0.85

Calls 3

resizeFunction · 0.85
updateEquationFunction · 0.85
setFreqFunction · 0.85

Tested by

no test coverage detected