Skip to content

Commit

Permalink
Merge pull request #60 from Pi4J/preparation-HS23
Browse files Browse the repository at this point in the history
Revised component catalogue
  • Loading branch information
FDelporte authored Oct 24, 2023
2 parents 75c1045 + 9d9d25f commit b71a170
Show file tree
Hide file tree
Showing 63 changed files with 2,896 additions and 4,735 deletions.
5 changes: 2 additions & 3 deletions .run/Debug on Pi.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
</option>
<option name="jreName" value="#USE_PROJECT_JDK" />
<option name="mavenProperties">
<map>
<entry key="pi.ipnumber" value="pi4j.local" />
</map>
<map />
</option>
<option name="passParentEnv" value="true" />
<option name="runMavenInBackground" value="true" />
Expand All @@ -34,6 +32,7 @@
<option name="profilesMap">
<map>
<entry key="debug" value="true" />
<entry key="remote-run" value="true" />
</map>
</option>
<option name="resolveToWorkspace" value="false" />
Expand Down
33 changes: 33 additions & 0 deletions .run/Rerun version on Pi.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Rerun version on Pi" type="MavenRunConfiguration" factoryName="Maven">
<MavenSettings>
<option name="myGeneralSettings" />
<option name="myRunnerSettings" />
<option name="myRunnerParameters">
<MavenRunnerParameters>
<option name="profiles">
<set />
</option>
<option name="goals">
<list>
<option value="package" />
<option value="-DskipTests=true" />
<option value="-Dmaven.test.skip" />
<option value="-Dmaven.main.skip=true" />
<option value="--no-snapshot-updates" />
</list>
</option>
<option name="pomFileName" value="pom.xml" />
<option name="profilesMap">
<map>
<entry key="rerun" value="true" />
</map>
</option>
<option name="resolveToWorkspace" value="false" />
<option name="workingDirPath" value="$PROJECT_DIR$" />
</MavenRunnerParameters>
</option>
</MavenSettings>
<method v="2" />
</configuration>
</component>
4 changes: 1 addition & 3 deletions .run/Run on Pi.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
</option>
<option name="jreName" value="#USE_PROJECT_JDK" />
<option name="mavenProperties">
<map>
<entry key="pi.ipnumber" value="pi4j.local" />
</map>
<map />
</option>
<option name="passParentEnv" value="true" />
<option name="runMavenInBackground" value="true" />
Expand Down
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,35 @@ See [Pi4J website](https://pi4j.com/examples/components/).

## Start application on Pi

It's strongly recommended to use the Linux image [Pi4J-Basis-OS](https://github.com/Pi4J/pi4j-os/tree/upgrade-jdk18-jfx18) and [IntelliJ IDEA](https://www.jetbrains.com/idea/) as IDE on your developer machine. But, of course, you can use any other IDE and use maven commands to experiment with our component catalogue.

It's strongly recommended to use the Linux image [Pi4J-Basic-OS](https://pi4j-download.com/latest.php?flavor=basic) and [IntelliJ IDEA](https://www.jetbrains.com/idea/) as IDE on your developer machine. But, of course, you can use any other IDE and use maven commands to experiment with our component catalogue.

In IntelliJ IDEA ready-made run-configurations are available for running the demo application on the RaspPi.

## Start application on Raspberry Pi
- Make sure that Pi and your development machine are in the same WLAN.
- You have to check whether the correct IP-address is set in the run-configuration
- via `Edit Configurations... -> Run on Pi -> Properties -> pi.ipnumber=pi4j.local`
- `Run on Pi` starts the demo application remotely on the Raspberry Pi
- Make sure that Pi and your development machine are in the same WLAN (see recommendations in [Pi4J OS](https://github.com/Pi4J/pi4j-os))
- Check whether the correct IP-address is set in `pom.xml`
- set properties `<pi.hostname>` and `<pi.ipnumber>`
- `Run on Pi` compiles and packages the demo application on your developer machine, deploys it to Raspberry Pi and starts the demo application remotely on the Raspberry Pi

## Restart application on Raspberry Pi
Once you have started the demo application on Raspberry Pi using `Run on Pi`, you can restart it without recompiling
- `Rerun version on Pi` starts the demo application remotely on the Raspberry Pi without applying any changes

## Start application in debugger

To start the application on the Raspberry Pi in debug mode the two run configurations `Debug on Pi` and `Attach to Pi Debugger` are required.
To start the application on the Raspberry Pi in debug mode, two run configurations are required: `Debug on Pi` and `Attach to Pi Debugger`.

The sequence of starting the run configurations is critical:
1. Check whether the correct IP-address is set in the run-configurations (both, `Debug on Pi` and `Attach to Pi Debugger`)
1. Start `Debug on Pi` using the **Run** button
1. Wait till the console contains the following message: `Listening for transport dt_socket at address: 5005 (Attach debugger)`
1. Check whether the correct IP-address (or hostname) is set in `pom.xml`
1. Start `Debug on Pi` using the **Run** button
1. Wait till the following message is displayed in console:
`Listening for transport dt_socket at address: 5005 (Attach debugger)`
1. Start `Attach to Pi Debugger` using the **Debug** button
1. Only now the demo application is started

Now you can use the debugger from IntelliJ IDEA, setting breakpoints and stepping through the application.

The output to console is in `Debug on Pi Tab` the debugger output in `Attach to Pi Debugger Tab`. You have to switch between these tabs.
The output to console is in `Debug on Pi` tab the debugger output in `Attach to Pi Debugger` tab. You have to switch between these tabs.

## LICENSE

Expand Down
64 changes: 53 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
<launcher.args>--demo</launcher.args>

<!-- Raspberry Remote Deployment -->
<pi.ipnumber>pi4j.local</pi.ipnumber>
<pi.hostname>pi4j</pi.hostname>
<pi.ipnumber>${pi.hostname}.local</pi.ipnumber> <!-- change to concrete ip-number if hostname is not unique in wlan -->
<pi.port>22</pi.port>
<pi.username>pi</pi.username>
<pi.password>pi4j</pi.password>
Expand All @@ -40,10 +41,10 @@

<!-- Project Dependencies -->
<java.version>17</java.version>
<pi4j.version>2.3.0-SNAPSHOT</pi4j.version>
<pi4j.version>2.4.0</pi4j.version>
<picocli.version>4.7.4</picocli.version>
<junit.version>5.9.3</junit.version>
<mockito.version>5.3.1</mockito.version>
<junit.version>5.10.0</junit.version>
<mockito.version>5.4.0</mockito.version>
<ant-jsch.version>1.10.9</ant-jsch.version>

<!-- Maven Dependencies -->
Expand Down Expand Up @@ -88,7 +89,6 @@
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-mock</artifactId>
<version>${pi4j.version}</version>
<scope>test</scope>
</dependency>

<!-- Plugin for I2C -->
Expand Down Expand Up @@ -138,7 +138,6 @@
<release>${java.version}</release>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<verbose>false</verbose>
<annotationProcessorPaths>
<path>
<groupId>info.picocli</groupId>
Expand All @@ -150,8 +149,8 @@
<!-- Used by PicoCLI annotation processor -->
<arg>-Aproject=${launcher.class}</arg>
</compilerArgs>
<source>17</source>
<target>17</target>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>

Expand Down Expand Up @@ -232,7 +231,6 @@
<!-- Run the JAR file locally -->
<profile>
<id>local-run</id>

<build>
<plugins>
<plugin>
Expand All @@ -258,7 +256,6 @@
<!-- Transfer and run JAR with dependencies on remote Raspberry -->
<profile>
<id>remote-run</id>

<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -296,7 +293,52 @@
<sshexec host="${pi.ipnumber}" port="${pi.port}"
username="${pi.username}" password="${pi.password}" trust="true"
failonerror="false" usepty="true" useSystemIn="true"
command="sudo java ${pi.jvmOptions} --module-path ${pi.deploydirectory} --module ${launcher.class} ${launcher.args}"/>
command="sudo java -XX:+UseZGC -Xmx1G ${pi.jvmOptions} --module-path ${pi.deploydirectory} --module ${launcher.class} ${launcher.args}"/>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>${ant-jsch.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>

<!-- Rerun the app on remote Raspberry without deploying any changes-->
<profile>
<id>rerun</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>transfer</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- Stop all running Java processes -->
<sshexec host="${pi.ipnumber}" port="${pi.port}"
username="${pi.username}" password="${pi.password}" trust="true"
failonerror="false" usepty="true" useSystemIn="false"
suppresssystemerr="true" suppresssystemout="true"
command="sudo killall -9 java"/>

<!-- Run application on Raspberry Pi -->
<sshexec host="${pi.ipnumber}" port="${pi.port}"
username="${pi.username}" password="${pi.password}" trust="true"
failonerror="false" usepty="true" useSystemIn="true"
command="sudo java -XX:+UseZGC -Xmx1G ${pi.jvmOptions} --module-path ${pi.deploydirectory} --module ${launcher.class} ${launcher.args}"/>
</target>
</configuration>
</execution>
Expand Down
21 changes: 5 additions & 16 deletions src/main/java/com/pi4j/catalog/Application.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.pi4j.catalog;

import com.pi4j.context.Context;
import java.time.Duration;

import java.util.logging.Logger;
import com.pi4j.context.Context;

/**
* This interface should be implemented by each CrowPi example / application
Expand Down Expand Up @@ -40,25 +40,14 @@ default String getDescription() {
* Utility function to sleep for the specified amount of milliseconds.
* An {@link InterruptedException} will be catched and ignored while setting the interrupt flag again.
*
* @param milliseconds Time in milliseconds to sleep
* @param duration Time to sleep
*/
default void delay(long milliseconds) {
default void delay(Duration duration) {
try {
Thread.sleep(milliseconds);
Thread.sleep(duration.toMillis());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}

/**
* Logger instance
*/
Logger logger = Logger.getLogger("Pi4J-App");

default void logInfo(String msg){
logger.info(() -> msg);
}
default void logError(String msg){
logger.severe(() -> msg);
}
}
22 changes: 14 additions & 8 deletions src/main/java/com/pi4j/catalog/Launcher.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package com.pi4j.catalog;

import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Model.CommandSpec;

import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Scanner;

import com.pi4j.Pi4J;
import com.pi4j.context.Context;
import com.pi4j.catalog.applications.*;
import com.pi4j.library.pigpio.PiGpio;
import com.pi4j.plugin.linuxfs.provider.i2c.LinuxFsI2CProvider;
import com.pi4j.plugin.pigpio.provider.gpio.digital.PiGpioDigitalInputProvider;
Expand All @@ -11,18 +19,16 @@
import com.pi4j.plugin.pigpio.provider.serial.PiGpioSerialProvider;
import com.pi4j.plugin.pigpio.provider.spi.PiGpioSpiProvider;
import com.pi4j.plugin.raspberrypi.platform.RaspberryPiPlatform;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Model.CommandSpec;
import java.util.*;

import com.pi4j.catalog.applications.*;

@Command(name = "Raspberry Pi Example Launcher", version = "1.0.0", mixinStandardHelpOptions = true)
public final class Launcher implements Runnable {
/**
* This list must contain all applications which should be executable through the launcher.
* Each class instance must implement the Application interface and gets automatically added as a subcommand.
*/
public static final List<Application> APPLICATIONS = new ArrayList<Application>(Arrays.asList(
public static final List<Application> APPLICATIONS = List.of(
new SimpleButton_App(),
new SimpleLed_App(),
new Ads1115_App(),
Expand All @@ -37,7 +43,7 @@ public final class Launcher implements Runnable {
new Potentiometer_App(),
new SerialGps_App(),
new Servo_App()
));
);

/**
* Demo mode will keep the launcher running forever, allowing the consecutive execution of several applications.
Expand Down Expand Up @@ -123,7 +129,7 @@ protected String[] getProviders() {
}
})
.add(PiGpioDigitalInputProvider.newInstance(piGpio),
PiGpioDigitalOutputProvider.newInstance(piGpio),
PiGpioDigitalOutputProvider.newInstance(piGpio) ,
PiGpioPwmProvider.newInstance(piGpio),
PiGpioSerialProvider.newInstance(piGpio),
PiGpioSpiProvider.newInstance(piGpio),
Expand Down
Loading

0 comments on commit b71a170

Please sign in to comment.