From d3a9a3e4675a88b0a36d1d0c779241bb029d90df Mon Sep 17 00:00:00 2001 From: eljamm <83901271+eljamm@users.noreply.github.com> Date: Mon, 13 Nov 2023 03:13:21 +0100 Subject: [PATCH] Fixes and Improvements --- app/asgi.py | 8 +- raspberry/raspi/sensors/__init__.py | 3 +- raspberry/raspi/sensors/distance.py | 37 +- raspberry/raspi/utils/utils.py | 15 +- raspberry/ws_control.py | 17 +- sensor/consumers.py | 60 +- .../static/sensor/css/sensor/ultrasonic.css | 106 +++ .../sensor/css/sensor/ultrasonic.css.map | 1 + .../sensor/images/wiring/pins/ultrasonic.svg | 828 +++++++++--------- sensor/static/sensor/js/sensors/ultrasonic.js | 78 ++ .../static/sensor/scss/sensor/ultrasonic.scss | 82 ++ .../templates/sensor/sensors/ultrasonic.html | 13 + sensor/views.py | 4 +- 13 files changed, 793 insertions(+), 459 deletions(-) create mode 100644 sensor/static/sensor/css/sensor/ultrasonic.css create mode 100644 sensor/static/sensor/css/sensor/ultrasonic.css.map create mode 100644 sensor/static/sensor/js/sensors/ultrasonic.js create mode 100644 sensor/static/sensor/scss/sensor/ultrasonic.scss diff --git a/app/asgi.py b/app/asgi.py index 096a334..a9daff9 100644 --- a/app/asgi.py +++ b/app/asgi.py @@ -7,6 +7,7 @@ https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/ """ +import sensor.routing import os from channels.auth import AuthMiddlewareStack @@ -19,15 +20,14 @@ django_asgi_app = get_asgi_application() -import sensor.routing application = ProtocolTypeRouter({ - "http": django_asgi_app, - "websocket": AllowedHostsOriginValidator( + "http": django_asgi_app, + "websocket": AllowedHostsOriginValidator( AuthMiddlewareStack( URLRouter( sensor.routing.websocket_urlpatterns ) ) ), -}) \ No newline at end of file +}) diff --git a/raspberry/raspi/sensors/__init__.py b/raspberry/raspi/sensors/__init__.py index 1e99560..6df2210 100644 --- a/raspberry/raspi/sensors/__init__.py +++ b/raspberry/raspi/sensors/__init__.py @@ -6,4 +6,5 @@ from .ledmatrix import Matrix from .buzzer import Buzzer from .segment import Segment -from .relay import Relay \ No newline at end of file +from .relay import Relay +from .distance import Ultrasonic diff --git a/raspberry/raspi/sensors/distance.py b/raspberry/raspi/sensors/distance.py index fb2e37b..a72f055 100644 --- a/raspberry/raspi/sensors/distance.py +++ b/raspberry/raspi/sensors/distance.py @@ -1,34 +1,34 @@ -# WORK IN PROGRESS - import json import logging from time import sleep from gpiozero import DistanceSensor -from gpiozero.pins.pigpio import PiGPIOFactory -class Ultrasound: - def __init__(self, pins, pin_factory=PiGPIOFactory(), - setup=False): +class Ultrasonic: + def __init__(self, pins, setup=False): self.echo = pins["E"] self.trigger = pins["T"] - self.pin_factory = pin_factory if setup: self.setup() def setup(self): - self.device = DistanceSensor( - echo=self.echo, trigger=self.trigger, pin_factory=self.pin_factory) + self.device = DistanceSensor(echo=self.echo, trigger=self.trigger) + + def cleanup(self): + self.device.close() def read(self): - data = sensor.distance*100 + distance = self.device.distance*100 + + message = "Distance: {:.1f} cm".format(distance) json_file = { "sensor": "ultrasonic", - "message": data, + "message": message, "message_type": "data", + "distance": distance } return json_file @@ -54,10 +54,13 @@ def process(self, ws, delay): "E": 17 } - sensor = Ultrasound(pins) - - sensor.wait_for_active() + sensor = Ultrasonic(pins, setup=True) - while True: - print('Distance: ', sensor.distance * 100) - sleep(1) + try: + while True: + distance = sensor.device.distance*100 + print('Distance: ', "Distance: {:.1f} cm".format(distance)) + sleep(1) + except KeyboardInterrupt: + sensor.cleanup() + print("\nQuitting Program") diff --git a/raspberry/raspi/utils/utils.py b/raspberry/raspi/utils/utils.py index ffda60f..01794bf 100644 --- a/raspberry/raspi/utils/utils.py +++ b/raspberry/raspi/utils/utils.py @@ -13,7 +13,7 @@ async def async_receive(ws): def run(sensor, pi): (logger, dht11, mat8x8, dpad, array_led, - lcd, joystick, buzzer, segment, relay) = pi.sensors + lcd, joystick, buzzer, segment, relay, ultra) = pi.sensors # --- Sensor Regex --- # sensor_is_dht = re.search(".*dht11-.*", sensor) @@ -24,6 +24,7 @@ def run(sensor, pi): sensor_is_buz = re.search(".*buzzer-.*", sensor) sensor_is_seg = re.search(".*7segment.*", sensor) sensor_is_rel = re.search(".*relay-.*", sensor) + sensor_is_ult = re.search(".*ultrasonic.*", sensor) # --- Extra Regex --- # extra_is_gauge = re.search(".*gauge.*", sensor) @@ -86,6 +87,10 @@ def run(sensor, pi): relay.setup() relay.com.on() # Power COM on from GPIO + # Ultrasonic + elif sensor_is_ult: + ultra.setup() + while True: message = pi.message message_type = pi.message_type @@ -149,6 +154,10 @@ def run(sensor, pi): relay.com.off() # Power COM off from GPIO relay.cleanup() + # Ultrasonic + elif sensor_is_ult: + ultra.cleanup() + break # --- Process --- # @@ -228,6 +237,10 @@ def run_scroll(stop_event: threading.Event): if extra_is_alarm: relay.toggle_switch(1.0) + # Ultrasonic + elif sensor_is_ult: + ultra.process(pi.ws, 1.5) + except RuntimeError as error: logger.warning(error.args[0]) sleep(2.0) diff --git a/raspberry/ws_control.py b/raspberry/ws_control.py index 0dd49c7..a6984d4 100644 --- a/raspberry/ws_control.py +++ b/raspberry/ws_control.py @@ -11,7 +11,7 @@ from raspi import ( DHT11, LCD, ArrayLED, DPad, Joystick, Matrix, Buzzer, Segment, Relay, - async_receive, run + Ultrasonic, async_receive, run ) @@ -118,19 +118,28 @@ def __init__(self, server, port, pi_name): self.segment = Segment(seg_pins, multi=seg_multi) # --- Relay --- # - pins = { + relay_pins = { "COM": 21, # Common pin "SWITCH": 20 # Relay coil switch } - self.relay = Relay(pins) + self.relay = Relay(relay_pins) + + # --- Ultrasonic --- # + + ultra_pins = { + "T": 18, + "E": 17 + } + + self.ultra = Ultrasonic(ultra_pins) # --- Misc --- # self.sensor = "" self.sensors = [self.logger, self.dht11, self.mat8x8, self.dpad, self.array_led, self.lcd, self.joystick, self.buzzer, - self.segment, self.relay] + self.segment, self.relay, self.ultra] if __name__ == "__main__": diff --git a/sensor/consumers.py b/sensor/consumers.py index e338b5d..8d2c62f 100644 --- a/sensor/consumers.py +++ b/sensor/consumers.py @@ -50,19 +50,28 @@ async def receive(self, text_data): 'time': now.isoformat() } - if (sensor == 'dht11'): - temp = text_data_json['temp'] - hum = text_data_json['hum'] + # Write data to database + if message_type != "command": + if (sensor == 'dht11'): + temp = text_data_json['temp'] + hum = text_data_json['hum'] - dht11_json = { - 'temp': temp, - 'hum': hum, - } + tmp_json = { + 'temp': temp, + 'hum': hum, + } - json_file = {**json_file, **dht11_json} + json_file = {**json_file, **tmp_json} + + if (sensor == 'ultrasonic'): + distance = text_data_json['distance'] + + tmp_json = { + 'distance': distance, + } + + json_file = {**json_file, **tmp_json} - # Write data to database - if message_type != "control": await self.register_data(self.pi_name, sensor, now, message) # Send message to group @@ -84,16 +93,26 @@ async def sensor_message(self, event): 'time': now } - if (sensor == 'dht11'): - temp = event['temp'] - hum = event['hum'] + if message_type != "command": + if (sensor == 'dht11'): + temp = event['temp'] + hum = event['hum'] + + tmp_json = { + 'temp': temp, + 'hum': hum, + } + + json_file = {**json_file, **tmp_json} + + if (sensor == 'ultrasonic'): + distance = event['distance'] - dht11_json = { - 'temp': temp, - 'hum': hum, - } + tmp_json = { + 'distance': distance, + } - json_file = {**json_file, **dht11_json} + json_file = {**json_file, **tmp_json} # Send message to WebSocket await self.send(text_data=json.dumps(json_file)) @@ -104,6 +123,7 @@ def register_data(self, raspi, sensor, time, data): pi = Raspi.objects.get(name=raspi) se = pi.sensor_set.get(name=sensor) se.item_set.create(datetime=time, data=data) - except: - #logging.debug("Raspi: %s | Sensor: %s | Time: %s | Data: %s" % (raspi, sensor, time, data)) + except Exception: + # logging.debug("Raspi: %s | Sensor: %s | Time: %s | Data: %s" % + # (raspi, sensor, time, data)) logging.debug("Sensor does not exist in database") diff --git a/sensor/static/sensor/css/sensor/ultrasonic.css b/sensor/static/sensor/css/sensor/ultrasonic.css new file mode 100644 index 0000000..0cd9a5a --- /dev/null +++ b/sensor/static/sensor/css/sensor/ultrasonic.css @@ -0,0 +1,106 @@ +.ultra { + width: 30vw; +} + +.ultra-container { + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; + margin-bottom: 5%; +} +@media (min-width: 1200px) { + .ultra-container { + padding: 2% 10%; + } +} +@media (max-width: 1199.98px) { + .ultra-container { + padding: 2% 8%; + } +} +@media (max-width: 991.98px) { + .ultra-container { + padding: 2% 6%; + } +} +@media (max-width: 767.98px) { + .ultra-container { + flex-direction: column; + padding: 2% 4%; + } +} +@media (max-width: 575.98px) { + .ultra-container { + flex-direction: column; + padding: 2% 2%; + } +} + +.ultra-box { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + object-fit: fill; + font-style: bold; + text-align: center; + font-size: 24px; +} +.ultra-box p { + margin: 0%; +} +@media (min-width: 1200px) { + .ultra-box p { + font-size: 2.2rem; + } +} +@media (max-width: 1199.98px) { + .ultra-box p { + font-size: 2rem; + } +} +@media (max-width: 991.98px) { + .ultra-box p { + font-size: 1.6rem; + } +} +@media (max-width: 767.98px) { + .ultra-box p { + font-size: 1.5rem; + } +} +@media (max-width: 575.98px) { + .ultra-box p { + font-size: 1.2rem; + } +} +@media (min-width: 1200px) { + .ultra-box div { + font-size: 2rem; + } +} +@media (max-width: 1199.98px) { + .ultra-box div { + font-size: 1.6rem; + } +} +@media (max-width: 991.98px) { + .ultra-box div { + font-size: 1.4rem; + } +} +@media (max-width: 767.98px) { + .ultra-box div { + font-size: 1.2rem; + margin-bottom: 15%; + } +} +@media (max-width: 575.98px) { + .ultra-box div { + font-size: 1.1rem; + margin-bottom: 10%; + } +} + +/*# sourceMappingURL=ultrasonic.css.map */ diff --git a/sensor/static/sensor/css/sensor/ultrasonic.css.map b/sensor/static/sensor/css/sensor/ultrasonic.css.map new file mode 100644 index 0000000..9905637 --- /dev/null +++ b/sensor/static/sensor/css/sensor/ultrasonic.css.map @@ -0,0 +1 @@ +{"version":3,"sourceRoot":"","sources":["../../scss/sensor/ultrasonic.scss","../../scss/utils/_common.scss","../../scss/third-party/bootstrap/mixins/_breakpoints.scss"],"names":[],"mappings":"AAGA;EACI;;;AAGF;ECDA;EACA;EAIA;EACA;EDiBE;;AEkCA;EFxDF;IAKI;;;AEgEF;EFrEF;IAQI;;;AE6DF;EFrEF;IAWI;;;AE0DF;EFrEF;IAcI;IACA;;;AEsDF;EFrEF;IAkBI;IACA;;;;AAMN;EC/BE;EACA;EASA;EACA;EDwBE;EAEA;EACA;EACA;;AAEA;EACE;;AEoBF;EFrBA;IAII;;;AE8BJ;EFlCA;IAOI;;;AE2BJ;EFlCA;IAUI;;;AEwBJ;EFlCA;IAaI;;;AEqBJ;EFlCA;IAgBI;;;AEKJ;EFDA;IAEI;;;AEYJ;EFdA;IAKI;;;AESJ;EFdA;IAQI;;;AEMJ;EFdA;IAWI;IACA;;;AEEJ;EFdA;IAeI;IACA","file":"ultrasonic.css"} \ No newline at end of file diff --git a/sensor/static/sensor/images/wiring/pins/ultrasonic.svg b/sensor/static/sensor/images/wiring/pins/ultrasonic.svg index a2d6d4b..bd3fb2f 100644 --- a/sensor/static/sensor/images/wiring/pins/ultrasonic.svg +++ b/sensor/static/sensor/images/wiring/pins/ultrasonic.svg @@ -4,7 +4,7 @@ height="136.828346pt" viewBox="0 0 561.826772 136.828346" version="1.2" - id="svg1005" + id="svg1008" sodipodi:docname="ultrasonic.svg" inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" @@ -13,7 +13,7 @@ xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> + inkscape:current-layer="svg1008" /> + id="defs283"> + id="g161"> @@ -451,1974 +451,1982 @@ d="M 11.203125 -3.671875 L 11.296875 0 L 8.140625 0 L 4.015625 -7.1875 L 3.828125 -7.1875 L 3.8125 -4.09375 L 3.921875 0 L 1.28125 0 L 1.421875 -3.421875 L 1.28125 -11.609375 L 4.421875 -11.609375 L 8.5625 -4.421875 L 8.75 -4.421875 L 8.671875 -11.5 L 11.359375 -11.65625 Z M 11.203125 -3.671875 " id="path155" /> + + + + id="path163" /> + id="path166" /> + id="path169" /> + id="path172" /> + id="path175" /> + id="path178" /> + id="path181" /> + id="path184" /> + id="path187" /> + id="path190" /> + id="path193" /> + id="path196" /> + id="path199" /> + id="path202" /> + id="path205" /> + id="path208" /> + id="path211" /> + id="path214" /> + id="path217" /> + id="path220" /> + id="path223" /> + id="path226" /> + id="path229" /> + id="path232" /> + id="path235" /> + id="path238" /> + id="path241" /> + id="path244" /> + id="path247" /> + id="path250" /> + id="path253" /> + id="path256" /> + id="path259" /> + id="path262" /> + id="path265" /> + id="path268" /> + id="path271" /> + id="path274" /> + id="path277" /> + id="path280" /> + id="surface2570"> + id="path285" /> + id="path287" /> + id="path289" /> + id="path291" /> + id="path293" /> + id="path295" /> + id="path297" /> + id="path299" /> + id="path301" /> + id="path303" /> + id="g307"> + id="path305" /> + id="path309" /> + id="path311" /> + id="path313" /> + id="path315" /> + id="g319"> + id="path317" /> + id="g323"> + id="path321" /> + id="path325" /> + id="g329"> + id="path327" /> + id="g333"> + id="path331" /> + id="path335" /> + id="path337" /> + id="path339" /> + id="path341" /> + id="path343" /> + id="path345" /> + id="path347" /> + id="path349" /> + id="path351" /> + id="path353" /> + id="path355" /> + id="path357" /> + id="path359" /> + id="g363"> + id="path361" /> + id="path365" /> + id="path367" /> + id="path369" /> + id="path371" /> + id="g375"> + id="path373" /> + id="g379"> + id="path377" /> + id="path381" /> + id="g385"> + id="path383" /> + id="g389"> + id="path387" /> + id="path391" /> + id="path393" /> + id="path395" /> + id="path397" /> + id="path399" /> + id="path401" /> + id="path403" /> + id="path405" /> + id="path407" /> + id="path409" /> + id="path411" /> + id="path413" /> + id="path415" /> + id="g419"> + id="path417" /> + id="path421" /> + id="path423" /> + id="path425" /> + id="path427" /> + id="g431"> + id="path429" /> + id="g435"> + id="path433" /> + id="path437" /> + id="g441"> + id="path439" /> + id="g445"> + id="path443" /> + id="path447" /> + id="path449" /> + id="path451" /> + id="path453" /> + id="path455" /> + id="path457" /> + id="path459" /> + id="path461" /> + id="path463" /> + id="path465" /> + id="path467" /> + id="path469" /> + id="path471" /> + id="g475"> + id="path473" /> + id="path477" /> + id="path479" /> + id="path481" /> + id="path483" /> + id="g487"> + id="path485" /> + id="g491"> + id="path489" /> + id="path493" /> + id="g497"> + id="path495" /> + id="g501"> + id="path499" /> + id="path503" /> + id="path505" /> + id="path507" /> + id="path509" /> + id="path511" /> + id="g515"> + id="path513" /> + id="g519"> + id="path517" /> + id="path521" /> + id="g525"> + id="path523" /> + id="path527" /> + id="path529" /> + id="path531" /> + id="path533" /> + id="g537"> + id="path535" /> + id="g541"> + id="path539" /> + id="path543" /> + id="g547"> + id="path545" /> + id="path549" /> + id="path551" /> + id="g555"> + id="path553" /> + id="path557" /> + id="path559" /> + id="g563"> + id="path561" /> + id="g567"> + id="path565" /> + id="path569" /> + id="g573"> + id="path571" /> + id="path575" /> + id="g579"> + id="path577" /> + id="g583"> + id="path581" /> + id="path585" /> + id="g589"> + id="path587" /> + id="g593"> + id="path591" /> + id="path595" /> + id="path597" /> + id="g601"> + id="path599" /> + id="g605"> + id="path603" /> + id="path607" /> + id="g611"> + id="path609" /> + id="g615"> + id="path613" /> + id="path617" /> + id="g621"> + id="path619" /> + id="g625"> + id="path623" /> + id="g631"> + id="use627" /> + id="use629" /> + id="g635"> + id="use633" /> + id="g643"> + id="use637" /> + id="use639" /> + id="use641" /> + id="g649"> + id="use645" /> + id="use647" /> + id="g653"> + id="use651" /> + id="g657"> + id="use655" /> + id="g661"> + id="use659" /> + id="g665"> + id="use663" /> + id="g669"> + id="use667" /> + id="g673"> + id="use671" /> + id="g677"> + id="use675" /> + id="g683"> + id="use679" /> + id="use681" /> + id="g687"> + id="use685" /> + id="g693"> + id="use689" /> + id="use691" /> + id="g697"> + id="use695" /> + id="g701"> + id="use699" /> + id="g705"> + id="use703" /> + id="g713"> + id="use707" /> + id="use709" /> + id="use711" /> + id="g717"> + id="use715" /> + id="g721"> + id="use719" /> + id="g727"> + id="use723" /> + id="use725" /> + id="g731"> + id="use729" /> + id="g735"> + id="use733" /> + id="g739"> + id="use737" /> + id="g745"> + id="use741" /> + id="use743" /> + id="g749"> + id="use747" /> + id="g753"> + id="use751" /> + id="g757"> + id="use755" /> + id="g765"> + id="use759" /> + id="use761" /> + id="use763" /> + id="g769"> + id="use767" /> + id="g773"> + id="use771" /> + id="g785"> + id="use775" /> + id="use777" /> + id="use779" /> + id="use781" /> + id="use783" /> + id="g789"> + id="use787" /> + id="g797"> + id="use791" /> + id="use793" /> + id="use795" /> + id="g805"> + id="use799" /> + id="use801" /> + id="use803" /> + id="g809"> + id="use807" /> + id="g813"> + id="use811" /> + id="g817"> + id="use815" /> + id="g821"> + id="use819" /> + id="g825"> + id="use823" /> + id="g831"> + id="use827" /> + id="use829" /> + id="g835"> + id="use833" /> + id="g839"> + id="use837" /> + id="g843"> + id="use841" /> + id="g847"> + id="use845" /> + id="g851"> + id="use849" /> + id="g855"> + id="use853" /> + id="g859"> + id="use857" /> + id="g863"> + id="use861" /> + id="g867"> + id="use865" /> + id="g871"> + id="use869" /> + id="g879"> + id="use873" /> + id="use875" /> + id="use877" /> + id="g883"> + id="use881" /> + id="g887"> + id="use885" /> + id="g891"> + id="use889" /> + id="g897"> + id="use893" /> + id="use895" /> + id="g903"> + id="use899" /> + id="use901" /> + id="g907"> + id="use905" /> + id="g911"> + id="use909" /> + id="g927"> + id="use913" /> + id="use915" /> + id="use917" /> + id="use919" /> + id="use921" /> + id="use923" /> + id="use925" /> + id="g931"> + id="use929" /> + id="g937"> + id="use933" /> + id="use935" /> + id="g941"> + id="use939" /> + id="g945"> + id="use943" /> + id="g949"> + id="use947" /> + id="g953"> + id="use951" /> + id="g957"> + id="use955" /> + id="g961"> + id="use959" /> + id="g965"> + id="use963" /> + id="g969"> + id="use967" /> + id="g973"> + id="use971" /> + id="g977"> + id="use975" /> + id="g981"> + id="use979" /> + id="g985"> + id="use983" /> + id="g989"> + id="use987" /> + id="g993"> + id="use991" /> + id="g997"> + id="use995" /> + id="g1001"> + id="use999" /> + id="g1005"> + id="use1003" /> diff --git a/sensor/static/sensor/js/sensors/ultrasonic.js b/sensor/static/sensor/js/sensors/ultrasonic.js new file mode 100644 index 0000000..9ce7d2d --- /dev/null +++ b/sensor/static/sensor/js/sensors/ultrasonic.js @@ -0,0 +1,78 @@ +window.onload = function () { + const debug = JSON.parse(document.getElementById('debug').textContent); + const piName = JSON.parse(document.getElementById('pi-name').textContent); + const sensorName = JSON.parse(document.getElementById('sensor-name').textContent); + + const dataSocket = new WebSocket( + 'ws://' + + window.location.host + + '/ws/' + + piName + + '/' + + sensorName + + '/' + ); + + dataSocket.onmessage = function (e) { + const data = JSON.parse(e.data); + console.log(data); + + if (debug === true) { + // Process received data + if (data.message_type === "data") { + document.querySelector('#data-log').value += (data.message + '\n'); + } + } + + var distance = document.getElementById('distance-text'); + distance.textContent = data.distance.toFixed(2) + " cm"; + }; + + dataSocket.onopen = function (e) { + // Send start signal + dataSocket.send(JSON.stringify({ + 'sensor': sensorName, + 'message': 'start', + 'message_type': 'command', + })); + } + + window.onbeforeunload = function () { + // Send stop signal + dataSocket.send(JSON.stringify({ + 'sensor': sensorName, + 'message': 'stop', + 'message_type': 'command', + })); + dataSocket.close + }; + + dataSocket.onclose = function (e) { + console.error('Data socket closed unexpectedly'); + }; + + if (debug === true) { + document.querySelector('#data-message-input').focus(); + document.querySelector('#data-message-input').onkeyup = function (e) { + if (e.keyCode === 13) { // enter, return + document.querySelector('#data-message-submit').click(); + } + }; + + document.querySelector('#data-message-submit').onclick = function (e) { + const messageInputDom = document.querySelector('#data-message-input'); + const message = messageInputDom.value; + dataSocket.send(JSON.stringify({ + 'sensor': sensorName, + 'message': message, + 'message_type': 'command', + })); + messageInputDom.value = ''; + }; + + document.querySelector('#clear-textarea').onclick = function (e) { + const dataLogDom = document.querySelector('#data-log'); + dataLogDom.value = ''; + }; + } +} \ No newline at end of file diff --git a/sensor/static/sensor/scss/sensor/ultrasonic.scss b/sensor/static/sensor/scss/sensor/ultrasonic.scss new file mode 100644 index 0000000..35e3500 --- /dev/null +++ b/sensor/static/sensor/scss/sensor/ultrasonic.scss @@ -0,0 +1,82 @@ +@use "../third-party/bootstrap" as *; +@use "../utils" as *; + +.ultra { + width: 30vw; + } + + .ultra-container { + @include flex-row; + @include flex-center; + + @include media-breakpoint-up(xl) { + padding: 2% 10%; + } + @include media-breakpoint-down(xl) { + padding: 2% 8%; + } + @include media-breakpoint-down(lg) { + padding: 2% 6%; + } + @include media-breakpoint-down(md) { + flex-direction: column; + padding: 2% 4%; + } + @include media-breakpoint-down(sm) { + flex-direction: column; + padding: 2% 2%; + } + + margin-bottom: 5%; + } + +.ultra-box { + @include flex-column; + @include flex-center; + + object-fit: fill; + + font-style: bold; + text-align: center; + font-size: 24px; + + p { + margin: 0%; + + @include media-breakpoint-up(xl) { + font-size: 2.2rem; + } + @include media-breakpoint-down(xl) { + font-size: 2rem; + } + @include media-breakpoint-down(lg) { + font-size: 1.6rem; + } + @include media-breakpoint-down(md) { + font-size: 1.5rem; + } + @include media-breakpoint-down(sm) { + font-size: 1.2rem; + } + } + + div { + @include media-breakpoint-up(xl) { + font-size: 2rem; + } + @include media-breakpoint-down(xl) { + font-size: 1.6rem; + } + @include media-breakpoint-down(lg) { + font-size: 1.4rem; + } + @include media-breakpoint-down(md) { + font-size: 1.2rem; + margin-bottom: 15%; + } + @include media-breakpoint-down(sm) { + font-size: 1.1rem; + margin-bottom: 10%; + } + } + } \ No newline at end of file diff --git a/sensor/templates/sensor/sensors/ultrasonic.html b/sensor/templates/sensor/sensors/ultrasonic.html index 085574b..3902f44 100644 --- a/sensor/templates/sensor/sensors/ultrasonic.html +++ b/sensor/templates/sensor/sensors/ultrasonic.html @@ -2,6 +2,9 @@ {% load range_iterator %} {% load reusable_blocks %} + + + {% sub_header "tool.svg" "Wiring Schematic" "wiring" %} @@ -14,4 +17,14 @@
Ultrasonic Pins +
+ + +{% sub_header "tablet.svg" "Display Panel" "display" %} + +
+
+

Distance

+
+
\ No newline at end of file diff --git a/sensor/views.py b/sensor/views.py index 09e2c74..65951d2 100644 --- a/sensor/views.py +++ b/sensor/views.py @@ -102,7 +102,7 @@ def pi_name(request, pi_name): def sensor_name(request, pi_name, sensor_name): - debug = settings.DEBUG + debug = True sensors = ["dht11", "ultrasonic", "8x8matrix", "buzzer", "relay", "lcd", "7segment", "ledarray", "joystick"] @@ -116,7 +116,7 @@ def sensor_name(request, pi_name, sensor_name): def sensor_extra(request, pi_name, sensor_name, extra): - debug = settings.DEBUG + debug = True return render(request, 'sensor/extra.html', { 'debug': debug, 'pi_name': pi_name,