From e3c379a3b20c57ea38c1fd3491c1552a98efedbf Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Thu, 25 Jun 2015 17:02:47 +0100 Subject: [PATCH] misc --- data.json | 1 + generate-json.py | 124 ++++++++++++++++++++++++++++++++++++++++ resources/pinout.css | 3 + serve.py | 1 - src/en-GB/settings.yaml | 1 + 5 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 data.json create mode 100755 generate-json.py diff --git a/data.json b/data.json new file mode 100644 index 0000000..f08df00 --- /dev/null +++ b/data.json @@ -0,0 +1 @@ +[{"page_url": "ground", "title": "Ground", "name": "Ground", "pin": {"25": null, "39": null, "20": null, "14": null, "30": null, "34": null, "6": null, "9": null}, "description": "Raspberry Pi Ground Pins"}, {"name": "SPI", "pin": {"11": {"name": "SPI1 CE1"}, "24": {"active": "high", "direction": "output", "name": "SPI0 CE0", "description": "Chip Select 0"}, "26": {"active": "high", "direction": "output", "name": "SPI0 CE1", "description": "Chip Select 1"}, "12": {"name": "SPI1 CE0"}, "21": {"active": "high", "direction": "input", "name": "SPI0 MISO", "description": "Master In / Slave Out"}, "23": {"active": "high", "direction": "output", "name": "SPI0 SCLK", "description": "Clock"}, "19": {"active": "high", "direction": "output", "name": "SPI0 MOSI", "description": "Master Out / Slave In"}, "36": {"name": "SPI1 CE2"}, "35": {"name": "SPI1 MISO"}, "38": {"name": "SPI1 MOSI"}, "40": {"name": "SPI1 SCLK"}}, "title": "SPI - Serial Peripheral Interface", "pincount": 5, "description": "Raspberry Pi SPI pins", "page_url": "spi"}, {"page_url": "uart", "title": "UART - Universal Asynchronous Receiver/Transmitter", "name": "UART", "pin": {"8": {"active": "high", "direction": "output", "name": "TXD / Transmit"}, "10": {"active": "high", "direction": "input", "name": "RXD / Receive"}}, "description": "Raspberry Pi UART pins"}, {"page_url": "i2c", "title": "I2C - Inter Integrated Circuit", "name": "I2C", "pin": {"5": {"active": "high", "direction": "both", "name": "Clock"}, "3": {"active": "high", "direction": "both", "name": "Data"}, "27": {"active": "high", "direction": "both", "name": "EEPROM Data"}, "28": {"active": "high", "direction": "both", "name": "EEPROM Clock"}}, "description": "Raspberry Pi i2c pins"}, {"title": "Raspberry Pi WiringPi", "name": "WiringPi GPIO Pinout", "pin": {"11": {"name": "WiringPi 0"}, "13": {"name": "WiringPi 2"}, "36": {"name": "WiringPi 27"}, "12": {"name": "WiringPi 1"}, "35": {"name": "WiringPi 24"}, "24": {"name": "WiringPi 10"}, "10": {"name": "WiringPi 16"}, "26": {"name": "WiringPi 11"}, "38": {"name": "WiringPi 28"}, "15": {"name": "WiringPi 3"}, "21": {"name": "WiringPi 13"}, "22": {"name": "WiringPi 6"}, "23": {"name": "WiringPi 14"}, "19": {"name": "WiringPi 12"}, "18": {"name": "WiringPi 5"}, "31": {"name": "WiringPi 22"}, "16": {"name": "WiringPi 4"}, "37": {"name": "WiringPi 25"}, "29": {"name": "WiringPi 21"}, "40": {"name": "WiringPi 29"}, "33": {"name": "WiringPi 23"}, "3": {"name": "WiringPi 8"}, "5": {"name": "WiringPi 9"}, "7": {"name": "WiringPi 7"}, "32": {"name": "WiringPi 26"}, "8": {"name": "WiringPi 15"}}, "page_url": "wiringpi"}, {"page_url": "arduino_spi", "title": "ATmega 328p / Arduino over SPI", "name": "Arduino SPI", "pin": {"24": {"active": "high", "direction": "output", "name": "CE0", "description": "Arduino Reset"}, "19": {"active": "high", "direction": "output", "name": "MOSI", "description": "Master Out / Slave In"}, "21": {"active": "high", "direction": "input", "name": "MISO", "description": "Master In / Slave Out"}, "23": {"active": "high", "direction": "output", "name": "SCKL", "description": "Clock"}}, "description": "Program Arduino with Raspberry Pi SPI"}, null, {"buy": "https://www.piborg.org/ledborg", "name": "PiBorg LEDBorg", "pin": {"11": {"active": "high", "direction": "output", "name": "Red LED", "description": "PiBorg Red LED"}, "13": {"active": "high", "direction": "input", "name": "Green LED", "description": "PiBorg Green LED"}, "15": {"active": "high", "direction": "output", "name": "Blue LED", "description": "PiBorg Blue LED"}}, "title": "Purple!", "description": "A single RGB LED for your Raspberry Pi", "page_url": "piborg_ledborg"}, {"buy": "http://shop.pimoroni.com/products/piglow", "description": "Simply 18 LEDs in a spiral pattern controllable in Python.", "pin": {"1": {}, "3": {"mode": "i2c"}, "2": {}, "5": {"mode": "i2c"}, "14": {}, "17": {}}, "title": "PiGlow", "url": "https://github.com/pimoroni/piglow", "pincount": 26, "name": "PiGlow", "github": "https://github.com/pimoroni/piglow", "page_url": "piglow", "manufacturer": "Pimoroni"}, {"description": "An all-in-one light, sound, input and output add-on board.", "pin": {"11": {"active": "high", "direction": "output", "name": "Yellow LED"}, "24": {"active": "high", "direction": "input", "name": "Input C"}, "13": {"active": "high", "direction": "output", "name": "Red LED"}, "12": {"active": "high", "direction": "output", "name": "Buzzer"}, "15": {"active": "high", "direction": "output", "name": "Output A"}, "21": {"active": "high", "direction": "input", "name": "Input A"}, "22": {"active": "high", "direction": "output", "name": "Output D"}, "16": {"active": "high", "direction": "output", "name": "Output B"}, "19": {"active": "high", "direction": "output", "name": "Input D"}, "18": {"active": "high", "direction": "output", "name": "Output C"}, "23": {"active": "high", "direction": "input", "name": "Button"}, "26": {"active": "high", "direction": "input", "name": "Input B"}, "7": {"active": "high", "direction": "output", "name": "Green LED"}}, "title": "Pibrella", "url": "https://github.com/pimoroni/pibrella", "name": "Pibrella", "pincount": 26, "page_url": "pibrella", "manufacturer": "Pimoroni Vs Cyntech"}, {"buy": "http://shop.pimoroni.com/products/unicorn-hat", "description": "64 blindingly bright RGB LEDs on a single HAT", "pin": {"12": {"active": "high", "direction": "output", "mode": "pwm", "description": "WS2812 Data", "name": "Data"}}, "title": "Unicorn HAT", "url": "http://shop.pimoroni.com/products/unicorn-hat", "pincount": 40, "name": "Unicorn HAT", "github": "https://github.com/pimoroni/unicornhat", "page_url": "unicorn_hat", "manufacturer": "Pimoroni"}, {"buy": "http://shop.pimoroni.com/products/skywriter-hat", "description": "A 3D positional and gesture sensor.", "pin": {"11": {"name": "Reset"}, "3": {"mode": "i2c"}, "5": {"mode": "i2c"}, "13": {"name": "Transfer"}}, "title": "Skywriter HAT", "url": "https://github.com/pimoroni/skywriter-hat", "pincount": 40, "name": "Skywriter HAT", "github": "https://github.com/pimoroni/skywriter-hat", "page_url": "skywriter_hat", "manufacturer": "Pimoroni"}, {"buy": "http://shop.pimoroni.com/products/explorer-hat", "description": "An all-in-one light, input, motor, touch and output add-on board.", "pin": {"11": {"active": "high", "name": "LED 2", "mode": "output"}, "36": {"active": "high", "name": "Output 4", "mode": "output"}, "12": {}, "35": {"active": "high", "name": "Motor 1 +", "mode": "output"}, "24": {}, "10": {}, "13": {"active": "high", "name": "LED 3", "mode": "output"}, "38": {"active": "high", "name": "Motor 1 -", "mode": "output"}, "15": {"active": "high", "name": "Input 2", "mode": "input"}, "21": {}, "22": {"active": "high", "name": "Input 4", "mode": "input"}, "23": {}, "19": {}, "18": {"active": "high", "name": "Input 3", "mode": "input"}, "31": {"active": "high", "name": "Output 1", "mode": "output"}, "16": {"active": "high", "name": "Input 1", "mode": "input"}, "37": {"active": "high", "name": "Motor 2 -", "mode": "output"}, "29": {"active": "high", "name": "LED 4", "mode": "output"}, "40": {"active": "high", "name": "Motor 2 +", "mode": "output"}, "33": {"active": "high", "name": "Output 3", "mode": "output"}, "3": {}, "5": {}, "7": {"active": "high", "name": "LED 1", "mode": "output"}, "32": {"active": "high", "name": "Output 2", "mode": "output"}, "8": {}}, "title": "Explorer HAT and Explorer HAT Pro", "url": "https://github.com/pimoroni/explorer-hat", "page_url": "explorer_hat_pro", "pincount": 40, "name": "Explorer HAT Pro", "github": "https://github.com/pimoroni/explorer-hat", "i2c": {"0x48": {"device": "ads1015", "name": "Analog Input"}, "0x28": {"device": "cap1208", "name": "Cap Touch"}}, "manufacturer": "Pimoroni"}, {"buy": "http://shop.pimoroni.com/products/explorer-hat", "description": "An all-in-one light, input, touch and output add-on board.", "pin": {"11": {"active": "high", "name": "LED 2", "mode": "output"}, "13": {"active": "high", "name": "LED 3", "mode": "output"}, "15": {"active": "high", "name": "Input 2", "mode": "input"}, "22": {"active": "high", "name": "Input 4", "mode": "input"}, "16": {"active": "high", "name": "Input 1", "mode": "input"}, "33": {"active": "high", "name": "Output 3", "mode": "output"}, "18": {"active": "high", "name": "Input 3", "mode": "input"}, "31": {"active": "high", "name": "Output 1", "mode": "output"}, "29": {"active": "high", "name": "LED 4", "mode": "output"}, "36": {"active": "high", "name": "Output 4", "mode": "output"}, "7": {"active": "high", "name": "LED 1", "mode": "output"}, "32": {"active": "high", "name": "Output 2", "mode": "output"}}, "title": "Explorer HAT and Explorer HAT Pro", "url": "https://github.com/pimoroni/explorer-hat", "pincount": 40, "name": "Explorer HAT", "github": "https://github.com/pimoroni/explorer-hat", "page_url": "explorer_hat", "manufacturer": "Pimoroni"}, {"description": "A 3-line character LCD with an RGB backlight and joystick", "pin": {"3": {"mode": "i2c"}, "5": {"mode": "i2c"}, "7": {"active": "low", "name": "Joystick Button", "mode": "input"}, "11": {"active": "low", "name": "Joystick Left", "mode": "input"}, "13": {"active": "low", "name": "Joystick Up", "mode": "input"}, "15": {"active": "low", "name": "Joystick Right", "mode": "input"}, "19": {"mode": "spi"}, "21": {"active": "low", "name": "Joystick Down", "mode": "input"}, "22": {"active": "high", "name": "LCD CMD/DATA", "mode": "output"}, "23": {"mode": "spi"}}, "title": "Display-o-Tron 3000", "url": "https://github.com/pimoroni/dot3k", "name": "Display-o-Tron 3000", "pincount": 40, "page_url": "display_o_tron_3000", "manufacturer": "Pimoroni"}, {"github": "https://github.com/raspberrypilearning/dots", "name": "Raspberry Pi Dots", "pin": {"bcm21": {"direction": "input", "name": "Dot 12"}, "bcm20": {"direction": "input", "name": "Bear"}, "bcm23": {"direction": "input", "name": "Dot 16"}, "bcm22": {"direction": "input", "name": "Dot 15"}, "bcm25": {"direction": "input", "name": "Dot 5"}, "bcm24": {"direction": "input", "name": "Dot 19"}, "bcm27": {"direction": "input", "name": "Color: Red"}, "bcm26": {"direction": "input", "name": "Dot 11"}, "bcm2": {"direction": "input", "name": "Dot 22"}, "bcm3": {"direction": "input", "name": "Dot 21"}, "bcm0": {"direction": "input", "name": "Color: Blue"}, "bcm1": {"direction": "input", "name": "Dot 7"}, "bcm6": {"direction": "input", "name": "Dot 14"}, "bcm7": {"direction": "input", "name": "Dot 6"}, "bcm4": {"direction": "input", "name": "Dot 2"}, "bcm5": {"direction": "input", "name": "Dot 9"}, "bcm8": {"direction": "input", "name": "Dot 18"}, "bcm9": {"direction": "input", "name": "Dot 17"}, "bcm10": {"direction": "input", "name": "Color: Green"}, "bcm11": {"direction": "input", "name": "Dot 8"}, "bcm12": {"direction": "input", "name": "Dot 10"}, "bcm13": {"direction": "input", "name": "Cloud"}, "bcm14": {"direction": "input", "name": "Dot 1"}, "bcm15": {"direction": "input", "name": "Dot 3"}, "bcm16": {"direction": "input", "name": "Dot 13"}, "bcm17": {"direction": "input", "name": "Dot 4"}, "bcm18": {"direction": "input", "name": "Dot 20"}, "bcm19": {"direction": "input", "name": "Color: Orange"}}, "title": "Raspberry Pi Dots", "url": "http://www.raspberrypi.org/dots/", "page_url": "raspberry_pi_dots", "description": "Join the dots to make a circuit"}, {"buy": "http://www.ryanteck.uk/store/traffichat", "description": "A quick and easy way to learn the basics of GPIO on a budget. All in a nice HAT.", "pin": {"18": {"active": "high", "direction": "output", "name": "LED3 / Red"}, "15": {"active": "high", "direction": "output", "name": "LED1 / Green"}, "29": {"active": "high", "direction": "output", "name": "Buzzer"}, "22": {"active": "high", "direction": "input", "name": "Button"}, "16": {"active": "high", "direction": "output", "name": "LED2 / Amber"}}, "title": "Traffic HAT", "url": "http://www.ryanteck.uk/store/traffichat", "name": "Traffic HAT", "pincount": 40, "page_url": "traffic_hat", "manufacturer": "Ryanteck LTD."}, {"page_url": "iqaudio_pi_dac", "title": "IQaudIO Pi-DAC+", "name": "IQaudIO Pi-DAC+", "pin": {"1": null, "2": null, "3": null, "4": null, "5": null, "6": null, "9": null, "12": {"name": "I2S"}, "14": null, "16": {"name": "Rotary Encoder"}, "18": {"name": "Rotary Encoder"}, "25": null, "27": null, "28": null, "35": {"name": "I2S"}, "38": {"name": "I2S"}, "39": null, "40": {"name": "I2S"}}, "description": "Program Arduino with Raspberry Pi SPI"}] diff --git a/generate-json.py b/generate-json.py new file mode 100755 index 0000000..3f4e8a6 --- /dev/null +++ b/generate-json.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python +import json +import markdown +import unicodedata +import re +import os +import time +import sys +import pinout +import yaml +import markjaml + +reload(sys) +sys.setdefaultencoding('utf8') + +lang = "en-GB" + +if len(sys.argv) > 1: + lang = sys.argv[1] + +pinout.load(lang) + +overlays = pinout.settings['overlays'] + +pages = {} + +def cssify(value): + value = slugify(value); + if value[0] == '3' or value[0] == '5': + value = 'pow' + value + + return value + +def slugify(value): + """ + Normalizes string, converts to lowercase, removes non-alpha characters, + and converts spaces to hyphens. + """ + value = unicode(value) + value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii') + value = re.sub('[^\w\s-]', '', value).strip().lower() + return re.sub('[-\s]+', '_', value) + +def load_overlay(overlay): + try: + data = markjaml.load('src/{}/overlay/{}.md'.format(lang,overlay)) + + loaded = data['data'] + except IOError: + return None + + + details = [] + + if 'manufacturer' in loaded: + details.append('* Made by ' + loaded['manufacturer']) + + if 'pincount' in loaded: + pincount = int(loaded['pincount']) + if pincount == 40: + details.append('* HAT form-factor') + elif pincount == 26: + details.append('* Classic 26-pin') + else: + details.append('* {} pin header'.format(pincount)) + + if 'pin' in loaded: + uses_5v = False + uses_3v = False + uses = 0 + for pin in loaded['pin']: + pin = str(pin) + if pin.startswith('bcm'): + pin = pinout.bcm_to_physical(pin[3:]) + + if pin in pinout.pins: + actual_pin = pinout.pins[pin] + + if actual_pin['type'] in ['+3v3','+5v','GND']: + if actual_pin['type'] == '+3v3': + uses_3v = True + if actual_pin['type'] == '+5v': + uses_5v = True + else: + uses += 1 + + if uses > 0: + details.append('* Uses {} GPIO pins'.format(uses)) + + if '3' in loaded['pin'] and '5' in loaded['pin']: + pin_3 = loaded['pin']['3'] + pin_5 = loaded['pin']['5'] + if 'mode' in pin_3 and 'mode' in pin_5: + if pin_3['mode'] == 'i2c' and pin_5['mode'] == 'i2c': + details.append('* Uses I2C') + + if 'url' in loaded: + details.append('* [More Information]({url})'.format(url=loaded['url'])) + + if 'github' in loaded: + details.append('* [GitHub Repository]({url})'.format(url=loaded['github'])) + + if 'buy' in loaded: + details.append('* [Buy Now]({url})'.format(url=loaded['buy'])) + + if not 'page_url' in loaded: + loaded['page_url'] = slugify(loaded['name']) + + pages[loaded['page_url']] = loaded + return loaded + +def load_md(filename): + filename = 'src/{}/{}'.format(lang, filename) + try: + html = markdown.markdown(open(filename).read(), extensions=['fenced_code']) + + return html + except IOError: + print('Unable to load markdown from {}'.format(filename)) + return '' + +overlays = map(load_overlay,overlays) + +print(json.dumps(overlays)) \ No newline at end of file diff --git a/resources/pinout.css b/resources/pinout.css index 67e406e..2952aad 100644 --- a/resources/pinout.css +++ b/resources/pinout.css @@ -411,6 +411,9 @@ ol.linenums {margin-left:30px;} #container { width:1200px; } + .board { + right:1200px; + } #content { width:700px; } diff --git a/serve.py b/serve.py index 816d5fb..22b1ece 100755 --- a/serve.py +++ b/serve.py @@ -8,7 +8,6 @@ lang = 'en-GB' @app.route("/") def redirect_to_pinout(): return redirect('/pinout') - @app.route("/resources/") def custom_static(filename): diff --git a/src/en-GB/settings.yaml b/src/en-GB/settings.yaml index 4a1f1c8..4fa569f 100644 --- a/src/en-GB/settings.yaml +++ b/src/en-GB/settings.yaml @@ -26,3 +26,4 @@ overlays: - display-o-tron - dots - traffic-hat +- iqaudio-pi-dac