mirror of
https://github.com/braillerap/BrailleRap.git
synced 2025-06-08 01:49:59 +02:00
Tools for NatBraille embossing
This commit is contained in:
parent
b3f8444807
commit
e0441a9224
6
NatBrailleTools/BrailleLogger/.classpath
Normal file
6
NatBrailleTools/BrailleLogger/.classpath
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
17
NatBrailleTools/BrailleLogger/.project
Normal file
17
NatBrailleTools/BrailleLogger/.project
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>BrailleLogger</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
@ -0,0 +1,12 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.source=1.6
|
@ -0,0 +1,2 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
|
BIN
NatBrailleTools/BrailleLogger/bin/Braille2GcodeEncoder.class
Normal file
BIN
NatBrailleTools/BrailleLogger/bin/Braille2GcodeEncoder.class
Normal file
Binary file not shown.
BIN
NatBrailleTools/BrailleLogger/bin/Braille6GcodeEncoding.class
Normal file
BIN
NatBrailleTools/BrailleLogger/bin/Braille6GcodeEncoding.class
Normal file
Binary file not shown.
BIN
NatBrailleTools/BrailleLogger/bin/BrailleGcodeDot.class
Normal file
BIN
NatBrailleTools/BrailleLogger/bin/BrailleGcodeDot.class
Normal file
Binary file not shown.
BIN
NatBrailleTools/BrailleLogger/bin/BrailleGcodeEncoding.class
Normal file
BIN
NatBrailleTools/BrailleLogger/bin/BrailleGcodeEncoding.class
Normal file
Binary file not shown.
BIN
NatBrailleTools/BrailleLogger/bin/BrailleLogger.class
Normal file
BIN
NatBrailleTools/BrailleLogger/bin/BrailleLogger.class
Normal file
Binary file not shown.
BIN
NatBrailleTools/BrailleLogger/bin/GCodeGenerator.class
Normal file
BIN
NatBrailleTools/BrailleLogger/bin/GCodeGenerator.class
Normal file
Binary file not shown.
220
NatBrailleTools/BrailleLogger/src/Braille2GcodeEncoder.java
Normal file
220
NatBrailleTools/BrailleLogger/src/Braille2GcodeEncoder.java
Normal file
@ -0,0 +1,220 @@
|
|||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Braille encoder class
|
||||||
|
* @author crocsg
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Braille2GcodeEncoder {
|
||||||
|
|
||||||
|
private GCodeGenerator generator = new GCodeGenerator ();
|
||||||
|
private int page_num= 0;
|
||||||
|
private int char_cnt_line = 0;
|
||||||
|
|
||||||
|
private BrailleGcodeEncoding encoder;
|
||||||
|
|
||||||
|
private float position_x;
|
||||||
|
private float position_y;
|
||||||
|
|
||||||
|
private ArrayList <Point2D.Float> pagedot;
|
||||||
|
private ArrayList<ArrayList<Point2D.Float>> linedot;
|
||||||
|
private String bufline = "";
|
||||||
|
private String pagegcode = "";
|
||||||
|
|
||||||
|
private final float Braille_cell_width = 2.3f;
|
||||||
|
private final float Braille_cell_height = 2.3f;
|
||||||
|
private final float Braille_cell_padding = 6.1f;
|
||||||
|
private final float Braille_line_padding = 10f;
|
||||||
|
private boolean pageAvailable = false;
|
||||||
|
private boolean newpage=true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the pageAvailable
|
||||||
|
*/
|
||||||
|
public boolean isPageAvailable() {
|
||||||
|
return pageAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the pagegcode
|
||||||
|
*/
|
||||||
|
public String getPagegcode() {
|
||||||
|
return pagegcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
private Braille2GcodeEncoder() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param encoder Braille Encoding
|
||||||
|
*/
|
||||||
|
public Braille2GcodeEncoder(BrailleGcodeEncoding encoder) {
|
||||||
|
this.encoder = encoder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startPage ()
|
||||||
|
{
|
||||||
|
pagedot = new ArrayList <Point2D.Float> ();
|
||||||
|
position_y = 2;//TODO avoid magic
|
||||||
|
pageAvailable = false;
|
||||||
|
newpage = false;
|
||||||
|
pagegcode = "";
|
||||||
|
startLine ();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void endPage ()
|
||||||
|
{
|
||||||
|
if ( ! pagedot.isEmpty())
|
||||||
|
{
|
||||||
|
pagegcode = generator.Header();
|
||||||
|
|
||||||
|
for (Point2D.Float p: pagedot)
|
||||||
|
{
|
||||||
|
pagegcode += generator.moveTo(p.getX(),p.getY());
|
||||||
|
pagegcode += generator.printDot();
|
||||||
|
}
|
||||||
|
pagegcode += generator.Footer();
|
||||||
|
|
||||||
|
|
||||||
|
pageAvailable = true;
|
||||||
|
|
||||||
|
int n = JOptionPane.showConfirmDialog(
|
||||||
|
null,
|
||||||
|
"Page " + (page_num+1) + " chargez le papier quand l'embosseuse est disponible",
|
||||||
|
"BrailleRapSP Embosseuse Braille",
|
||||||
|
JOptionPane.OK_CANCEL_OPTION);
|
||||||
|
if (n == JOptionPane.CANCEL_OPTION)
|
||||||
|
{
|
||||||
|
// cancel print
|
||||||
|
System.exit(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
page_num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startLine ()
|
||||||
|
{
|
||||||
|
linedot = new ArrayList <ArrayList <Point2D.Float>> ();
|
||||||
|
for (int i =0; i < encoder.getNline(); i++ )
|
||||||
|
{
|
||||||
|
linedot.add(new ArrayList<Point2D.Float>());
|
||||||
|
}
|
||||||
|
|
||||||
|
position_x = 0; //TODO avoid magic
|
||||||
|
bufline = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private Point2D.Float getDotAbsolutePosition(Point p)
|
||||||
|
{
|
||||||
|
Point2D.Float absolute = new Point2D.Float();
|
||||||
|
absolute.x = position_x + (float) p.x * Braille_cell_width;
|
||||||
|
absolute.y = position_y + (float) p.y * Braille_cell_height;
|
||||||
|
|
||||||
|
return absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void nextCellPosition ()
|
||||||
|
{
|
||||||
|
this.position_x += Braille_cell_padding;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void nextLinePosition ()
|
||||||
|
{
|
||||||
|
this.position_y += Braille_line_padding;
|
||||||
|
}
|
||||||
|
private void endLine ()
|
||||||
|
{
|
||||||
|
ArrayList<Point> dots;
|
||||||
|
|
||||||
|
// compute braille dots on line
|
||||||
|
for (int i =0; i < bufline.length(); i++)
|
||||||
|
{
|
||||||
|
dots = encoder.GetCharacterDots(bufline.charAt(i));
|
||||||
|
if (dots != null)
|
||||||
|
{
|
||||||
|
for (int d= 0; d < dots.size (); d++)
|
||||||
|
{
|
||||||
|
int x = dots.get(d).x;
|
||||||
|
int y = dots.get(d).y;
|
||||||
|
|
||||||
|
linedot.get(y).add(getDotAbsolutePosition(dots.get(d)));
|
||||||
|
}
|
||||||
|
|
||||||
|
nextCellPosition ();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// store braille absolute dot on page
|
||||||
|
for (int l = 0; l < linedot.size(); l++)
|
||||||
|
{
|
||||||
|
pagedot.addAll(linedot.get(l));
|
||||||
|
}
|
||||||
|
|
||||||
|
nextLinePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addCharToBuffer (char a)
|
||||||
|
{
|
||||||
|
bufline += a;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Open ()
|
||||||
|
{
|
||||||
|
startPage ();
|
||||||
|
}
|
||||||
|
public void processChar (char a)
|
||||||
|
{
|
||||||
|
if (a == '\n')
|
||||||
|
{
|
||||||
|
endLine ();
|
||||||
|
startLine ();
|
||||||
|
}
|
||||||
|
else if (a == 0x0c)
|
||||||
|
endPage ();
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (newpage)
|
||||||
|
startPage();
|
||||||
|
addCharToBuffer (a);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Close ()
|
||||||
|
{
|
||||||
|
endLine ();
|
||||||
|
endPage ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void requestNewPage() {
|
||||||
|
newpage = true;
|
||||||
|
pageAvailable = false;
|
||||||
|
startPage ();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
141
NatBrailleTools/BrailleLogger/src/Braille6GcodeEncoding.java
Normal file
141
NatBrailleTools/BrailleLogger/src/Braille6GcodeEncoding.java
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
import java.awt.Point;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lenovo
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Braille6GcodeEncoding implements BrailleGodeEncoding {
|
||||||
|
private static final BrailleGcodeDot[] dot = new BrailleGcodeDot[] {
|
||||||
|
new BrailleGcodeDot('a', new int[] {1}),
|
||||||
|
new BrailleGcodeDot('b', new int[] {1,2}),
|
||||||
|
new BrailleGcodeDot('c', new int[] {1,4}),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
new BrailleGcodeDot('d', new int[]{1,4,5}),
|
||||||
|
new BrailleGcodeDot('e', new int[] {1,5}),
|
||||||
|
new BrailleGcodeDot('f', new int[]{1,2,4}),
|
||||||
|
new BrailleGcodeDot('g', new int[]{1,2,4,5}),
|
||||||
|
new BrailleGcodeDot('h', new int[]{1,2,5}),
|
||||||
|
new BrailleGcodeDot('i', new int[]{2,4}),
|
||||||
|
new BrailleGcodeDot('j', new int[]{2,4,5}),
|
||||||
|
new BrailleGcodeDot('k', new int[]{1,3}),
|
||||||
|
new BrailleGcodeDot('l', new int[]{1,2,3}),
|
||||||
|
new BrailleGcodeDot('m', new int[]{1,3,4}),
|
||||||
|
new BrailleGcodeDot('n', new int[]{1,3,4,5}),
|
||||||
|
new BrailleGcodeDot('o', new int[]{1,3,5}),
|
||||||
|
new BrailleGcodeDot('p', new int[]{1,2,3,4}),
|
||||||
|
new BrailleGcodeDot('q', new int[]{1,2,3,4,5}),
|
||||||
|
new BrailleGcodeDot('r', new int[]{1,2,3,5}),
|
||||||
|
new BrailleGcodeDot('s', new int[]{2,3,4}),
|
||||||
|
new BrailleGcodeDot('t', new int[]{2,3,4,5}),
|
||||||
|
new BrailleGcodeDot('u', new int[]{1,3,6}),
|
||||||
|
new BrailleGcodeDot('v', new int[]{1,2,3,6}),
|
||||||
|
new BrailleGcodeDot('w', new int[]{2,4,5,6}),
|
||||||
|
new BrailleGcodeDot('x', new int[]{1,3,4,6}),
|
||||||
|
new BrailleGcodeDot('y', new int[]{1,3,4,5,6}),
|
||||||
|
new BrailleGcodeDot('z', new int[]{1,3,5,6}),
|
||||||
|
|
||||||
|
new BrailleGcodeDot(' ', new int[]{}),
|
||||||
|
new BrailleGcodeDot('.', new int[]{2,5,6}),
|
||||||
|
new BrailleGcodeDot(',', new int[]{2}),
|
||||||
|
new BrailleGcodeDot('?', new int[]{2,6}),
|
||||||
|
new BrailleGcodeDot(';', new int[]{2,3}),
|
||||||
|
new BrailleGcodeDot(',', new int[]{2,4}),
|
||||||
|
new BrailleGcodeDot('!', new int[]{2,3,5}),
|
||||||
|
new BrailleGcodeDot('(', new int[]{2,3,6}),
|
||||||
|
new BrailleGcodeDot(')', new int[]{3,5,6}),
|
||||||
|
new BrailleGcodeDot('\'', new int[]{3}),
|
||||||
|
new BrailleGcodeDot('-', new int[]{3,6}),
|
||||||
|
new BrailleGcodeDot('/', new int[]{3,4}),
|
||||||
|
new BrailleGcodeDot('*', new int[]{3,5}),
|
||||||
|
new BrailleGcodeDot('+', new int[]{2,3,5}),
|
||||||
|
new BrailleGcodeDot('=', new int[]{2,3,5,6}),
|
||||||
|
new BrailleGcodeDot('0', new int[]{3, 4, 5, 6}),
|
||||||
|
new BrailleGcodeDot('1', new int[]{1, 6}),
|
||||||
|
new BrailleGcodeDot('2', new int[]{1, 2, 6}),
|
||||||
|
new BrailleGcodeDot('3', new int[]{1, 4, 6}),
|
||||||
|
new BrailleGcodeDot('4', new int[]{1, 4, 5, 6}),
|
||||||
|
new BrailleGcodeDot('5', new int[]{1, 5, 6}),
|
||||||
|
new BrailleGcodeDot('6', new int[]{1, 2, 4, 6}),
|
||||||
|
new BrailleGcodeDot('7', new int[]{1, 2, 4, 5, 6}),
|
||||||
|
new BrailleGcodeDot('8', new int[]{1, 2, 5, 6}),
|
||||||
|
new BrailleGcodeDot('9', new int[]{2, 4, 6}),
|
||||||
|
|
||||||
|
new BrailleGcodeDot('ŕ', new int[]{1, 2, 3,5, 6}),
|
||||||
|
new BrailleGcodeDot('â', new int[]{1, 6}),
|
||||||
|
new BrailleGcodeDot('ç', new int[]{1,2, 3, 4, 6}),
|
||||||
|
new BrailleGcodeDot('č', new int[]{2, 3, 4, 6}),
|
||||||
|
new BrailleGcodeDot('é', new int[]{1, 2, 3, 4, 5, 6}),
|
||||||
|
new BrailleGcodeDot('ę', new int[]{1, 2, 6}),
|
||||||
|
new BrailleGcodeDot('ë', new int[]{1, 2, 4, 6}),
|
||||||
|
new BrailleGcodeDot('î', new int[]{1, 4, 6}),
|
||||||
|
new BrailleGcodeDot('ď', new int[]{1,2, 4, 5, 6}),
|
||||||
|
new BrailleGcodeDot('ů', new int[]{2, 3, 4, 5, 6}),
|
||||||
|
new BrailleGcodeDot('ű', new int[]{1, 5, 6}),
|
||||||
|
new BrailleGcodeDot('ü', new int[]{1, 2, 5, 6}),
|
||||||
|
|
||||||
|
new BrailleGcodeDot('¨', new int[]{1, 3}), // Majuscule NatBraille
|
||||||
|
new BrailleGcodeDot('`', new int[]{3, 4, 5, 6}) // Chiffres NatBraille
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
private final int nrow = 2; // number of row in braille encoding
|
||||||
|
private final int nline = 3; // number of line in braille encoding
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Braille6GcodeEncoding() {
|
||||||
|
super();
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see BrailleGodeEncoding#GetCharacterDots(char)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ArrayList<Point> GetCharacterDots(char a) {
|
||||||
|
//TODO make this fast
|
||||||
|
|
||||||
|
for (int i =0; i < dot.length;i++)
|
||||||
|
{
|
||||||
|
if (dot[i].getCar() == a)
|
||||||
|
{
|
||||||
|
ArrayList<Point> Braille = new ArrayList<Point>();
|
||||||
|
for (int d = 0; d < dot[i].getPos().length; d++)
|
||||||
|
{
|
||||||
|
int x = dot[i].getPos()[d] <= nline ? 0 : 1;
|
||||||
|
int y = dot[i].getPos()[d] <= nline ? dot[i].getPos()[d] - 1 : dot[i].getPos()[d] - 1 - nline;
|
||||||
|
|
||||||
|
Braille.add(new Point(x,y));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Braille;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see BrailleGodeEncoding#getNRow()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int getNRow() {
|
||||||
|
return nrow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see BrailleGodeEncoding#getNline()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int getNline() {
|
||||||
|
return nline;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
52
NatBrailleTools/BrailleLogger/src/BrailleGcodeDot.java
Normal file
52
NatBrailleTools/BrailleLogger/src/BrailleGcodeDot.java
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lenovo
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class BrailleGcodeDot {
|
||||||
|
|
||||||
|
|
||||||
|
private char car;
|
||||||
|
|
||||||
|
public char getCar() {
|
||||||
|
return car;
|
||||||
|
}
|
||||||
|
public void setCar(char car) {
|
||||||
|
this.car = car;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int[] pos;
|
||||||
|
|
||||||
|
public int[] getPos() {
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
public void setPos(int[] pos) {
|
||||||
|
this.pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public BrailleGcodeDot() {
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param car
|
||||||
|
* @param position
|
||||||
|
*/
|
||||||
|
public BrailleGcodeDot(char car, int[] position) {
|
||||||
|
this.car = car;
|
||||||
|
this.pos = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BrailleGcodeDot(char car) {
|
||||||
|
this.car = car;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
18
NatBrailleTools/BrailleLogger/src/BrailleGcodeEncoding.java
Normal file
18
NatBrailleTools/BrailleLogger/src/BrailleGcodeEncoding.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import java.awt.Point;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lenovo
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface BrailleGcodeEncoding {
|
||||||
|
|
||||||
|
public ArrayList<Point> GetCharacterDots (char a);
|
||||||
|
public int getNRow ();
|
||||||
|
public int getNline ();
|
||||||
|
|
||||||
|
}
|
71
NatBrailleTools/BrailleLogger/src/BrailleLogger.java
Normal file
71
NatBrailleTools/BrailleLogger/src/BrailleLogger.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
import java.awt.geom.Point2D;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main program
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lenovo
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class BrailleLogger {
|
||||||
|
|
||||||
|
|
||||||
|
ArrayList <Point2D.Float> braillepoints = new ArrayList <Point2D.Float>();
|
||||||
|
/**
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
System.out.println ("; BrailleRapSP GCODE generator");
|
||||||
|
int arg = 0;
|
||||||
|
for (String s: args)
|
||||||
|
{
|
||||||
|
System.out.println(";" + arg);
|
||||||
|
System.out.println(";" + s);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args[0] != null)
|
||||||
|
{
|
||||||
|
FileReader fr;
|
||||||
|
Braille2GcodeEncoder encoder = new Braille2GcodeEncoder(new Braille6GcodeEncoding());
|
||||||
|
try {
|
||||||
|
fr = new FileReader(args[0]);
|
||||||
|
|
||||||
|
int i;
|
||||||
|
while ((i=fr.read()) != -1)
|
||||||
|
{
|
||||||
|
encoder.processChar((char) i);
|
||||||
|
if (encoder.isPageAvailable())
|
||||||
|
{
|
||||||
|
System.out.println(encoder.getPagegcode());
|
||||||
|
encoder.requestNewPage ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
encoder.Close ();
|
||||||
|
if (encoder.isPageAvailable())
|
||||||
|
{
|
||||||
|
System.out.println(encoder.getPagegcode());
|
||||||
|
|
||||||
|
}
|
||||||
|
fr.close();
|
||||||
|
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
67
NatBrailleTools/BrailleLogger/src/GCodeGenerator.java
Normal file
67
NatBrailleTools/BrailleLogger/src/GCodeGenerator.java
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.text.DecimalFormatSymbols;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lenovo
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GCodeGenerator {
|
||||||
|
|
||||||
|
|
||||||
|
public String Home ()
|
||||||
|
{
|
||||||
|
return ("G28 X\nG28 Y\n");
|
||||||
|
}
|
||||||
|
public String Speed()
|
||||||
|
{
|
||||||
|
return ("G1 F8000\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String Position()
|
||||||
|
{
|
||||||
|
return ("G90\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String Motoroff ()
|
||||||
|
{
|
||||||
|
return "M84\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String Header ()
|
||||||
|
{
|
||||||
|
String gcode = "";
|
||||||
|
gcode = Home ();
|
||||||
|
gcode += Speed ();
|
||||||
|
|
||||||
|
return gcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String Footer ()
|
||||||
|
{
|
||||||
|
// TODO avoid magic
|
||||||
|
String gcode = "G1 X10.00 Y600.00\n"; // eject page
|
||||||
|
gcode += Motoroff ();
|
||||||
|
|
||||||
|
return gcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String moveTo(double x, double y)
|
||||||
|
{
|
||||||
|
DecimalFormatSymbols sym= new DecimalFormatSymbols ();
|
||||||
|
sym.setDecimalSeparator('.');
|
||||||
|
DecimalFormat decimalFormat = new DecimalFormat("##0.000", sym);
|
||||||
|
|
||||||
|
String gcode = "G1 X" + decimalFormat.format(x) + " Y" + decimalFormat.format(y) + "\n";
|
||||||
|
return gcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String printDot() {
|
||||||
|
|
||||||
|
return ("M3 S1\nM3 S0\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
26
NatBrailleTools/simpleJavaGrblStreamer/.classpath
Normal file
26
NatBrailleTools/simpleJavaGrblStreamer/.classpath
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
</classpath>
|
23
NatBrailleTools/simpleJavaGrblStreamer/.project
Normal file
23
NatBrailleTools/simpleJavaGrblStreamer/.project
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>simpleJavaGrblStreamer</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
@ -0,0 +1,3 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding//src/main/java=UTF-8
|
||||||
|
encoding/<project>=UTF-8
|
@ -0,0 +1,5 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||||
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.source=1.6
|
21
NatBrailleTools/simpleJavaGrblStreamer/LICENSE
Normal file
21
NatBrailleTools/simpleJavaGrblStreamer/LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2015 Will Winder
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
9
NatBrailleTools/simpleJavaGrblStreamer/README.md
Normal file
9
NatBrailleTools/simpleJavaGrblStreamer/README.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# simpleJavaGrblStreamer
|
||||||
|
|
||||||
|
A minimal Java application to stream a file to GRBL as quickly as possible.
|
||||||
|
|
||||||
|
Uses a blocking queue to send events from the serial event thread to the main thread which is sending the file.
|
||||||
|
|
||||||
|
Build with "mvn compile assembly:single"
|
||||||
|
|
||||||
|
Run with "java -jar <commPort> <baud> <file>"
|
37
NatBrailleTools/simpleJavaGrblStreamer/pom.xml
Normal file
37
NatBrailleTools/simpleJavaGrblStreamer/pom.xml
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.willwinder.sjgs</groupId>
|
||||||
|
<artifactId>simpleJavaGrblStreamer</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.scream3r</groupId>
|
||||||
|
<artifactId>jssc</artifactId>
|
||||||
|
<version>2.8.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>1.6</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.6</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>com.willwinder.sjgs.simplejavagrblstreamer.SimpleJavaGrblStreamer</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,171 @@
|
|||||||
|
package com.willwinder.sjgs.simplejavagrblstreamer;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import jssc.SerialPort;
|
||||||
|
import jssc.SerialPortEvent;
|
||||||
|
import jssc.SerialPortEventListener;
|
||||||
|
import jssc.SerialPortException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author wwinder
|
||||||
|
*/
|
||||||
|
public class SimpleJavaGrblStreamer {
|
||||||
|
static int GRBL_BUFFER_SIZE = 125;
|
||||||
|
|
||||||
|
public static void main(String argv[]) throws SerialPortException, IOException, InterruptedException {
|
||||||
|
if (argv.length != 3 && argv.length != 2) {
|
||||||
|
System.out.println("Arguments: <comm port> <baud> <file>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String commPort = argv[0];
|
||||||
|
Integer baud = Integer.parseInt(argv[1]);
|
||||||
|
InputStream file = null;
|
||||||
|
if (argv.length == 2)
|
||||||
|
file = System.in;
|
||||||
|
else {
|
||||||
|
file = new FileInputStream(argv[2]);
|
||||||
|
System.out.println("Streaming file " + argv[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Streaming to port <" + commPort + " : " + baud + ">");
|
||||||
|
SimpleJavaGrblStreamer s = new SimpleJavaGrblStreamer(commPort, baud);
|
||||||
|
s.send(file);
|
||||||
|
|
||||||
|
System.out.println("Done senting file.");
|
||||||
|
}
|
||||||
|
|
||||||
|
String commPort = null;
|
||||||
|
Integer baud = null;
|
||||||
|
|
||||||
|
private SimpleJavaGrblStreamer(String commPort, Integer baud) {
|
||||||
|
this.commPort = commPort;
|
||||||
|
this.baud = baud;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void send(InputStream f) throws SerialPortException, IOException, InterruptedException {
|
||||||
|
BlockingQueue<Integer> commandComplete = new LinkedBlockingQueue();
|
||||||
|
|
||||||
|
SerialPort serialPort = new SerialPort(commPort);
|
||||||
|
serialPort.openPort();
|
||||||
|
serialPort.setParams(baud, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE, true, true);
|
||||||
|
|
||||||
|
Thread.sleep(5000);
|
||||||
|
|
||||||
|
serialPort.addEventListener(new GrblSerialListener(serialPort, commandComplete));
|
||||||
|
GrblSerialSender sender = new GrblSerialSender(f, serialPort, commandComplete, GRBL_BUFFER_SIZE);
|
||||||
|
sender.send();
|
||||||
|
serialPort.closePort();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class GrblSerialListener implements SerialPortEventListener {
|
||||||
|
SerialPort serialPort = null;
|
||||||
|
BlockingQueue<Integer> completedCommands;
|
||||||
|
StringBuilder inputBuffer;
|
||||||
|
private GrblSerialListener(SerialPort port, BlockingQueue<Integer> completedCommands) {
|
||||||
|
this.serialPort = port;
|
||||||
|
this.completedCommands = completedCommands;
|
||||||
|
inputBuffer = new StringBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialEvent(SerialPortEvent event) {
|
||||||
|
if(event.isRXCHAR() && event.getEventValue() > 0){
|
||||||
|
try {
|
||||||
|
byte buffer[] = serialPort.readBytes();
|
||||||
|
for (byte b: buffer) {
|
||||||
|
if (b == '\n') {
|
||||||
|
//System.out.println("Received command: " + inputBuffer.toString());
|
||||||
|
if (inputBuffer.toString().startsWith("ok") || inputBuffer.toString().startsWith("error"))
|
||||||
|
completedCommands.add(1);
|
||||||
|
inputBuffer.setLength(0);
|
||||||
|
} else {
|
||||||
|
inputBuffer.append((char)b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SerialPortException ex) {
|
||||||
|
System.out.println(ex);
|
||||||
|
System.out.println("serialEvent");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class GrblSerialSender {
|
||||||
|
InputStream file = null;
|
||||||
|
SerialPort port = null;
|
||||||
|
Integer currentBufferSize = null;
|
||||||
|
Integer maxBufferSize = null;
|
||||||
|
|
||||||
|
BlockingQueue<Integer> completedCommands = null;
|
||||||
|
LinkedList<Integer> activeCommandSizes;
|
||||||
|
|
||||||
|
private GrblSerialSender(InputStream f, SerialPort sp, BlockingQueue<Integer> completedCommands, Integer activeBufferSize) {
|
||||||
|
file = f;
|
||||||
|
port = sp;
|
||||||
|
maxBufferSize = activeBufferSize;
|
||||||
|
currentBufferSize = 0;
|
||||||
|
this.completedCommands = completedCommands;
|
||||||
|
activeCommandSizes = new LinkedList<Integer>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void send() throws IOException {
|
||||||
|
// Java 8
|
||||||
|
//try(Stream<String> lines = Files.lines(Paths.get(file.getAbsolutePath()))){
|
||||||
|
// lines.forEach(s -> sendLine(s));
|
||||||
|
//}
|
||||||
|
|
||||||
|
BufferedReader br = null;
|
||||||
|
try {
|
||||||
|
String sCurrentLine;
|
||||||
|
br = new BufferedReader(new InputStreamReader(file));
|
||||||
|
while ((sCurrentLine = br.readLine()) != null) {
|
||||||
|
sendLine(sCurrentLine);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (br != null)br.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendLine(String s) {
|
||||||
|
// Wait until there is room, if necessary.
|
||||||
|
while (maxBufferSize < (currentBufferSize + s.length() + 1)) {
|
||||||
|
try {
|
||||||
|
//System.out.println("waiting for room.... active command count: " + this.activeCommandSizes.size());
|
||||||
|
|
||||||
|
// Wait for a command to complete
|
||||||
|
completedCommands.take();
|
||||||
|
currentBufferSize -= this.activeCommandSizes.removeFirst();
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
Logger.getLogger(SimpleJavaGrblStreamer.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.out.println("Sending command: " + s.trim());
|
||||||
|
//System.out.printf(".");
|
||||||
|
this.port.writeString(s.trim() + "\n");
|
||||||
|
int commandSize = s.length() + 1;
|
||||||
|
activeCommandSizes.add(commandSize);
|
||||||
|
currentBufferSize += commandSize;
|
||||||
|
} catch (SerialPortException ex) {
|
||||||
|
Logger.getLogger(SimpleJavaGrblStreamer.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user