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

Wallpaper script + instructions #48

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/.idea/
/wallpaper/wallpaper-out.png
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ This project provides some scripts to extend the official Raspberry Pi Operating

## How To Use

### Script to Setup for Java

1. Prepare an SD Card with the 64-bit version of the Raspberry Pi Operating System, see [the Pi4J website > Prepare a Raspberry Pi > Write OS to SD card](https://www.pi4j.com/prepare/sd-card/).
2. Put the SD Card in your Raspberry Pi and start it.
3. The board will probably reboot to do some basic settings.
Expand All @@ -18,6 +20,30 @@ This project provides some scripts to extend the official Raspberry Pi Operating
6. Make sure you see `All done! Have fun...` if the script finished. If not, you may need to run it again as one of the intermediate steps has stopped it.
7. You're done! Check [the Pi4J website > Getting Started With Pi4J](https://www.pi4j.com/getting-started/) for the next steps. Have fun with #JavaOnRaspberryPi.

### Wallpaper

An additional Java (JBang) script is available to turn the desktop wallpaper into an information screen. This script will take an image as input, overlay some useful info as text (IP, Java version, etc.), and save this as a new image. This generated image is then pushed as the new wallpaper to the desktop.

```shell
mkdir wallpaper
cd wallpaper
wget https://raw.githubusercontent.com/Pi4J/pi4j-os/main/wallpaper/GenerateWallpaperInfoImage.java
# Add an image, or download one of the examples
wget https://raw.githubusercontent.com/Pi4J/pi4j-os/main/wallpaper/wallpaper-1-1920x1080.png
# Run the command to test it
jbang GenerateWallpaperInfoImage.java wallpaper-1-1920x1080.png wallpaper-out.png 1280 800
```

This will generate a result like this:

![Screenshot of a generated wallpaper](screenshot/generated-wallpaper.png)

If you want to run this script automatically, you can use a watch in the terminal. The following example will refresh the background every 10 seconds:

```shell
watch -n 10 jbang GenerateWallpaperInfoImage.java wallpaper-1-1920x1080.png wallpaper-out.png 1280 800
```

## History Of This Repository

The original goal of this repository was to provide a build of the official Raspberry Pi OS with additional tools to prepare it for Java(FX) and Pi4J projects. Because it became difficult to support because of changes in the OS for the Raspberry Pi 5, we decided to stop this goal, and provide some scripts here that can help you to achieve the same result. You can still find the latest sources of the Pi4J OS here with the tag [end-of-os](https://github.com/Pi4J/pi4j-os/releases/tag/end-of-os).
Expand Down
Binary file added screenshot/generated-wallpaper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 49 additions & 30 deletions wallpaper/GenerateWallpaperInfoImage.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import javax.imageio.ImageIO;
///usr/bin/env jbang "$0" "$@" ; exit $?

//DEPS com.pi4j:pi4j-core:2.7.0

import com.pi4j.Pi4J;
import com.sun.management.OperatingSystemMXBean;
import java.lang.management.ManagementFactory;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
Expand All @@ -8,31 +14,46 @@
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import java.util.Enumeration;
import java.util.List;
import javax.imageio.ImageIO;

/**
* Code to create a wallpaper image with system information.
*
* The input and output image must be provided as args.
* As no dependencies are used, this can be executed with java instead of jbang:
* java <input-image-path> <output-image-path>
* The input image, output image, and width and height for the output image must be provided as args.
* The Pi4J dependency is used to detect the type of Raspberry Pi board.
* You can execute this script with JBang:
* java <input-image-path> <output-image-path> <output-image-width> <output-image-height>
*
* Example usages:
* java GenerateWallpaperInfoImage.java data/wallpaper-2-1920x1080.jpg wallpaper.png
* Example usage to generate a wallpaper for a 1280x800 screen:
* cd wallpaper
* jbang GenerateWallpaperInfoImage.java wallpaper-2-1920x1080.png wallpaper-out.png 1280 800
*/
public class GenerateWallpaperInfoImage {

public static void main(String[] args) {
if (args.length != 2) {
System.out.println("Usage: java <input-image-path> <output-image-path>");
if (args.length != 4) {
System.out.println("Usage: java <input-image-path> <output-image-path> <width> <height>");
return;
}

var outputFile = generateSystemInfoImage(args[0], args[1]);
var width = 0;
var height = 0;

try {
width = Integer.parseInt(args[2]);
height = Integer.parseInt(args[3]);
} catch (Exception e) {
System.err.println("Could not parse the width and/or height");
}

var outputFile = generateSystemInfoImage(args[0], args[1], width, height);

if (outputFile == null) {
System.err.println("No output image could be created...");
Expand All @@ -49,21 +70,17 @@ public static void main(String[] args) {
}
}

public static File generateSystemInfoImage(String inputImagePath, String outputImagePath) {
public static File generateSystemInfoImage(String inputImagePath, String outputImagePath, int width, int height) {
try {
// Read the input image
BufferedImage originalImage = ImageIO.read(new File(inputImagePath));

// Create a copy of the image
BufferedImage newImage = new BufferedImage(
originalImage.getWidth(),
originalImage.getHeight(),
BufferedImage.TYPE_INT_ARGB
);
BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

// Draw the original image
Graphics2D g2d = newImage.createGraphics();
g2d.drawImage(originalImage, 0, 0, null);
g2d.drawImage(originalImage, 0, 0, width, height, null);

// Configure text rendering
g2d.setRenderingHint(
Expand Down Expand Up @@ -110,20 +127,21 @@ private static List<String> getSystemInfo() {
// OS Information
info.add("Operating System");
info.add(" Name: " + System.getProperty("os.name"));
info.add(" Version: " + System.getProperty("os.version"));
info.add(" Arch: " + System.getProperty("os.arch"));
if (System.getProperty("os.name").toLowerCase().contains("linux")) {
info.add(" Kernel: " + execute(Arrays.asList("uname", "-r")));
}

// Java Version
info.add("Java");
info.add(" Java Version: " + System.getProperty("java.runtime.version") + ", " + System.getProperty("java.vendor"));
info.add(" JavaFX Version: " + System.getProperty("javafx.runtime.version"));
info.add(" Version: " + System.getProperty("java.version"));
info.add(" Runtime: " + System.getProperty("java.runtime.version"));
info.add(" Vendor: " + System.getProperty("java.vendor"));

// Java Version
// Raspberry Pi info
var pi4j = Pi4J.newAutoContext();
info.add("Raspberry Pi");
info.add(" Board model: " + execute(Arrays.asList("cat", "/proc/cpuinfo", "|", "grep", "'Revision'", "|", "awk", "'{print $3}'")));
info.add(" Board model: " + pi4j.boardInfo().getBoardModel().getLabel());

// IP Addresses
info.add("Network");
Expand All @@ -145,15 +163,16 @@ private static List<String> getSystemInfo() {
info.add("Error retrieving network interfaces: " + e.getMessage());
}

// System resources
Runtime runtime = Runtime.getRuntime();
long maxMemory = runtime.maxMemory() / (1024 * 1024);
long totalMemory = runtime.totalMemory() / (1024 * 1024);
long freeMemory = runtime.freeMemory() / (1024 * 1024);
info.add("Memory");
info.add(" Max: " + maxMemory + "MB");
info.add(" Total: " + totalMemory + "MB");
info.add(" Free: " + freeMemory + "MB");
// Overall system memory using OperatingSystemMXBean
OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
long totalPhysicalMemorySize = osBean.getTotalPhysicalMemorySize() / (1024 * 1024);
long freePhysicalMemorySize = osBean.getFreePhysicalMemorySize() / (1024 * 1024);
info.add("System Memory");
info.add(" Total: " + totalPhysicalMemorySize + "MB");
info.add(" Free: " + freePhysicalMemorySize + "MB");

// Timestap
info.add("Generated on " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));

return info;
}
Expand Down
Binary file removed wallpaper/wallpaper-2-1920x1080.jpg
Binary file not shown.
Binary file added wallpaper/wallpaper-2-1920x1080.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.