Bug in 7 bit 2's complement code fixed

pull/4/head
Reenforcements 2018-11-18 13:33:32 -05:00
rodzic 4a7872f67d
commit a59473d7e5
3 zmienionych plików z 186 dodań i 122 usunięć

Wyświetl plik

@ -2,7 +2,6 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="0b5af789-e47c-4138-bdb9-8fa765481e1e" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/LOG.md" beforeDir="false" afterPath="$PROJECT_DIR$/LOG.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/PECRender/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/PECRender/main.py" afterDir="false" />
</list>
@ -15,7 +14,7 @@
<component name="CoverageDataManager">
<SUITE FILE_PATH="coverage/PES_Embroidery$svgImport.coverage" NAME="svgImport Coverage Results" MODIFIED="1541478220694" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/src/learning" />
<SUITE FILE_PATH="coverage/PES_Embroidery$main.coverage" NAME="main Coverage Results" MODIFIED="1542424584074" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/src" />
<SUITE FILE_PATH="coverage/PES_Embroidery$PECRender_main.coverage" NAME="PECRender-main Coverage Results" MODIFIED="1542515370890" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/PECRender" />
<SUITE FILE_PATH="coverage/PES_Embroidery$PECRender_main.coverage" NAME="PECRender-main Coverage Results" MODIFIED="1542565942147" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/PECRender" />
<SUITE FILE_PATH="coverage/PES_Embroidery$main__1_.coverage" NAME="PECRender-main Coverage Results" MODIFIED="1542509072203" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/PECRender" />
</component>
<component name="FUSProjectUsageTrigger">
@ -34,25 +33,25 @@
<usages-collector id="statistics.vcs.git.usages" />
<usages-collector id="statistics.file.types.edit">
<counts>
<entry key="Python" value="14350" />
<entry key="Python" value="15613" />
</counts>
</usages-collector>
<usages-collector id="statistics.js.language.service.starts" />
<usages-collector id="statistics.file.types.open">
<counts>
<entry key="Python" value="15" />
<entry key="Python" value="16" />
<entry key="UML" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.open">
<counts>
<entry key="JavaScript-modules-diagram//Users/imaustyn/Documents/MiamiUniversity/ECE 487/Project/PES-Embroidery" value="1" />
<entry key="py" value="15" />
<entry key="py" value="16" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.edit">
<counts>
<entry key="py" value="14350" />
<entry key="py" value="15613" />
</counts>
</usages-collector>
</session>
@ -62,8 +61,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="345">
<caret line="28" column="12" selection-start-line="28" selection-start-column="12" selection-end-line="28" selection-end-column="12" />
<state relative-caret-position="157">
<caret line="15" lean-forward="true" selection-start-line="15" selection-end-line="15" />
<folding>
<element signature="e#0#15#0" expanded="true" />
</folding>
@ -74,8 +73,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/PES.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2145">
<caret line="143" column="14" selection-start-line="143" selection-start-column="14" selection-end-line="143" selection-end-column="14" />
<state relative-caret-position="263">
<caret line="148" column="7" selection-start-line="148" selection-start-column="7" selection-end-line="148" selection-end-column="7" />
<folding>
<marker date="1542488383227" expanded="true" signature="91:168" ph="..." />
<marker date="1542488383227" expanded="true" signature="345:385" ph="..." />
@ -91,19 +90,26 @@
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/PECRender/main.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="131">
<caret line="103" column="28" lean-forward="true" selection-start-line="103" selection-start-column="28" selection-end-line="103" selection-end-column="28" />
<state relative-caret-position="330">
<caret line="22" column="9" lean-forward="true" selection-start-line="22" selection-start-column="9" selection-end-line="22" selection-end-column="9" />
<folding>
<element signature="e#0#10#0" expanded="true" />
<marker date="1542515370218" expanded="true" signature="248:345" ph="..." />
<marker date="1542515370218" expanded="true" signature="2268:2457" ph="..." />
<marker date="1542515370218" expanded="true" signature="2723:3990" ph="..." />
<marker date="1542515370218" expanded="true" signature="4326:4330" ph="..." />
<marker date="1542565941388" expanded="true" signature="272:446" ph="..." />
<marker date="1542565941388" expanded="true" signature="6154:6158" ph="..." />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file:///usr/local/lib/python2.7/site-packages/pyglet/graphics/vertexdomain.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="372">
<caret line="454" lean-forward="true" selection-start-line="454" selection-end-line="454" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/svgFunctions.py">
<provider selected="true" editor-type-id="text-editor">
@ -163,6 +169,11 @@
<find>End stitches</find>
<find>Beep</find>
<find>color</find>
<find>color change</find>
<find>Color change</find>
<find>png</find>
<find>width</find>
<find>getCoordinate</find>
</findStrings>
</component>
<component name="Git.Settings">
@ -410,13 +421,6 @@
</state>
</provider>
</entry>
<entry file="file:///usr/local/lib/python2.7/site-packages/pyglet/graphics/vertexdomain.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="192">
<caret line="114" selection-start-line="114" selection-end-line="114" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/lib/python2.7/site-packages/pyglet/app/__init__.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="199">
@ -424,31 +428,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="345">
<caret line="28" column="12" selection-start-line="28" selection-start-column="12" selection-end-line="28" selection-end-column="12" />
<folding>
<element signature="e#0#15#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/PES.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2145">
<caret line="143" column="14" selection-start-line="143" selection-start-column="14" selection-end-line="143" selection-end-column="14" />
<folding>
<marker date="1542488383227" expanded="true" signature="91:168" ph="..." />
<marker date="1542488383227" expanded="true" signature="345:385" ph="..." />
<marker date="1542488383227" expanded="true" signature="1480:3114" ph="..." />
<marker date="1542488383227" expanded="true" signature="3292:3370" ph="..." />
<marker date="1542488383227" expanded="true" signature="3384:3423" ph="..." />
<marker date="1542488383227" expanded="true" signature="3464:3469" ph="..." />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/svgFunctions.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255">
@ -483,16 +462,46 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/PES.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="263">
<caret line="148" column="7" selection-start-line="148" selection-start-column="7" selection-end-line="148" selection-end-column="7" />
<folding>
<marker date="1542488383227" expanded="true" signature="91:168" ph="..." />
<marker date="1542488383227" expanded="true" signature="345:385" ph="..." />
<marker date="1542488383227" expanded="true" signature="1480:3114" ph="..." />
<marker date="1542488383227" expanded="true" signature="3292:3370" ph="..." />
<marker date="1542488383227" expanded="true" signature="3384:3423" ph="..." />
<marker date="1542488383227" expanded="true" signature="3464:3469" ph="..." />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="157">
<caret line="15" lean-forward="true" selection-start-line="15" selection-end-line="15" />
<folding>
<element signature="e#0#15#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file:///usr/local/lib/python2.7/site-packages/pyglet/graphics/vertexdomain.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="372">
<caret line="454" lean-forward="true" selection-start-line="454" selection-end-line="454" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/PECRender/main.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="131">
<caret line="103" column="28" lean-forward="true" selection-start-line="103" selection-start-column="28" selection-end-line="103" selection-end-column="28" />
<state relative-caret-position="330">
<caret line="22" column="9" lean-forward="true" selection-start-line="22" selection-start-column="9" selection-end-line="22" selection-end-column="9" />
<folding>
<element signature="e#0#10#0" expanded="true" />
<marker date="1542515370218" expanded="true" signature="248:345" ph="..." />
<marker date="1542515370218" expanded="true" signature="2268:2457" ph="..." />
<marker date="1542515370218" expanded="true" signature="2723:3990" ph="..." />
<marker date="1542515370218" expanded="true" signature="4326:4330" ph="..." />
<marker date="1542565941388" expanded="true" signature="272:446" ph="..." />
<marker date="1542565941388" expanded="true" signature="6154:6158" ph="..." />
</folding>
</state>
</provider>

8
LOG.md
Wyświetl plik

@ -1,3 +1,11 @@
# 11/18
Y axis was flipped apparently.
It seems to be mostly working, but it's getting off track somehow. I think I'm missing a key command in these stitches somewhere. Some of the stitches probably have special meaning that I'm using as coordinates and that's distorting things.
I WAS STILL DOING THE TWO'S COMPLEMENT MATH INCORRECTLY AHHHHH
# 11/17
These documentation pages I found have contradictory information XD. I'm just going to do my best and hope it works and doesn't end up breaking my machine somehow.

Wyświetl plik

@ -2,6 +2,8 @@ import sys
import pyglet
import struct
import random
import math
import time
from ctypes import c_byte, c_short
# Make a new window to render into
@ -11,6 +13,7 @@ window.set_location(300, 0)
pyglet.gl.glClearColor(0.4,0.4,0.4,1)
filepath = "/Users/imaustyn/Documents/MiamiUniversity/ECE 487/Project/Understanding2/tux.pes"
#filepath = "/Users/imaustyn/Downloads/Circle embroidery designs/Circle.pes"
# Global variables
class Global:
@ -19,22 +22,26 @@ class Global:
x = 0
y = 0
file = None
scale = 8.0
xOffset = 500
yOffset = 500
xScale = 4.0
yScale = 4.0
xOffset = 500.0
yOffset = 500.0
testColors = [(244, 238, 66), (255,255,255), (0,0,0)]
colorIndex = 0
@classmethod
def addLine(cls, x1, y1, x2, y2, r, g, b):
cls.batch.add(2, pyglet.gl.GL_LINES, None,
('v2f', ((x1 / cls.scale) + cls.xOffset,
(y1 / cls.scale) + cls.yOffset,
(x2 / cls.scale) + cls.xOffset,
(y2 / cls.scale) + cls.yOffset )),
('v2f', ((x1 / cls.xScale) + cls.xOffset,
(y1 / cls.yScale) + cls.yOffset,
(x2 / cls.xScale) + cls.xOffset,
(y2 / cls.yScale) + cls.yOffset )),
('c3B', (r,g,b, r,g,b))
)
print("addLine from ({}, {}) to ({}, {})".format(x1, y1, x2, y2) )
cls.x = x2
cls.y = y2
cls.x = int(x2)
cls.y = int(y2)
@classmethod
def readPECHeader(cls):
@ -70,69 +77,105 @@ class Global:
print("Width and height of design: {}, {}".format(width, height))
print("Starting stitches at location: {}".format(f.tell()))
def readBytes(f, num):
bytes = f.read(num)
s = ""
for b in bytes:
s = s + hex(ord(b))
print("Read: {}".format(s))
return bytes
# I'm pretty sure one coordinate can be the long form
# and the second one is short or vice versa. I initially
# thought they had to come in pairs but that didn't seem
# to be working so let's try it this way.
def getCoordinate(f):
peek = f.read(1)
f.seek(f.tell() - 1)
if len(peek) is 0 or peek is None:
return "End"
if peek == 0xFF:
print("End stitches")
return "End"
peekByte = struct.unpack("B", peek)[0]
if (peekByte & 0x80) > 0:
# Double length
c = struct.unpack(">H", readBytes(f,2) )[0]
print("Beep: {}".format(hex(c)))
# Color change
if c == 0xFEB0:
print("Color change")
return 0
# Verify
if (c & 0x8000) == 0:
print("Double length stitch didn't have leading 1.")
sys.exit(0)
c = c_short((c & 0x07FF) + (0xF800 if ((c & 0x0800) > 0) else 0)).value
return c
else:
# Single length coordinate
c = struct.unpack("B", readBytes(f,1) )[0]
if (c & 0x80) != 0:
print("Single length stitch didn't have leading 0.")
sys.exit(0)
c = c_byte( (c & 0x3F) + (0xc0 if ((c & 0x40) > 0) else 1) ).value
return c
# Get the starting point
Global.x = -Global.getCoordinate(f)
Global.y = Global.getCoordinate(f)
Global.addLine(Global.x, Global.y, width, 0,
(Global.testColors[Global.colorIndex])[0],
(Global.testColors[Global.colorIndex])[1],
(Global.testColors[Global.colorIndex])[2])
Global.addLine(Global.x, Global.y, Global.x + 0, Global.y + height,
(Global.testColors[Global.colorIndex])[0],
(Global.testColors[Global.colorIndex])[1],
(Global.testColors[Global.colorIndex])[2])
Global.addLine(Global.x, Global.y, Global.x + -width, Global.y + 0,
(Global.testColors[Global.colorIndex])[0],
(Global.testColors[Global.colorIndex])[1],
(Global.testColors[Global.colorIndex])[2])
Global.addLine(Global.x, Global.y, Global.x + 0, Global.y + -height,
(Global.testColors[Global.colorIndex])[0],
(Global.testColors[Global.colorIndex])[1],
(Global.testColors[Global.colorIndex])[2])
while True:
x = getCoordinate(f)
y = getCoordinate(f)
# I'm pretty sure one coordinate can be the long form
# and the second one is short or vice versa. I initially
# thought they had to come in pairs but that didn't seem
# to be working so let's try it this way.
@classmethod
def getCoordinate(cls, f):
peek = f.read(1)
f.seek(f.tell() - 1)
if len(peek) is 0 or peek is None:
return "End"
if peek == 0xFF:
print("End stitches")
return "End"
peekByte = struct.unpack("B", peek)[0]
if (peekByte & 0x80) > 0:
# Double length
c = struct.unpack(">H", Global.readBytes(f, 2))[0]
print("Beep: {}".format(hex(c)))
# Color change
if c == 0xFEB0:
Global.colorIndex = struct.unpack("b", Global.readBytes(f, 1))[0]
print("Color change to {}".format(Global.colorIndex))
return None
# Verify
if (c & 0x8000) == 0:
print("Double length stitch didn't have leading 1.")
sys.exit(0)
c = c_short((c & 0x07FF) + (0xF800 if ((c & 0x0800) > 0) else 0)).value
return c
else:
# Single length coordinate
c = struct.unpack("B", Global.readBytes(f, 1))[0]
if (c & 0x80) != 0:
print("Single length stitch didn't have leading 0.")
sys.exit(0)
print(c)
# c = c_byte( (c & 0x3F) | (0xc0 if ((c & 0x40) > 0) else 0) ).value
c = c_byte(((c & 0b01000000) << 1) | c).value
return c
@classmethod
def readBytes(cls, f, num):
bytes = f.read(num)
s = ""
for b in bytes:
s = s + hex(ord(b))
print("Read: {}".format(s))
return bytes
@classmethod
def stepRendering(cls, stepBy):
f = cls.file
for i in range(0,stepBy):
x = cls.getCoordinate(f)
if x is None:
continue
y = -cls.getCoordinate(f)
if y is None:
continue
if x is "End" or y is "End":
break
cls.addLine(Global.x, Global.y, Global.x + x, Global.y + y, int(random.uniform(0,255)), int(random.uniform(0,255)), int(random.uniform(0,255)))
print("Done rendering")
print("({},{})".format(x,y))
cls.addLine(Global.x, Global.y, Global.x + x, Global.y + y,
(Global.testColors[Global.colorIndex])[0],
(Global.testColors[Global.colorIndex])[1],
(Global.testColors[Global.colorIndex])[2])
@ -147,6 +190,12 @@ def on_key_press(symbol, modifiers):
if symbol is pyglet.window.key.P:
pauseEmbroidery = ~(pauseEmbroidery)
if symbol is pyglet.window.key.S:
if modifiers & pyglet.window.key.MOD_SHIFT:
Global.stepRendering(300)
else:
Global.stepRendering(1)
@window.event
def on_key_release(symbol, modifiers):
None
@ -154,7 +203,7 @@ def on_key_release(symbol, modifiers):
def updateDisplay(s):
window.clear()
pyglet.gl.glLineWidth(8)
pyglet.gl.glLineWidth(2)
# Stitch a line
@ -185,5 +234,3 @@ pyglet.app.run()