Skip to content

Commit

Permalink
update host software to fix issues where it prints garbage after runn…
Browse files Browse the repository at this point in the history
…ing for a while
  • Loading branch information
rayshobby committed Dec 16, 2013
1 parent 425834a commit fc72286
Show file tree
Hide file tree
Showing 23 changed files with 216 additions and 21 deletions.
55 changes: 50 additions & 5 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ ShareAlike (CC-SA) 3.0 license.
The folders are organized as follows:

- 'schematic' contains the circuit schematic and part list.
Note that the circuit uses a 12MHz crystal (or resonator).
This is the lowest frequency clock supported by V-USB.
You need to set the mcu fuse bits accordingly to use external
crystal oscillator. See the 'bootloader' folder below.

- 'bootloader' contains the modified USnoobie bootloader
The bootloader is optional, but once flashed, it allows
the mcu to bootload (by pressing the button during power-on
or reset) as a usbasp programmer, so you will not need
any external programer to flash a program.


Check the 'burn.bat' file in the 'bootloader' folder for the
recommended fuse bits.

- 'arduino code' contains the Arduino library for HIDSerial.
To use it:
* copy boards.txt (from hardware/arduino folder)
Expand All @@ -32,12 +39,50 @@ The folders are organized as follows:
* Run Arduino (the recommended version is 1.0.5 or 1.0.4).
* Make sure you select 'USnoobie' from Tools -> Boards
* If you use the USnoobie bootloader, select 'USBasp' from
Tools -> Programmer.
Tools -> Programmer. If not, select the name of the external
ISP programmer you are using to flash the program.
* Select any provided example from File -> Examples -> HIDSerial
* Upload
* Upload the example code to ATmega328.

- 'host software' contains the standalone applications and Processing
source code for HIDSerialMonitor. Please check the README.txt
therein.


- Using the Arduino HIDSerial library:
* The library provides several examples for you to learn how to
get started using the API functions.
* The HIDSerial class is similar to Arduino's Serial class. To
use it, you need to first define a class variable, e.g.

HIDSerial serial;

Then, in your setup() function, call:

serial.begin();

Next, in your loop() function, you can use:

serial.print(...);
serial.println(...);
serial.write(...);

to print values to the host. You can also use:

serial.available();

to check if there is any incoming data, and

serial.read(...);

to read the incoming data to a char buffer. Again,these are similar
to the Arduino's Serial class. The ***main difference***, though,
is that in the loop() you need to call

serial.poll();

as often as you can -- since the USB tasks are simulated in software,
calling serial.poll() frequently ensures the mcu has ample time to
perform USB tasks. This requirement can be relieved in future updates,
but for you please cope with the requirement.

========================================================
2 changes: 2 additions & 0 deletions bootloader/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
NOTE: the original code by Frank Zhao has been slightly modified to use
button on pin PD4 for bootloading condition.

Please check the burn.bat for recommende fuse bits.

==========================================================================

bootloader files for USnooBie, base off USBaspLoader
Expand Down
15 changes: 14 additions & 1 deletion host software/HIDSerialMonitor.pde
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import com.codeminders.hidapi.HIDDevice;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
import java.awt.Font;


GTextArea outputField;
GTextField inputField;
GButton sendButton;
Expand Down Expand Up @@ -72,6 +74,11 @@ public void draw() {
if( device != null && !paused ) {
String result = deviceRead();
if( result != null ) {

if(outputField.stext.getNbrLines() > 100){
int loc = outputField.stext.getPlainText().indexOf("\n",1);
outputField.stext.deleteCharacters(0,loc);
}
outputField.appendText(result);
}
}
Expand Down Expand Up @@ -129,7 +136,7 @@ public HIDDeviceInfo[] deviceFindAllDescriptors() {
public String deviceRead() {
try {
device.disableBlocking();
byte[] data = new byte[8];
byte[] data = new byte[10];
int read = device.read(data);
if (read > 0) {
String str = new String();
Expand Down Expand Up @@ -174,7 +181,13 @@ public void handleButtonEvents(GButton button, GEvent event) {
if (device!=null) {
pauseButton.setEnabled(false);
sendButton.setEnabled(false);
try{
device.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
device = null;
outputField = new GTextArea(this, 0, 100, 405, 400, G4P.SCROLLBARS_VERTICAL_ONLY);
connectButton.setText("Connect");
connectButton.setTextBold();
outputField.appendText("Disconnected.\n");
Expand Down
2 changes: 1 addition & 1 deletion host software/application.linux32/HIDSerialMonitor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

APPDIR=$(dirname "$0")
java -Djava.library.path="$APPDIR:$APPDIR/lib" -cp "$APPDIR/lib/HIDSerialMonitor.jar:$APPDIR/lib/core.jar:$APPDIR/lib/jogl-all.jar:$APPDIR/lib/gluegen-rt.jar:$APPDIR/lib/jogl-all-natives-linux-i586.jar:$APPDIR/lib/gluegen-rt-natives-linux-i586.jar:$APPDIR/lib/core.jar:$APPDIR/lib/G4P.jar:$APPDIR/lib/hidapi.jar" HIDSerialMonitor "$@"
java -Djava.library.path="$APPDIR:$APPDIR/lib" -cp "$APPDIR/lib/HIDSerialMonitor.jar:$APPDIR/lib/core.jar:$APPDIR/lib/jogl-all.jar:$APPDIR/lib/gluegen-rt.jar:$APPDIR/lib/jogl-all-natives-linux-i586.jar:$APPDIR/lib/gluegen-rt-natives-linux-i586.jar:$APPDIR/lib/core.jar:$APPDIR/lib/G4P.jar:$APPDIR/lib/BlinkStick.jar:$APPDIR/lib/hidapi-1.1.jar" HIDSerialMonitor "$@"
Binary file modified host software/application.linux32/lib/HIDSerialMonitor.jar
Binary file not shown.
16 changes: 15 additions & 1 deletion host software/application.linux32/source/HIDSerialMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
import java.awt.Font;

import java.util.HashMap;
Expand All @@ -32,6 +33,8 @@ public class HIDSerialMonitor extends PApplet {





GTextArea outputField;
GTextField inputField;
GButton sendButton;
Expand Down Expand Up @@ -85,6 +88,11 @@ public void draw() {
if( device != null && !paused ) {
String result = deviceRead();
if( result != null ) {

if(outputField.stext.getNbrLines() > 100){
int loc = outputField.stext.getPlainText().indexOf("\n",1);
outputField.stext.deleteCharacters(0,loc);
}
outputField.appendText(result);
}
}
Expand Down Expand Up @@ -142,7 +150,7 @@ public HIDDeviceInfo[] deviceFindAllDescriptors() {
public String deviceRead() {
try {
device.disableBlocking();
byte[] data = new byte[8];
byte[] data = new byte[10];
int read = device.read(data);
if (read > 0) {
String str = new String();
Expand Down Expand Up @@ -187,7 +195,13 @@ public void handleButtonEvents(GButton button, GEvent event) {
if (device!=null) {
pauseButton.setEnabled(false);
sendButton.setEnabled(false);
try{
device.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
device = null;
outputField = new GTextArea(this, 0, 100, 405, 400, G4P.SCROLLBARS_VERTICAL_ONLY);
connectButton.setText("Connect");
connectButton.setTextBold();
outputField.appendText("Disconnected.\n");
Expand Down
15 changes: 14 additions & 1 deletion host software/application.linux32/source/HIDSerialMonitor.pde
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import com.codeminders.hidapi.HIDDevice;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
import java.awt.Font;


GTextArea outputField;
GTextField inputField;
GButton sendButton;
Expand Down Expand Up @@ -60,6 +62,11 @@ public void draw() {
if( device != null && !paused ) {
String result = deviceRead();
if( result != null ) {

if(outputField.stext.getNbrLines() > 100){
int loc = outputField.stext.getPlainText().indexOf("\n",1);
outputField.stext.deleteCharacters(0,loc);
}
outputField.appendText(result);
}
}
Expand Down Expand Up @@ -117,7 +124,7 @@ public HIDDeviceInfo[] deviceFindAllDescriptors() {
public String deviceRead() {
try {
device.disableBlocking();
byte[] data = new byte[8];
byte[] data = new byte[10];
int read = device.read(data);
if (read > 0) {
String str = new String();
Expand Down Expand Up @@ -162,7 +169,13 @@ public void handleButtonEvents(GButton button, GEvent event) {
if (device!=null) {
pauseButton.setEnabled(false);
sendButton.setEnabled(false);
try{
device.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
device = null;
outputField = new GTextArea(this, 0, 100, 405, 400, G4P.SCROLLBARS_VERTICAL_ONLY);
connectButton.setText("Connect");
connectButton.setTextBold();
outputField.appendText("Disconnected.\n");
Expand Down
2 changes: 1 addition & 1 deletion host software/application.linux64/HIDSerialMonitor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

APPDIR=$(dirname "$0")
java -Djava.library.path="$APPDIR:$APPDIR/lib" -cp "$APPDIR/lib/HIDSerialMonitor.jar:$APPDIR/lib/core.jar:$APPDIR/lib/jogl-all.jar:$APPDIR/lib/gluegen-rt.jar:$APPDIR/lib/jogl-all-natives-linux-amd64.jar:$APPDIR/lib/gluegen-rt-natives-linux-amd64.jar:$APPDIR/lib/core.jar:$APPDIR/lib/G4P.jar:$APPDIR/lib/hidapi.jar" HIDSerialMonitor "$@"
java -Djava.library.path="$APPDIR:$APPDIR/lib" -cp "$APPDIR/lib/HIDSerialMonitor.jar:$APPDIR/lib/core.jar:$APPDIR/lib/jogl-all.jar:$APPDIR/lib/gluegen-rt.jar:$APPDIR/lib/jogl-all-natives-linux-amd64.jar:$APPDIR/lib/gluegen-rt-natives-linux-amd64.jar:$APPDIR/lib/core.jar:$APPDIR/lib/G4P.jar:$APPDIR/lib/BlinkStick.jar:$APPDIR/lib/hidapi-1.1.jar" HIDSerialMonitor "$@"
Binary file modified host software/application.linux64/lib/HIDSerialMonitor.jar
Binary file not shown.
16 changes: 15 additions & 1 deletion host software/application.linux64/source/HIDSerialMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
import java.awt.Font;

import java.util.HashMap;
Expand All @@ -32,6 +33,8 @@ public class HIDSerialMonitor extends PApplet {





GTextArea outputField;
GTextField inputField;
GButton sendButton;
Expand Down Expand Up @@ -85,6 +88,11 @@ public void draw() {
if( device != null && !paused ) {
String result = deviceRead();
if( result != null ) {

if(outputField.stext.getNbrLines() > 100){
int loc = outputField.stext.getPlainText().indexOf("\n",1);
outputField.stext.deleteCharacters(0,loc);
}
outputField.appendText(result);
}
}
Expand Down Expand Up @@ -142,7 +150,7 @@ public HIDDeviceInfo[] deviceFindAllDescriptors() {
public String deviceRead() {
try {
device.disableBlocking();
byte[] data = new byte[8];
byte[] data = new byte[10];
int read = device.read(data);
if (read > 0) {
String str = new String();
Expand Down Expand Up @@ -187,7 +195,13 @@ public void handleButtonEvents(GButton button, GEvent event) {
if (device!=null) {
pauseButton.setEnabled(false);
sendButton.setEnabled(false);
try{
device.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
device = null;
outputField = new GTextArea(this, 0, 100, 405, 400, G4P.SCROLLBARS_VERTICAL_ONLY);
connectButton.setText("Connect");
connectButton.setTextBold();
outputField.appendText("Disconnected.\n");
Expand Down
15 changes: 14 additions & 1 deletion host software/application.linux64/source/HIDSerialMonitor.pde
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import com.codeminders.hidapi.HIDDevice;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
import java.awt.Font;


GTextArea outputField;
GTextField inputField;
GButton sendButton;
Expand Down Expand Up @@ -60,6 +62,11 @@ public void draw() {
if( device != null && !paused ) {
String result = deviceRead();
if( result != null ) {

if(outputField.stext.getNbrLines() > 100){
int loc = outputField.stext.getPlainText().indexOf("\n",1);
outputField.stext.deleteCharacters(0,loc);
}
outputField.appendText(result);
}
}
Expand Down Expand Up @@ -117,7 +124,7 @@ public HIDDeviceInfo[] deviceFindAllDescriptors() {
public String deviceRead() {
try {
device.disableBlocking();
byte[] data = new byte[8];
byte[] data = new byte[10];
int read = device.read(data);
if (read > 0) {
String str = new String();
Expand Down Expand Up @@ -162,7 +169,13 @@ public void handleButtonEvents(GButton button, GEvent event) {
if (device!=null) {
pauseButton.setEnabled(false);
sendButton.setEnabled(false);
try{
device.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
device = null;
outputField = new GTextArea(this, 0, 100, 405, 400, G4P.SCROLLBARS_VERTICAL_ONLY);
connectButton.setText("Connect");
connectButton.setTextBold();
outputField.appendText("Disconnected.\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<string>1.6*</string>

<key>ClassPath</key>
<string>$JAVAROOT/HIDSerialMonitor.jar:$JAVAROOT/core.jar:$JAVAROOT/jogl-all.jar:$JAVAROOT/gluegen-rt.jar:$JAVAROOT/jogl-all-natives-macosx-universal.jar:$JAVAROOT/gluegen-rt-natives-macosx-universal.jar:$JAVAROOT/core.jar:$JAVAROOT/G4P.jar:$JAVAROOT/hidapi.jar</string>
<string>$JAVAROOT/HIDSerialMonitor.jar:$JAVAROOT/core.jar:$JAVAROOT/jogl-all.jar:$JAVAROOT/gluegen-rt.jar:$JAVAROOT/jogl-all-natives-macosx-universal.jar:$JAVAROOT/gluegen-rt-natives-macosx-universal.jar:$JAVAROOT/core.jar:$JAVAROOT/G4P.jar:$JAVAROOT/BlinkStick.jar:$JAVAROOT/hidapi-1.1.jar</string>

<!-- http://developer.apple.com/releasenotes/Java/java141/system_properties/chapter_4_section_1.html#//apple_ref/doc/uid/TP30000285 -->
<key>Properties</key>
Expand Down
Binary file not shown.
Loading

0 comments on commit fc72286

Please sign in to comment.