Skip to content

Commit a002d2f

Browse files
author
Guillaume Revaillot
committed
add STM32OperationProgressListener
1 parent 2cbd42d commit a002d2f

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/main/java/org/stm32flash/STM32Device.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.stm32flash;
22

33
import java.io.IOException;
4+
import java.util.ArrayList;
45
import java.util.Arrays;
56
import java.util.concurrent.TimeoutException;
67

@@ -126,6 +127,17 @@ public STM32Device(STM32UsartInterface iface, boolean debug) {
126127
mDebug = debug;
127128
}
128129

130+
ArrayList<STM32OperationProgressListener> mListeners = new ArrayList();
131+
132+
public void registerProgressListener(STM32OperationProgressListener l) {
133+
mListeners.add(l);
134+
}
135+
136+
public void unregisterProgressListener(STM32OperationProgressListener l) {
137+
if (mListeners.contains(l))
138+
mListeners.remove(l);
139+
}
140+
129141
public boolean connect() throws IOException, TimeoutException {
130142
if (!mIsConnected) {
131143
// stm init will return nack if already connected - dont run it twice.

src/main/java/org/stm32flash/STM32Flasher.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ public STM32Device getDevice() {
2020
return mSTM32Device;
2121
}
2222

23+
public void registerProgressListener(STM32OperationProgressListener l) {
24+
mSTM32Device.registerProgressListener(l);
25+
}
26+
27+
public void unregisterProgressListener(STM32OperationProgressListener l) {
28+
mSTM32Device.unregisterProgressListener(l);
29+
}
30+
2331
public boolean connect() throws IOException, TimeoutException {
2432
if (!mSTM32Device.connect()) {
2533
System.err.println("Could not connect to STM32 device.");
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.stm32flash;
2+
3+
public interface STM32OperationProgressListener {
4+
public void completed(boolean successfull);
5+
public void progress(long current, long total);
6+
}

0 commit comments

Comments
 (0)