This commit is contained in:
2024-06-28 04:07:22 -06:00
parent e7bfcd1a78
commit 4da90cf9fe
7 changed files with 77 additions and 30 deletions
+47 -28
View File
@@ -4,7 +4,7 @@ import machine
import utime
import _thread
import math
import os
#import os
# gpio pin to read power analysis off of (int)
@@ -33,6 +33,7 @@ def do_pwm(outpin = 20, duty_cycle = 0.5, frequency = 2000):
pwm_pin.duty_u16(pwm_duty)
print(f"Clock Pulses Running\n\tGPIO Pin: {outpin}\n\tDuty Cycle: {percent_duty}%\n\tFrequency: {frequency}Hz")
# us of sleep calculate4d by floor(1000000 / (frequency_in_Hz * samples_per_pulse))
def us_samples(frequency, samples_per_pulse):
return math.floor(1000000/(frequency*samples_per_pulse))
@@ -53,52 +54,71 @@ def do_adc(adcpin=28, duty_cycle = 0.5, frequency = 2000, samples_per_pulse = 10
# == HTTP Stuff == #
# HTML template for the webpage
def default_webpage():
template = f"""
header = f"""
<!DOCTYPE html>
<html>
<head>
<title>Power Analysis Tool LFGGGGg</title>
<title>SillyFilly Pi Pico Power Analysis Tool (LFFGGGGG)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="preload" href="http://10.0.0.80/ComicCode-Regular.woff2" as="font" type="font/woff2" crossorigin>
<style>
body {{
font-family: 'Comic Code';
font-weight: normal;
font-style: normal;
}}
form, div {{
width: 80%;
margin: auto;
}}
h1 {{
font-size: 1.15em;'
}}
form input[type='number'] {{
width: 3.6em;
}}
</style>
</head>
<body>
<h1>SillyFilly Pi Pico Power Analysis Tool (LFFGGGGG)</h1>
"""
footer = f"""
</body>
</html>
"""
def default_webpage():
template = f"""
{header}
<form action="/action">
<b>Clock Control Config</b><br>
<input id="duty_cycle" name="duty_cycle" type="range" min="0" max="1" step="0.01" value="0.5"> <output id="duty_cycle_output">50%</output> Duty Cycle (% of time clock is on)<br><br>
<input type="number" name="freq" value="2000"> Frequency (Hz aka number of pulses per second)<br><br>
<b>Samplerate Config:</b><br>
<input type="number" id="samples_per_pulse" name="samples_per_pulse" value="5"> Samples Per Manual Clock Pulse<br><br>
<h1>SillyFilly Pi Pico Power Analysis Tool (LFFGGGGG)</h1>
<b>Config:</b><br>
Duty Cycle<br><input id="duty_cycle" name="duty_cycle" type="range" min="0" max="1" step="0.01" value="0.5"> <output id="duty_cycle_output">50%</output><br><br>
Frequency (Hz)<br><input type="number" size="5" name="freq" value="2000"><br><br>
Samples Per Clock Pulse:<br> <input type="number" size="5" id="samples_per_pulse" name="samples_per_pulse" value="5"><br><br>
<input type="submit" value="Go, Baby, Go!">
</form>
<script>
const value = document.querySelector("#duty_cycle_output");
const input = document.querySelector("#duty_cycle");
value.textContent = input.value;
value.textContent = "50%"; // set default for some reason? fuck javascript
input.addEventListener("input", (event) => {{
value.textContent = (event.target.value*100)+"%";
}});
</script>
</body>
</html>
{footer}
"""
return str(template)
# us of sleep calculate4d by floor(1000000 / (frequency_in_Hz * samples_per_pulse))
def running_webpage(outpin = 20, adcpin = 28, duty_cycle = 0.5, frequency = 2000, samples_per_pulse = 100):
dutyy = duty_cycle*100
us_sample = us_samples(frequency, samples_per_pulse)
template = f"""
<!DOCTYPE html>
<html>
<head>
<title>RUNNING - Power Analysis Tool LFGGGGg</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
{header}
<div id="sillyrunninfg">
<h1>SillyFilly Pi Pico Power Analysis Tool (LFFGGGGG)</h1>
<h2>WE RUNNING NOWWWWW LFGGGGGGGGGGGGG</h2>
<p>
@@ -110,8 +130,8 @@ def running_webpage(outpin = 20, adcpin = 28, duty_cycle = 0.5, frequency = 2000
Delay Between Samples: <b>{us_sample}us</b><br><br>
<b>LFGGGGGGGG FRONG</b>
</p>
</body>
</html>
</div>
{footer}
"""
return str(template)
@@ -137,7 +157,6 @@ if wlan.status() != 3:
else:
print('Connection successful!')
network_info = wlan.ifconfig()
#print('IP address:', network_info[0])
print(f"\n\nOpen web browser and navigate to http://{network_info[0]}\n\n")
# Set up socket and start listening
@@ -187,10 +206,10 @@ while True:
response = running_webpage()
else:
else:
response = default_webpage()
# Send the HTTP response and close the connection
# Send the HTTP response and close the conn
conn.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
conn.send(response)
conn.close()