public OutputStream getConfigStream() throws IOException {
reset();
- config(0,3);
- con();
- config(0,7);
+ config(0,2);
flush();
return new OutputStream() {
int bytes = 0;
int bits = 0;
public void write(int in) throws IOException {
for(int i=7; i>=0; i--) {
+ bits++;
config((((in & 0xff) & (1<<i))!=0)?1:0, 1);
+ if (bits==1) con();
}
}
public void write(byte[] b, int off, int len) throws IOException {
boolean pin;
getConfigStream();
+ config(0,1);
+ con();
+ config(0,7);
config(Integer.parseInt("10110111", 2), 8);
config(0,1);
flush();
pin = initErr();
System.out.println("good preamble => " + pin + " " + (pin ? green("good") : red("BAD")));
- reset();
- try { Thread.sleep(100); } catch (Exception e) { }
- config(0,3);
+ getConfigStream();
+ config(0,1);
con();
config(0,6);
flush();
- // one too many
config(Integer.parseInt("10110111", 2), 8);
config(0, 2);
flush();
pin = initErr();
System.out.println("bad preamble #2 => " + pin + " " + (pin ? red("BAD") : green("good")));
- reset();
- try { Thread.sleep(100); } catch (Exception e) { }
getConfigStream();
+ config(0,1);
+ con();
+ config(0,7);
config(Integer.parseInt("11110111", 2), 8);
config(0, 1);
flush();