Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added io.sloeber.ui/icons/timestamp_console.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions io.sloeber.ui/src/io/sloeber/ui/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public class Messages extends NLS {
public static final String EMAIL = "{EMAIL}"; //$NON-NLS-1$
public static final String URL = "{URL}"; //$NON-NLS-1$



public static String Invalid_Private_Hardware_folder;
public static String Invalid_Private_Library_folder;


public static String always;
public static String arduino_upload_project_handler_build_failed;
public static String arduino_upload_project_handler_build_failed_so_no_upload;
Expand Down Expand Up @@ -86,6 +86,7 @@ public class Messages extends NLS {
public static String serialMonitorRemoveSerialPortFromMonitor;
public static String serialMonitorReset;
public static String serialMonitorScrollLock;
public static String serialMonitorShowTimestamps;
public static String serialMonitorSend;
public static String serial_listener_error;
public static String set_or_remove_password;
Expand Down
25 changes: 17 additions & 8 deletions io.sloeber.ui/src/io/sloeber/ui/helpers/MyPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
/**
* ArduinoPreferences is a class containing only static methods that help
* managing the preferences.
*
*
* @author Jan Baeyens
*
*
*/
public class MyPreferences {

Expand All @@ -29,22 +29,23 @@ public class MyPreferences {
public static final String KEY_CLEAN_MONITOR_AFTER_UPLOAD = "Clean Serial Monitor after upload"; //$NON-NLS-1$
public static final String KEY_ENABLE_PARALLEL_BUILD_FOR_NEW_PROJECTS = "Enable parallel build for new projects"; //$NON-NLS-1$
public static final String KEY_AUTO_INSTALL_LIBRARIES = "Gui entry for install libraries"; //$NON-NLS-1$

public static final boolean DEFAULT_OPEN_SERIAL_WITH_MONITOR = true;
// Serial monitor keys
private static final String KEY_SERIAL_RATE = "Serial monitor last selected rate"; //$NON-NLS-1$
private static final String KEY_SERIAL_PORT = "Serial monitor last selected Port"; //$NON-NLS-1$
private static final String KEY_RXTX_LAST_USED_LINE_INDES = "Serial Monitor Last Used Line Ending index"; //$NON-NLS-1$
private static final String KEY_RXTX_LAST_USED_AUTOSCROLL = "Serial Monitor Last Used auto scroll setting"; //$NON-NLS-1$
private static final String KEY_RXTX_LAST_USED_TIMESTAMPS = "Serial Monitor Last Used show timestamps setting"; //$NON-NLS-1$
private static final String KEY_LAST_USED_PLOTTER_FILTER_MENU_OPTION = "Board plotter filter on off"; //$NON-NLS-1$
private static final String KEY_HIDE_JSON_FILES = "Hide json files in preferences platform selection page"; //$NON-NLS-1$


/***
* get the stored option whether a build before the upload is wanted or not.
* If nothing is stored the option is ask and this method will pop up a
* dialogbox
*
*
* @return true if a build is wanted before upload false if no build is
* wanted before upload
*/
Expand Down Expand Up @@ -190,7 +191,7 @@ public static boolean getEnableParallelBuildForNewProjects() {
/**
* This method returns the index of the last used line ending options are CR
* LF CR+LF none
*
*
* @return the index of the last used setting
*/
public static int getLastUsedSerialLineEnd() {
Expand All @@ -200,7 +201,7 @@ public static int getLastUsedSerialLineEnd() {
/**
* This method returns the index of the last used line ending options are CR
* LF CR+LF none
*
*
* @return the index of the last used setting
*/
public static void setLastUsedSerialLineEnd(int index) {
Expand All @@ -216,6 +217,14 @@ public static void setLastUsedAutoScroll(boolean autoScroll) {

}

public static boolean getLastUsedShowTimestamps() {
return getGlobalBoolean(KEY_RXTX_LAST_USED_TIMESTAMPS, false);
}

public static void setLastUsedShowTimestamps(boolean showTimestamps) {
setGlobalValue(KEY_RXTX_LAST_USED_TIMESTAMPS, showTimestamps);
}

public static void setCleanSerialMonitorAfterUpload(boolean newFilter) {
setGlobalValue(KEY_CLEAN_MONITOR_AFTER_UPLOAD, newFilter);
}
Expand Down Expand Up @@ -260,7 +269,7 @@ public static boolean getHideJson() {
public static void setHideJson(boolean state) {
setGlobalValue(KEY_HIDE_JSON_FILES, state);
}

public static boolean getAutomaticallyInstallLibrariesOption() {
return getGlobalBoolean(KEY_AUTO_INSTALL_LIBRARIES,Defaults.autoInstallLibraries);
}
Expand Down
1 change: 1 addition & 0 deletions io.sloeber.ui/src/io/sloeber/ui/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ serialMonitorNoMoreSerialPortsSupported=Maximum number of serial ports is used
serialMonitorRemoveSerialPortFromMonitor=Remove a serial port from the monitor
serialMonitorReset=Reset
serialMonitorScrollLock=Scroll Lock
serialMonitorShowTimestamps=Prefix messages with timestamps
serialMonitorSend=Send
serial_listener_error=Serial Montor: There are supposedly {NUMBER} channels to read
set_or_remove_password=Set or remove password.
Expand Down
1 change: 1 addition & 0 deletions io.sloeber.ui/src/io/sloeber/ui/messages_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ serialMonitorNoMoreSerialPortsSupported=Numero massimo di porte seriali utilizza
serialMonitorRemoveSerialPortFromMonitor=Elimina una porta seriale dal monitor
serialMonitorReset=Reset
serialMonitorScrollLock=Blocca scorrimento
serialMonitorShowTimestamps=Prefix messages with timestamps
serialMonitorSend=Invia
serial_listener_error=Monitor seriale: sono stati identificati {NUMBER} canali da leggere
set_or_remove_password=Imposta o rimuove la password.
Expand Down
1 change: 1 addition & 0 deletions io.sloeber.ui/src/io/sloeber/ui/messages_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ serialMonitorNoMoreSerialPortsSupported=Maximaal aantal seri
serialMonitorRemoveSerialPortFromMonitor=Verwijder een seri�le poort van de monitor
serialMonitorReset=Herstart
serialMonitorScrollLock=Scroll Lock
serialMonitorShowTimestamps=Prefix messages with timestamps
serialMonitorSend=Zend
serial_listener_error=Plotter data fout: Er zijn {NUMBER} kanalen
set_or_remove_password=Account beheer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
Expand Down Expand Up @@ -132,6 +134,7 @@ public synchronized void addData(String event) {
}
}
}

private synchronized void synchronizedrun() {
try {
if (!SerialListener.this.isDisposed) {
Expand All @@ -155,12 +158,14 @@ public void run() {
@Override
public void event(String event) {
this.textUpdater.addData(event);

}

public static void setPlotterFilter(boolean selection) {
myPlotterFilterFlag = selection;
}

public int getColorIndex() {
return theColorIndex;
}

public int getColorIndex() {
Expand Down
87 changes: 84 additions & 3 deletions io.sloeber.ui/src/io/sloeber/ui/monitor/views/SerialMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.File;
import java.net.URL;
import java.nio.charset.Charset;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -83,14 +85,26 @@ public class SerialMonitor extends ViewPart implements ISerialUser {
static private final int MY_MAX_SERIAL_PORTS = 6;
static private final boolean[] serialPortAllocated = new boolean[MY_MAX_SERIAL_PORTS];

// This array is used to allocate the serial port IDs, which determine the color used
// in the text control.
static private final boolean[] serialPortAllocated = new boolean[MY_MAX_SERIAL_PORTS];

// These StringBuilders are used to create discrete lines of text when in timestamp
// mode.
static private final StringBuilder[] lineBuffer = new StringBuilder[MY_MAX_SERIAL_PORTS];

static private final DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); //$NON-NLS-1$

static private final URL IMG_CLEAR;
static private final URL IMG_LOCK;
static private final URL IMG_FILTER;
static private final URL IMG_TIMESTAMP;

static {
IMG_CLEAR = Activator.getDefault().getBundle().getEntry("icons/clear_console.png"); //$NON-NLS-1$
IMG_LOCK = Activator.getDefault().getBundle().getEntry("icons/lock_console.png"); //$NON-NLS-1$
IMG_FILTER = Activator.getDefault().getBundle().getEntry("icons/filter_console.png"); //$NON-NLS-1$
IMG_TIMESTAMP = Activator.getDefault().getBundle().getEntry("icons/timestamp_console.png"); //$NON-NLS-1$
}

// Connect to a serial port
Expand All @@ -104,6 +118,8 @@ public class SerialMonitor extends ViewPart implements ISerialUser {
private Action plotterFilter;
// clear serial monitor
private Action clear;
// Toggle timestamps on serial messages.
private Action showTimestamps;

// The string to send to the serial port
protected Text sendString;
Expand All @@ -124,6 +140,8 @@ public class SerialMonitor extends ViewPart implements ISerialUser {
// link to color registry
private ColorRegistry colorRegistry = null;

private boolean timestampMode = true;

static private Composite parent;

/*
Expand Down Expand Up @@ -169,6 +187,7 @@ public SerialMonitor() {
for (int i = 0; i < MY_MAX_SERIAL_PORTS; i++) {
serialColorID[i] = "io.sloeber.serial.color." + (1 + i); //$NON-NLS-1$
serialPortAllocated[i] = false;
lineBuffer[i] = new StringBuilder();
}
SerialManager.registerSerialUser(this);

Expand Down Expand Up @@ -309,7 +328,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
ITheme currentTheme = themeManager.getCurrentTheme();
FontRegistry fontRegistry = currentTheme.getFontRegistry();
monitorOutput.setFont(fontRegistry.get("io.sloeber.serial.fontDefinition")); //$NON-NLS-1$
monitorOutput.setText(Messages.serialMonitorNoInput);
monitorOutput.setText(Messages.serialMonitorNoInput + System.getProperty("line.separator"));
monitorOutput.addMouseListener(new MouseListener() {

@Override
Expand Down Expand Up @@ -389,6 +408,7 @@ private void fillLocalToolBar(IToolBarManager manager) {
manager.add(clear);
manager.add(scrollLock);
manager.add(plotterFilter);
manager.add(showTimestamps);
manager.add(connect);
manager.add(disconnect);
}
Expand Down Expand Up @@ -458,6 +478,18 @@ public void run() {
plotterFilter.setEnabled(true);
plotterFilter.setChecked(MyPreferences.getLastUsedPlotterFilter());
SerialListener.setPlotterFilter(MyPreferences.getLastUsedPlotterFilter());

showTimestamps = new Action(Messages.serialMonitorShowTimestamps, IAction.AS_CHECK_BOX) {
@Override
public void run() {
timestampMode = isChecked();
MyPreferences.setLastUsedShowTimestamps(isChecked());
}
};
showTimestamps.setImageDescriptor(ImageDescriptor.createFromURL(IMG_TIMESTAMP));
showTimestamps.setEnabled(true);
showTimestamps.setChecked(MyPreferences.getLastUsedShowTimestamps());
timestampMode = MyPreferences.getLastUsedShowTimestamps();
}

/**
Expand All @@ -479,11 +511,46 @@ public void setFocus() {
* this is the index number of the opened port
*/
public void ReportSerialActivity(String stInfo, int style) {
String text = stInfo;

if (timestampMode) {
StringBuilder sb = new StringBuilder();
String ts = LocalTime.now().format(timeFormatter) + ": "; //$NON-NLS-1$

// Normalize the line endings.
text = text.replaceAll("\r", ""); //$NON-NLS-1$ //$NON-NLS-2$
int begin = 0;
while (true) {
int idx = text.indexOf("\n", begin); //$NON-NLS-1$
if (idx >= 0) {
// Note the first time through this loop lineBuffer[style] may contain
// an incomplete line from the previously received chunk of data.
String substring = text.substring(begin, idx + 1);
lineBuffer[style].append(substring);
sb.append(ts);
sb.append(lineBuffer[style]);

lineBuffer[style].setLength(0);
begin = idx + 1;
} else {
// Save any remaining data for the next time through this method.
lineBuffer[style].append(text.substring(begin));
break;
}
}

if (sb.length() < 1) {
return;
}

text = sb.toString();
}

int startPoint = monitorOutput.getCharCount();
monitorOutput.append(stInfo);
monitorOutput.append(text);
StyleRange styleRange = new StyleRange();
styleRange.start = startPoint;
styleRange.length = stInfo.length();
styleRange.length = text.length();
styleRange.fontStyle = SWT.NORMAL;
styleRange.foreground = colorRegistry.get(serialColorID[style]);
monitorOutput.setStyleRange(styleRange);
Expand Down Expand Up @@ -566,10 +633,24 @@ public void connectSerial(String comPort, int baudRate) {
public void disConnectSerialPort(String comPort) {
Serial newSerial = GetSerial(comPort);
if (newSerial != null) {

SerialListener theListener = serialConnections.get(newSerial);
serialPortAllocated[theListener.getColorIndex()] = false;
serialConnections.remove(newSerial);
newSerial.removeListener(theListener);

int idx = theListener.getColorIndex();
serialPortAllocated[idx] = false;
if (lineBuffer[idx].length() > 0) {
// Flush any leftover data.
String str = lineBuffer[idx].toString();
str += System.getProperty("line.separator");
ReportSerialActivity(str, idx);

// Clear the leftover data out.
lineBuffer[idx].setLength(0);
}

newSerial.dispose();
theListener.dispose();
SerialPortsUpdated();
Expand Down