or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

advanced-features.mdbluetooth-communication.mdcore-protocol.mdgui-components.mdindex.mdmessage-handling.mdserial-communication.md

gui-components.mddocs/

0

# GUI Components

1

2

Swing-based graphical components for interactive Arduino control with visual pin layouts, control panels, and real-time monitoring capabilities. The GUI module provides complete desktop applications for Arduino interaction with visual representation of different Arduino board types.

3

4

## Capabilities

5

6

### Advanced GUI Controller

7

8

Main controller class providing high-level Arduino commands through a simplified interface, designed for GUI integration.

9

10

```java { .api }

11

class InteractiveJArduinoDataControllerClientAdvanced implements JArduinoObserver, JArduinoClientSubject {

12

// Arduino command methods (simplified interface)

13

void sendpinMode(PinMode mode, DigitalPin pin);

14

void senddigitalRead(DigitalPin pin);

15

void senddigitalWrite(DigitalPin pin, DigitalState value);

16

void sendanalogReference(AnalogReference type);

17

void sendanalogRead(AnalogPin pin);

18

void sendanalogWrite(PWMPin pin, byte value);

19

void sendtone(DigitalPin pin, int freq, int dur);

20

void sendnoTone(DigitalPin pin);

21

void sendping();

22

void sendattachInterrupt(InterruptPin interrupt, InterruptTrigger mode);

23

void senddetachInterrupt(InterruptPin interrupt);

24

void sendeeprom_read(Short address);

25

void sendeeprom_sync_write(Short address, Byte value);

26

void sendeeprom_write(Short address, Byte value);

27

28

// Observer pattern methods

29

void receiveMsg(byte[] msg);

30

void register(JArduinoClientObserver observer);

31

void unregister(JArduinoClientObserver observer);

32

void unregisterAll();

33

}

34

```

35

36

### Advanced GUI Client

37

38

Main GUI application class providing interactive Arduino control with logging, command history, and visual feedback.

39

40

```java { .api }

41

class InteractiveJArduinoDataGUIClientAdvanced {

42

InteractiveJArduinoDataGUIClientAdvanced(InteractiveJArduinoDataControllerClientAdvanced controller, String card);

43

44

void writeToLog(String string);

45

void enable();

46

void disable();

47

void addToRepeat(APanel panel, String input, short i, short j, byte k);

48

}

49

```

50

51

### Arduino Board Visual Panels

52

53

Visual representations of different Arduino board types with interactive pin controls.

54

55

```java { .api }

56

class MainPanelUno extends JComponent;

57

class MainPanelDiecimila extends JComponent;

58

class MainPanelDuemilanove extends JComponent;

59

class MainPanelLilypad extends JComponent;

60

```

61

62

### Control Panel Components

63

64

Specialized panel classes for different types of Arduino pin controls and functionality.

65

66

```java { .api }

67

abstract class APanel extends JPanel;

68

class DigitalPanel extends APanel;

69

class AnalogPanel extends DigitalPanel;

70

class PWMPanel extends DigitalPanel;

71

class InterruptPanel1 extends DigitalPanel;

72

class InterruptPanel2 extends PWMPanel;

73

class AREFPanel extends APanel;

74

class EEPROMPanel extends JPanel;

75

class LogPanel extends JPanel;

76

class ReuseLogPanel extends JPanel;

77

class CommandExecuter extends Thread;

78

```

79

80

### Dialog Components

81

82

Interactive dialog boxes for configuration and input.

83

84

```java { .api }

85

class CardChooserDialog extends JFrame;

86

class AnalogWriteDialog extends JFrame;

87

class ToneDialog extends JFrame;

88

class DelayDialog extends JFrame;

89

class LogicalTestDialog extends JFrame;

90

```

91

92

### Code Generation

93

94

Components for generating Java code from GUI interactions.

95

96

```java { .api }

97

class CodeGenerator;

98

class GennerationHandler;

99

```

100

101

### Utility GUI Components

102

103

Additional GUI utilities for enhanced user experience.

104

105

```java { .api }

106

class ColorLegend extends JFrame;

107

class HintTextField extends JTextField implements FocusListener;

108

class LogObject;

109

```

110

111

## Usage Examples

112

113

### Basic GUI Application Setup

114

115

```java

116

import org.sintef.jarduino.gui.*;

117

import org.sintef.jarduino.serial.Serial4JArduino;

118

import javax.swing.*;

119

120

public class ArduinoGUIExample {

121

public static void main(String[] args) {

122

SwingUtilities.invokeLater(() -> {

123

// Create controller

124

InteractiveJArduinoDataControllerClientAdvanced controller =

125

new InteractiveJArduinoDataControllerClientAdvanced();

126

127

// Setup serial communication

128

Serial4JArduino arduino = new Serial4JArduino("COM3");

129

arduino.register(controller);

130

controller.register(arduino);

131

132

// Create and show GUI

133

InteractiveJArduinoDataGUIClientAdvanced gui =

134

new InteractiveJArduinoDataGUIClientAdvanced(controller, "Uno");

135

136

// Enable GUI after connection

137

gui.enable();

138

});

139

}

140

}

141

```

142

143

### Arduino Board Selection Dialog

144

145

```java

146

import org.sintef.jarduino.gui.dialogs.CardChooserDialog;

147

148

public class BoardSelectionExample {

149

public void showBoardSelector() {

150

CardChooserDialog dialog = new CardChooserDialog();

151

dialog.setVisible(true);

152

153

// User selects board type, then create appropriate GUI

154

String selectedBoard = dialog.getSelectedBoard(); // "Uno", "Diecimila", etc.

155

156

InteractiveJArduinoDataGUIClientAdvanced gui =

157

new InteractiveJArduinoDataGUIClientAdvanced(controller, selectedBoard);

158

}

159

}

160

```

161

162

### Custom Arduino Control Panel

163

164

```java

165

import org.sintef.jarduino.gui.panels.*;

166

import javax.swing.*;

167

168

public class CustomControlPanel extends JFrame {

169

private InteractiveJArduinoDataControllerClientAdvanced controller;

170

171

public CustomControlPanel(InteractiveJArduinoDataControllerClientAdvanced controller) {

172

this.controller = controller;

173

setupGUI();

174

}

175

176

private void setupGUI() {

177

setLayout(new GridLayout(2, 3));

178

179

// Add different types of control panels

180

add(new DigitalPanel(controller, DigitalPin.PIN_13)); // LED control

181

add(new AnalogPanel(controller, AnalogPin.A_0)); // Sensor reading

182

add(new PWMPanel(controller, PWMPin.PWM_PIN_9)); // PWM output

183

add(new InterruptPanel1(controller, InterruptPin.PIN_2_INT0)); // Interrupt

184

add(new AREFPanel(controller)); // Analog reference

185

add(new EEPROMPanel(controller)); // EEPROM control

186

187

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

188

pack();

189

setVisible(true);

190

}

191

}

192

```

193

194

### Real-time Arduino Monitoring

195

196

```java

197

import org.sintef.jarduino.gui.panels.LogPanel;

198

import org.sintef.jarduino.observer.JArduinoClientObserver;

199

200

public class ArduinoMonitor implements JArduinoClientObserver {

201

private LogPanel logPanel;

202

private InteractiveJArduinoDataGUIClientAdvanced gui;

203

204

public ArduinoMonitor(InteractiveJArduinoDataGUIClientAdvanced gui) {

205

this.gui = gui;

206

this.logPanel = new LogPanel();

207

}

208

209

@Override

210

public void receiveMsg(byte[] msg) {

211

FixedSizePacket packet = JArduinoProtocol.createMessageFromPacket(msg);

212

String message = "Received: " + packet.toString();

213

214

// Log to GUI

215

gui.writeToLog(message);

216

217

// Handle specific responses

218

if (packet instanceof AnalogReadResultMsg) {

219

AnalogReadResultMsg result = (AnalogReadResultMsg) packet;

220

gui.writeToLog("Sensor Value: " + result.getValue());

221

} else if (packet instanceof DigitalReadResultMsg) {

222

DigitalReadResultMsg result = (DigitalReadResultMsg) packet;

223

gui.writeToLog("Digital State: " + result.getValue());

224

}

225

}

226

}

227

```

228

229

### Interactive Dialogs

230

231

```java

232

import org.sintef.jarduino.gui.dialogs.*;

233

234

public class InteractiveDialogs {

235

public void showToneDialog() {

236

ToneDialog dialog = new ToneDialog();

237

dialog.setVisible(true);

238

239

if (dialog.isConfirmed()) {

240

int frequency = dialog.getFrequency();

241

int duration = dialog.getDuration();

242

DigitalPin pin = dialog.getSelectedPin();

243

244

controller.sendtone(pin, frequency, duration);

245

}

246

}

247

248

public void showAnalogWriteDialog() {

249

AnalogWriteDialog dialog = new AnalogWriteDialog();

250

dialog.setVisible(true);

251

252

if (dialog.isConfirmed()) {

253

PWMPin pin = dialog.getSelectedPin();

254

byte value = dialog.getPWMValue(); // 0-255

255

256

controller.sendanalogWrite(pin, value);

257

}

258

}

259

260

public void showDelayDialog() {

261

DelayDialog dialog = new DelayDialog();

262

dialog.setVisible(true);

263

264

if (dialog.isConfirmed()) {

265

int delayMs = dialog.getDelayValue();

266

// Apply delay to command execution

267

}

268

}

269

}

270

```

271

272

### Code Generation from GUI Actions

273

274

```java

275

import org.sintef.jarduino.gui.generators.*;

276

277

public class CodeGenerationExample {

278

private CodeGenerator generator;

279

private GennerationHandler handler;

280

281

public void generateJavaCode() {

282

generator = new CodeGenerator();

283

handler = new GennerationHandler();

284

285

// Record GUI actions

286

generator.recordAction("pinMode", DigitalPin.PIN_13, PinMode.OUTPUT);

287

generator.recordAction("digitalWrite", DigitalPin.PIN_13, DigitalState.HIGH);

288

generator.recordAction("analogRead", AnalogPin.A_0);

289

290

// Generate Java code

291

String generatedCode = generator.generateJavaCode();

292

System.out.println("Generated Code:");

293

System.out.println(generatedCode);

294

295

// Save to file

296

handler.saveCodeToFile(generatedCode, "GeneratedArduinoCode.java");

297

}

298

}

299

```

300

301

## GUI Features

302

303

### Visual Arduino Boards

304

305

The GUI provides visual representations of popular Arduino boards:

306

307

- **Arduino Uno**: Standard USB Arduino with 14 digital pins, 6 analog pins

308

- **Arduino Diecimila**: Classic Arduino with USB connection

309

- **Arduino Duemilanove**: Arduino with improved power management

310

- **Arduino LilyPad**: Wearable Arduino with circular design

311

312

Each board panel shows:

313

- Pin layout matching physical Arduino

314

- Color-coded pins (digital, analog, PWM, power)

315

- Interactive click controls for each pin

316

- Real-time state indicators

317

318

### Control Panels

319

320

Specialized control panels for different Arduino functions:

321

322

- **Digital Panels**: Control digital pins (INPUT/OUTPUT, HIGH/LOW)

323

- **Analog Panels**: Read analog sensors and control analog reference

324

- **PWM Panels**: Control PWM output with sliders (0-255 values)

325

- **Interrupt Panels**: Configure external interrupts with trigger modes

326

- **EEPROM Panel**: Read/write EEPROM memory addresses

327

328

### Logging and Monitoring

329

330

- **Real-time command logging**: All sent/received messages displayed

331

- **Command history**: Previous commands available for repeat

332

- **Error reporting**: Clear indication of communication issues

333

- **Response monitoring**: Arduino responses automatically parsed and displayed

334

335

### Command Building

336

337

- **Visual command construction**: Click pins to build commands

338

- **Parameter dialogs**: Input-specific dialogs for complex commands (tone frequency, PWM values)

339

- **Command validation**: GUI prevents invalid operations

340

- **Batch execution**: Queue multiple commands for execution

341

342

## Dependencies

343

344

- **JArduino Core**: `org.sintef.jarduino.core` for protocol and message classes

345

- **JArduino Serial**: `org.sintef.jarduino.serial` for serial communication

346

- **Swing**: `javax.swing.*` for GUI components

347

- **AWT**: `java.awt.*` for graphics and event handling

348

- **RXTX Library**: `org.kevoree.extra.osgi.rxtx` for serial port support