...
 
Commits (3)
from flask import Flask, render_template, request, send_from_directory, abort, jsonify
from flask import Flask, render_template, request, send_from_directory, abort, jsonify, Response
from flask_cors import CORS
from wtforms import Form, IntegerField, SubmitField
from os.path import join
......@@ -25,17 +25,23 @@ known_models = [
"Trimaran",
]
known_types = {
"svg": ("unfolding", "image/svg+xml"),
"dxf": ("silhouette", "application/dxf"),
"stl": ("stl", "application/sla"),
}
app = Flask(__name__, static_url_path="/static")
CORS(app)
@app.after_request
def add_header(response):
response.cache_control.no_cache = True
return response
def make(f, path, args, mkstl=True, mkdxf=True, mksvg=True):
t = 0.1
# Default thickness: paper
t = 0.05
for p, v in args.iteritems():
try:
......@@ -55,11 +61,7 @@ def make(f, path, args, mkstl=True, mkdxf=True, mksvg=True):
j = FingerJoint(thickness=t)
try:
print join(app.static_folder, path)
f.makeOutput(join(app.static_folder, path), default=False,
unfolding=mksvg, silhouette=mkdxf, stl=mkstl,
thickness = t, joint = j)
ss = f.makeOutput(None, remake=False, default=False,
ss = f.makeOutput(None, default=False,
unfolding=mksvg, silhouette=mkdxf, stl=mkstl,
thickness = t, joint = j)
except Exception as e:
......@@ -92,12 +94,9 @@ def catchall(path):
elif ext == "ajax":
ss = make(f, component, request.form)
return jsonify(ss)
elif ext == "svg":
return send_from_directory(join(app.static_folder, component), "graph-print.svg", as_attachment=True, cache_timeout=-1)
elif ext == "stl":
return send_from_directory(join(app.static_folder, component), "graph-model.stl", as_attachment=True, cache_timeout=-1)
elif ext == "dxf":
return send_from_directory(join(app.static_folder, component), "graph-silhouette.dxf", as_attachment=True, cache_timeout=-1)
elif ext in known_types:
ss = make(f, component, request.args)
return Response(ss[known_types[ext][0]], mimetype=known_types[ext][1])
elif ext:
abort(400)
......
#include "avr/pgmspace.h"
#include "arduino.h"
#include "string_functions.h"
#include <EEPROM.h>
#include "robotLibrary.h"
void setup()
{
robotSetup();
// Enter your setup code below
}
void loop()
{
robotLoop();
// Enter your loop code below
}
\ No newline at end of file
#ifndef INCL_ROBOTLIBRARY_H
#define INCL_ROBOTLIBRARY_H
#include <EEPROM.h>
#define numServos 2
#include "string_functions.h"
#define dataCommand "DATA"
#define dataRequest "GET"
#define uiRequest "UI_DESCRIPTION"
#include "arduino.h"
#include "avr/pgmspace.h"
#define getControllerPin(pinIndex) (int)pgm_read_word(&controllerPins[pinIndex])
#define getPinType(pinIndex) (int)pgm_read_word(&pinTypes[pinIndex])
#define getProtocol(pinIndex) (int)pgm_read_word(&protocol[pinIndex])
#define setDO(pin, newState) (digitalWrite(getControllerPin(pin), newState))
#define setPWM(pin, duty) (analogWrite(getControllerPin(pin), duty))
#define readDI(pin) (digitalRead(getControllerPin(pin)))
#define readAI(pin) (analogRead(getControllerPin(pin)))
#define robotPrintSetup(baud) Serial.begin(baud)
#define robotPrint(toPrint) Serial.print(toPrint)
#define robotPrintln(toPrint) Serial.println(toPrint)
#define numPins 38
// Define pin types
#define DO 0
#define DI 1
#define AO 2
#define AI 3
#define PO 4 // PWM Output
#define PI 5 // PWM Input
#define SO 6 // Servo Output
#define SI 7 // Servo Input
// Define protocol types
#define PROTOCOL_DIRECT 0
#define PROTOCOL_BLUETOOTH 1
#define getPinMateType(pinIndex)(getPinType(pinIndex) == DO ? DI : ( \
getPinType(pinIndex) == DI ? DO : ( \
getPinType(pinIndex) == PO ? PI : ( \
getPinType(pinIndex) == PI ? PO : ( \
getPinType(pinIndex) == AO ? AI : ( \
getPinType(pinIndex) == AI ? AO : ( \
getPinType(pinIndex) == SO ? SI : ( \
getPinType(pinIndex) == SI ? SO : ( \
-1)))))))))
#define set(pin) (setDO(pin, 1))
#define clear(pin) (setDO(pin, 0))
#define threshAI(pin, threshold) (readAI(pin) > threshold)
#define PRINT_DEBUG 1
#if PRINT_DEBUG == 1
#define robotPrintDebug(toPrint) robotPrint(toPrint)
#define robotPrintlnDebug(toPrint) robotPrintln(toPrint)
#define robotPrintSetupDebug(baud) robotPrintSetup(baud)
#else
#define robotPrintDebug(toPrint)
#define robotPrintlnDebug(toPrint)
#define robotPrintSetupDebug(baud)
#endif
#define NUM_DATA_OUTPUTS 4
#define DATA_OUTDEGREE 1
bool setSpeed(int servoNum, int speed);
void calibrateServo(int servoNum);
void getServoOffsets();
void eepromWriteInt(int address, int value);
int eepromReadInt(int address);
int speedToDuty(double speed, int pin);
bool getBluetoothData();
void sendBluetoothData(const char* data);
void processBluetoothData();
bool isBluetoothConnected();
void setPinMode(int pin, int mode);
long getPWMFrequency(int pinIndex);
int setPWMFrequency(int pin, long frequency);
void robotSetup();
void robotLoop();
void processData();
char* getData(int sourceID);
char* getData(int sourceID, int destID);
void processData(const char* data, int sourceID, int* destIDs, int numDestIDs);
void processData(const char* data, int destID);
void processData(const char* data, int sourceID, int destID);
#endif
\ No newline at end of file
#ifndef INCL_STRING_FUNCTIONS
#define INCL_STRING_FUNCTIONS
#include <stdlib.h>
inline int length(const char* source);
inline int indexOf(const char* source, const char* target);
inline bool contains(const char* source, const char* target);
inline void substring(const char* source, int startIndex, int endIndex, char* dest);
inline void substring(const char* source, int startIndex, char* dest);
inline void substring(const char* source, int startIndex, int endIndex, char* dest, int destLength);
inline void trim(char* source, int sourceLength);
inline bool equals(const char* first, const char* second);
inline bool equalsIgnoreCase(const char* first, const char* second);
inline void strcpy(const char* source, char* dest, int destLength);
inline void concat(const char* first, const char* second, char* dest, int destLength);
inline void concatInt(const char* first, int second, char* dest, int destLength);
//============================================================================================
// Gets the length of the character array
//============================================================================================
int length(const char* source)
{
int length = 0;
for(; source[length] != '\0'; length++);
return length;
}
//============================================================================================
// Gets the index of the given string, or -1 if not found
//============================================================================================
int indexOf(const char* source, const char* target)
{
int targetLength = length(target);
int sourceLength = length(source);
int index = -1;
for(int i = 0; i <= sourceLength - targetLength && index == -1; i++)
{
bool foundTarget = true;
for(int n = 0; n < targetLength && i+n < sourceLength; n++)
{
if(source[i+n] != target[n])
foundTarget = false;
}
if(foundTarget)
index = i;
}
return index;
}
//============================================================================================
// Checks if the given string is contained in the source string
//============================================================================================
bool contains(const char* source, const char* target)
{
return indexOf(source, target) >= 0;
}
//============================================================================================
// Returns a substring of the character array
// First is inclusive, second is exclusive
// Returns itself if bounds are bad
// Assumes beginning / end if either bound is negative
//============================================================================================
void substring(const char* source, int startIndex, int endIndex, char* dest)
{
substring(source, startIndex, endIndex, dest, 20);
}
//============================================================================================
// Returns a substring of the character array
// First is inclusive, second is exclusive
// Returns itself if bounds are bad
// Assumes beginning / end if either bound is negative
//============================================================================================
void substring(const char* source, int startIndex, char* dest)
{
substring(source, startIndex, length(source), dest, 30);
}
//============================================================================================
// Returns a substring of the character array
// First is inclusive, second is exclusive
// Returns itself if bounds are bad
// Assumes beginning / end if either bound is negative
//============================================================================================
void substring(const char* source, int startIndex, int endIndex, char* dest, int destLength)
{
char temp[destLength];
if(startIndex < 0)
startIndex == 0;
if(endIndex < 0)
endIndex == 0;
if(endIndex < startIndex)
{
dest[0] = '\0';
return;
}
if(endIndex >= length(source))
endIndex = length(source);
if(destLength < endIndex - startIndex + 1)
{
dest[0] = '\0';
return;
}
for(int i = 0; i < endIndex - startIndex; i++)
{
temp[i] = source[startIndex + i];
}
for(int i = 0; i < endIndex - startIndex; i++)
dest[i] = temp[i];
dest[endIndex - startIndex] = '\0';
}
//============================================================================================
// Removing leading and trailing spaces or new lines
//============================================================================================
void trim(char* source, int sourceLength)
{
char temp[sourceLength];
int startIndex = 0;
int endIndex = length(source)-1;
for(; startIndex < length(source) && (source[startIndex] == ' ' || source[startIndex] == '\n' || source[startIndex] == '\t'); startIndex++);
for(; endIndex >= 0 && (source[endIndex] == ' ' || source[endIndex] == '\n' || source[startIndex] == '\t'); endIndex--);
endIndex++;
substring(source, startIndex, endIndex, temp, sizeof(temp)-1);
strcpy(temp, source, sourceLength-1);
}
//============================================================================================
// Tests if two character arrays are equal
//============================================================================================
bool equals(const char* first, const char* second)
{
if(length(first) != length(second))
return false;
for(int i = 0; i < length(first); i++)
{
if(first[i] != second[i])
return false;
}
return true;
}
//============================================================================================
// Tests if two character arrays are equal, ignoring case
//============================================================================================
bool equalsIgnoreCase(const char* first, const char* second)
{
if(length(first) != length(second))
return false;
for(int i = 0; i < length(first); i++)
{
int firstChar = first[i];
int secondChar = second[i];
// Make them lowercase
if(firstChar >= 'A' && firstChar <= 'Z')
firstChar += 'a' - 'A';
if(secondChar >= 'A' && secondChar <= 'Z')
secondChar += 'a' - 'A';
if(firstChar != secondChar)
return false;
}
return true;
}
//============================================================================================
// Copies one array into the other
//============================================================================================
void strcpy(const char* source, char* dest, int destLength)
{
if(destLength < length(source) + 1)
{
dest[0] = '\0';
return;
}
for(int i = 0; i < length(source); i++)
{
dest[i] = source[i];
}
dest[length(source)] = '\0';
}
//============================================================================================
// Concatenates two character arrays
//============================================================================================
void concat(const char* first, const char* second, char* dest, int destLength)
{
char temp[destLength];
if(destLength < length(first) + length(second) + 1)
{
dest[0] = '\0';
return;
}
for(int i = 0; i < length(first); i++)
temp[i] = first[i];
for(int i = 0; i < length(second); i++)
temp[i + length(first)] = second[i];
temp[length(second) + length(first)] = '\0';
for(int i = 0; i < length(second) + length(first); i++)
dest[i] = temp[i];
dest[length(second) + length(first)] = '\0';
}
//============================================================================================
// Concatenates a character array with an integer
//============================================================================================
void concatInt(const char* first, int second, char* dest, int destLength)
{
char secondChar[10];
itoa(second, secondChar, 10);
concat(first, secondChar, dest, destLength);
}
#endif
\ No newline at end of file
7: 0
9: 4
17: 10
19: 14
\ No newline at end of file
0: <class 'svggen.api.component.Component'>.driver.control
1: <class 'svggen.api.component.Component'>.device.signal
2: <class 'svggen.api.component.Component'>.device.power
3: <class 'svggen.api.component.Component'>.device.ground
4: <class 'svggen.api.component.Component'>.dataFunction.input
5: <class 'svggen.library.ServoMount.ServoMount'>.beam.
6: <class 'svggen.api.component.Component'>.servo.
7: <class 'svggen.api.component.Component'>.dataFunction.output
8: <class 'svggen.library.ESPSeg.ESPSeg'>.right.
9: <class 'svggen.api.component.Component'>.slider.curPosition
10: <class 'svggen.api.component.Component'>.driver.control
11: <class 'svggen.api.component.Component'>.device.signal
12: <class 'svggen.api.component.Component'>.device.power
13: <class 'svggen.api.component.Component'>.device.ground
14: <class 'svggen.api.component.Component'>.dataFunction.input
15: <class 'svggen.library.ServoMount.ServoMount'>.beam.
16: <class 'svggen.api.component.Component'>.servo.
17: <class 'svggen.api.component.Component'>.dataFunction.output
18: <class 'svggen.library.ESPSeg.ESPSeg'>.left.
19: <class 'svggen.api.component.Component'>.slider.curPosition
20: <class 'svggen.library.ESPSeg.ESPSeg'>.wheel3.
21: <class 'svggen.library.ESPSeg.ESPSeg'>.wheel3hole.
22: <class 'svggen.library.ESPSeg.ESPSeg'>.wheel2.
23: <class 'svggen.library.ESPSeg.ESPSeg'>.wheel2hole.
24: <class 'svggen.library.ESPSeg.ESPSeg'>.sheathsplit.
25: <class 'svggen.library.ESPSeg.ESPSeg'>.sheath.
26: <class 'svggen.api.component.Component'>.beam.
27: <class 'svggen.library.ESPSeg.ESPSeg'>.wheel5.
28: <class 'svggen.library.ESPSeg.ESPSeg'>.wheel5hole.
29: <class 'svggen.library.ESPSeg.ESPSeg'>.wheel4.
30: <class 'svggen.library.ESPSeg.ESPSeg'>.wheel4hole.
31: <class 'svggen.library.ESPSeg.ESPSeg'>.tailsplit.
32: <class 'svggen.library.ESPSeg.ESPSeg'>.tail.
33: <class 'svggen.library.ESPSeg.ESPSeg'>.usb.
34: <class 'svggen.library.ESPSeg.ESPSeg'>.wheel1.
35: <class 'svggen.library.ESPSeg.ESPSeg'>.wheel1hole.
36: <class 'svggen.library.ESPSeg.ESPSeg'>.wheel0.
37: <class 'svggen.library.ESPSeg.ESPSeg'>.wheel0hole.
Wiring Instructions:
Device <class 'svggen.api.component.Component'>.device:
Connect signal to Pin 2 of ESP8266
Connect power to VCC of ESP8266
Connect ground to GND of ESP8266
Device <class 'svggen.api.component.Component'>.device:
Connect signal to Pin 3 of ESP8266
Connect power to VCC of ESP8266
Connect ground to GND of ESP8266
\ No newline at end of file
......@@ -115,16 +115,44 @@ function svgreload(svgmodel) {
swapSVG(document.getElementById('dxf'), svgmodel);
}
function directlink(ext) {
var formdata = new FormData(paramform);
url = component + "." + ext + "?" + (new URLSearchParams(formdata)).toString();
return url;
}
function makelink(par, ext, data) {
filename = component + "." + ext;
var element = document.createElement('a');
element.innerHTML = "Download ." + ext;
//element.setAttribute('download', filename);
element.href = directlink(ext);
// element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(data));
par.appendChild(element);
par.appendChild(document.createElement('br'));
}
function makelinks(data) {
var par = document.getElementById('downloads');
par.innerHTML = "";
makelink(par, "stl", data["stl"]);
makelink(par, "dxf", data["silhouette"]);
makelink(par, "svg", data["unfolding"]);
}
function remake() {
var xhr = new XMLHttpRequest();
var formdata = new FormData(paramform);
console.log(new URLSearchParams(formdata).toString())
console.log(directlink("stl"));
// Define what happens on successful data submission
xhr.addEventListener("load", function(event) {
console.log('success: ');
data = JSON.parse(event.target.responseText);
console.log(Object.keys(data))
makelinks(data);
stlreload(data["stl"]);
svgreload(data["unfolding"]);
});
......
body {
overflow: hidden;
margin: 0;
padding: 0;
background: lightsteelblue;
}
#downloads {
position: fixed;
bottom: 0;
left: 0;
padding: 1vw;
font-size: 1.5em;
}
#params {
position: fixed;
top: 0;
left: 0;
width: 20vw;
padding: 1vw;
}
#stl {
position: fixed;
top: 0;
right: 0;
width: 80vw;
height: 70vh;
}
#dxf {
background: aliceblue;
position: fixed;
bottom: 0;
right: 0;
width: 80vw;
height: 30vh;
padding: 5px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="static/styles.css">
<script src="static/three.js"></script>
<script src="static/Detector.js"></script>
<script src="static/OrbitControls.js"></script>
<script src="static/STLLoader.js"></script>
<style>
body {
overflow: hidden;
margin: 0;
padding: 0;
background: lightsteelblue;
}
#downloads {
position: fixed;
bottom: 0;
left: 0;
padding: 1vw;
font-size: 1.5em;
}
#params {
position: fixed;
top: 0;
left: 0;
width: 20vw;
padding: 1vw;
}
#stl {
position: fixed;
top: 0;
right: 0;
width: 80vw;
height: 70vh;
}
#dxf {
background: aliceblue;
position: fixed;
bottom: 0;
right: 0;
width: 80vw;
height: 30vh;
padding: 5px;
}
</style>
</head>
<body>
<div id="downloads">
<a href="{{ component }}.stl?{{ query }}">Download STL</a>
<br>
<a href="{{ component }}.dxf?{{ query }}">Download DXF</a>
</div>
<div id="params">
<h2>{{ component }}</h2>
......@@ -70,7 +23,7 @@
<br><br>
Material:
<select name="$thickness">
<option value="0.1">Paper</option>
<option value="0.05">Paper</option>
<option value="3">3mm plywood</option>
<option value="5">5mm plywood</option>
</select> <br><br>
......@@ -79,9 +32,14 @@
</form>
</div>
<div id="downloads"></div>
<div id="stl"></div>
<div id="dxf"></div>
<script>
var component = "{{ component }}";
</script>
<script src="static/svgpan.js"></script>
<script src="static/my.js"></script>
......