Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revised component catalogue #60

Merged
merged 40 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
503cbf7
ipnumber of pi is set in pom.xml now
DieterHolz Jun 21, 2023
a8cbed6
try to fix some testcases
DieterHolz Jun 21, 2023
ab00bfb
added back-links to Pi4J website in example apps
DieterHolz Jun 21, 2023
ed13f8d
removed ContinuousMeasuringException, replaced by IllegalStateException
DieterHolz Jun 22, 2023
ba58f72
moved Component to new package 'base'
DieterHolz Jun 22, 2023
eabd0b2
major refactoring of SimpleButton
DieterHolz Jun 22, 2023
e28e6a4
introduced DigitalActuator
DieterHolz Jun 23, 2023
8a78733
introduced PwmActuator
DieterHolz Jun 23, 2023
d74f19a
refactoring for testing
DieterHolz Jun 24, 2023
bd0586d
minor fix in ServoMotor
DieterHolz Jun 24, 2023
a0837c6
wip
DieterHolz Jun 28, 2023
0e839b9
wip
DieterHolz Jun 28, 2023
b72b952
wip
DieterHolz Jun 28, 2023
8a903ab
wip
DieterHolz Jun 28, 2023
5406407
wip
DieterHolz Jun 29, 2023
3d99830
wip
DieterHolz Jun 29, 2023
b48df06
wip
DieterHolz Jul 7, 2023
d06eab5
major refactorin of JoystickAnalog
DieterHolz Jul 7, 2023
54c131c
delay works with duration instead of long now
DieterHolz Jul 8, 2023
d267f09
Buzzer refactored
DieterHolz Jul 10, 2023
75d7d32
wip LCD
DieterHolz Jul 10, 2023
7d5ccfd
LCD refactoring finished (TestCases are still missing)
DieterHolz Jul 11, 2023
905a79b
Servo revisited
DieterHolz Jul 11, 2023
073e5ab
LedStrip wip
DieterHolz Jul 12, 2023
82d3834
SerialGps refactoring
DieterHolz Jul 13, 2023
eff4503
wip
DieterHolz Jul 13, 2023
6fc3a11
wip
DieterHolz Jul 17, 2023
f026afb
wip
DieterHolz Jul 17, 2023
82fe92e
ready for review
DieterHolz Jul 18, 2023
e9d3941
minor changes in Readme, optimize imports
DieterHolz Jul 18, 2023
1853608
"frequency" for LED strip must be different on Pi3 and Pi4. Aaargh.
DieterHolz Jul 18, 2023
5402c38
changed Pins in LedButton- LedStrip- and Buzzer-App
DieterHolz Jul 19, 2023
05f059a
cleanup logging in 'Camera'
DieterHolz Jul 24, 2023
593af02
upgrade JUnit to 5.10.0
DieterHolz Jul 24, 2023
cd8838f
'isOn()' added to 'SimpleLed'
DieterHolz Jul 24, 2023
1de5964
corrected link to Pi4J-Basic-OS in README
DieterHolz Jul 26, 2023
dd02346
Merge remote-tracking branch 'origin/main' into preparation-HS23
DieterHolz Oct 23, 2023
39d52b1
TestCase fixed
DieterHolz Oct 23, 2023
3d74eb7
optimize imports
DieterHolz Oct 24, 2023
9d9d25f
Bump to Pi4J V2.4.0
FDelporte Oct 24, 2023
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
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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a "beauty remark". When using auto save in IntelliJ IDEA with cleanup, imports should get sorted alphabetically. It's not critical at all, but will avoid code changes between commits, where imports only move place.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do a 'optimize imports'


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
Loading