76 lines
1.7 KiB
Java
76 lines
1.7 KiB
Java
package org.hwo.pulscounter;
|
|
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
|
|
import org.hwo.io.SerialPort;
|
|
import org.hwo.io.servicelink.ServiceLink;
|
|
import org.hwo.pulscounter.ui.AppSettingsListener;
|
|
|
|
public class PulsCounter2Application {
|
|
|
|
static PulsCounter2Application _application;
|
|
public static PulsCounter2Application getApplication(){
|
|
if (_application == null)
|
|
_application = new PulsCounter2Application();
|
|
|
|
return _application;
|
|
}
|
|
|
|
SerialPort serialPort;
|
|
ServiceLink serviceLink;
|
|
|
|
List<AppSettingsListener> appSettingsListeners;
|
|
|
|
public PulsCounter2Application(){
|
|
appSettingsListeners = new LinkedList<AppSettingsListener>();
|
|
}
|
|
|
|
public void addAppSettingsListener(AppSettingsListener listener){
|
|
appSettingsListeners.add(listener);
|
|
}
|
|
public void removeAppSettingsListener(AppSettingsListener listener){
|
|
appSettingsListeners.remove(listener);
|
|
}
|
|
|
|
private void fireServiceLinkChanged(){
|
|
for (AppSettingsListener l: appSettingsListeners){
|
|
l.ServiceLinkChanged(serviceLink);
|
|
}
|
|
}
|
|
|
|
public synchronized SerialPort getSerialPort() {
|
|
return serialPort;
|
|
}
|
|
public synchronized void setSerialPort(SerialPort serialPort) {
|
|
if (serviceLink != null){
|
|
serviceLink.close();
|
|
serviceLink = null;
|
|
}
|
|
this.serialPort = serialPort;
|
|
|
|
fireServiceLinkChanged();
|
|
}
|
|
|
|
public synchronized ServiceLink getServiceLink() {
|
|
if (serviceLink == null){
|
|
if (serialPort != null){
|
|
serviceLink = new ServiceLink(serialPort);
|
|
serviceLink.getSerialPort().setTimeout(200);
|
|
}
|
|
}
|
|
return serviceLink;
|
|
}
|
|
public synchronized void setServiceLink(ServiceLink serviceLink) {
|
|
if (serviceLink != null){
|
|
serviceLink.close();
|
|
}
|
|
this.serviceLink = serviceLink;
|
|
|
|
fireServiceLinkChanged();
|
|
}
|
|
|
|
|
|
|
|
}
|