putting json on website

This commit is contained in:
Gordon Williams 2013-11-26 11:53:38 +00:00
parent 27ea8fe997
commit a44c159cde
2 changed files with 112 additions and 11 deletions

91
scripts/build_board_json.py Executable file
View File

@ -0,0 +1,91 @@
#!/usr/bin/python
# This file is part of Espruino, a JavaScript interpreter for Microcontrollers
#
# Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# ----------------------------------------------------------------------------------------
# Builds JS file with info for the board
# ----------------------------------------------------------------------------------------
import subprocess;
import re;
import json;
import sys;
import os;
import importlib;
import string;
scriptdir = os.path.dirname(os.path.realpath(__file__))
basedir = scriptdir+"/../"
sys.path.append(basedir+"scripts");
sys.path.append(basedir+"boards");
import pinutils;
# -----------------------------------------------------------------------------------------
# Now scan AF file
print "Script location "+scriptdir
if len(sys.argv)!=2:
print "ERROR, USAGE: build_board_json.py BOARD_NAME"
exit(1)
boardname = sys.argv[1]
jsonFilename = "boards/"+boardname+".json"
print "JSON_FILENAME "+jsonFilename
print "BOARD "+boardname
# import the board def
board = importlib.import_module(boardname)
# Call the included board_specific file - it sets up 'pins' and 'fill_gaps'
pins = board.get_pins()
pins = pinutils.append_devices_to_pin_list(pins, board)
# -----------------------------------------------------------------------------------------
pinperipherals = {}
for pin in pins:
if pin["name"][0] == 'P':
pin["name"] = pin["name"][1:];
pin["simplefunctions"] = {};
pinfuncs = pin["simplefunctions"]
for func in sorted(pin["functions"]):
if func in pinutils.CLASSES:
name = pinutils.CLASSES[func]
# list for individual pin
if name in pinfuncs:
pinfuncs[name].append(func)
else:
pinfuncs[name] = [ func ];
# now handle more detailed
if name=="SPI" or name=="I2C" or name=="USART":
fs = pinutils.ALLOWED_FUNCTIONS[func].split("|")
periph = fs[0][4:]
periphpin = fs[1][fs[1].rfind("_")+1:]
if not periph in pinperipherals: pinperipherals[periph]={}
if not periphpin in pinperipherals[periph]: pinperipherals[periph][periphpin]=[]
pinperipherals[periph][periphpin].append(pin["name"])
else:
if not name in pinperipherals: pinperipherals[name]={}
if not "" in pinperipherals[name]: pinperipherals[name][""]=[]
pinperipherals[name][""].append(pin["name"]);
boarddata = {
"info" : board.info,
"chip" : board.chip,
"layout" : board.board,
"devices" : board.devices,
"pins" : pins,
"peripherals" : pinperipherals,
};
jsonFile = open(jsonFilename, 'w')
jsonFile.write(json.dumps(boarddata, indent=1));
jsonFile.close();

View File

@ -7,29 +7,39 @@ ESPRUINODOCS=$DIR/../EspruinoDocs
CMSDIR=$DIR/../espruinowebsite/cms
REFERENCEDIR=$DIR/../espruinowebsite/reference
BOARDIMGDIR=$WEBSITEDIR/www/img
JSONDIR=$WEBSITEDIR/www/json
function create_info() {
NICENAME=`python scripts/get_board_name.py $BOARDNAME`
echo $BOARDNAME = $NICENAME
# the board's image
cp boards/img/${BOARDNAME}.* ${BOARDIMGDIR}
# the individual board reference
python scripts/build_board_docs.py ${BOARDNAME} || { echo 'Build failed' ; exit 1; }
grep boards/${BOARDNAME}.html -v -f scripts/website_banned_lines.txt > ${REFERENCEDIR}/Reference${BOARDNAME}.html
# the board JSON
python scripts/build_board_json.py ${BOARDNAME} || { echo 'Build failed' ; exit 1; }
cp boards/${BOARDNAME}.json ${JSONDIR}
}
mkdir $BOARDIMGDIR
mkdir $JSONDIR
# -------------------------------------------- Create the text up the top of the reference
echo Updating Board Docs
echo "<h1>Espruino Hardware Reference</h1>" > NewReference.html
echo "<p>The Espruino Software will run on a variety of boards. The Espruino Board, <a href=\"/kick\">currently on KickStarter</a>, has been specially designed to complement our software and is the only board that we actively support. Please click on the thumbnails below to see diagrams of each board with all pins and their capabilities marked</p>" >> NewReference.html
echo "<h2>Espruino Board - Supported</h2>" >> NewReference.html
BOARDNAME=ESPRUINOBOARD
NICENAME=`python scripts/get_board_name.py $BOARDNAME`
echo $BOARDNAME = $NICENAME
python scripts/build_board_docs.py ${BOARDNAME} || { echo 'Build failed' ; exit 1; }
grep boards/${BOARDNAME}.html -v -f scripts/website_banned_lines.txt > ${REFERENCEDIR}/Reference${BOARDNAME}.html
cp boards/img/${BOARDNAME}.* ${BOARDIMGDIR}
create_info $BOARDNAME
convert boards/img/${BOARDNAME}.* -resize 256x256 ${BOARDIMGDIR}/${BOARDNAME}_thumb.jpg
echo -e "<center><span style=\"text-align:center;margin:10px;width:200px;\"><a href=\"Reference${BOARDNAME}\"><img src=\"img/${BOARDNAME}_thumb.jpg\" alt=\"${NICENAME}\"><br/>${NICENAME}</a></span></center>" >> NewReference.html
echo "<h2>Other Boards - Unsupported</h2>" >> NewReference.html
echo "<div id=\"boards\" style=\"display:inline-block;\">" >> NewReference.html
mkdir $BOARDIMGDIR
for BOARDNAME in STM32VLDISCOVERY STM32F3DISCOVERY STM32F4DISCOVERY OLIMEXINO_STM32 HYSTM32_24 HYSTM32_28 HYSTM32_32
do
NICENAME=`python scripts/get_board_name.py $BOARDNAME`
echo $BOARDNAME = $NICENAME
python scripts/build_board_docs.py ${BOARDNAME} || { echo 'Build failed' ; exit 1; }
grep boards/${BOARDNAME}.html -v -f scripts/website_banned_lines.txt > ${REFERENCEDIR}/Reference${BOARDNAME}.html
cp boards/img/${BOARDNAME}.* ${BOARDIMGDIR}
create_info $BOARDNAME
convert boards/img/${BOARDNAME}.* -resize 128x128 ${BOARDIMGDIR}/${BOARDNAME}_thumb.jpg
echo -e "<span style=\"display:inline-block;text-align:center;margin:10px;width:200px;\"><a href=\"Reference${BOARDNAME}\"><img src=\"img/${BOARDNAME}_thumb.jpg\" alt=\"${NICENAME}\"><br/>${NICENAME}</a></span>" >> NewReference.html
done