Repository navigation
Expand file tree
/
Copy pathBrickman.java
More file actions
53 lines (42 loc) · 1.47 KB
/
Copy pathBrickman.java
File metadata and controls
53 lines (42 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package ev3dev.utils;
import lombok.extern.slf4j.Slf4j;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.IOException;
@Slf4j
public class Brickman {
private static final String DISABLE_BRICKMAN_COMMAND = "sudo systemctl stop brickman";
private static final String ENABLE_BRICKMAN_COMMAND = "sudo systemctl start brickman";
/**
* Disable Brickman.
*/
public static void disable() {
LOGGER.trace("Disabling Brickman service");
Shell.execute(DISABLE_BRICKMAN_COMMAND);
Runtime.getRuntime().addShutdownHook(new Thread(Brickman::restoreBrickman, "restore brickman"));
}
/**
* Enable Brickman.
*/
private static void restoreBrickman() {
LOGGER.trace("Enabling Brickman service");
Shell.execute(ENABLE_BRICKMAN_COMMAND);
}
/**
* Draw Duke.
* @param gfx Required context to draw an image.
*/
public static void drawJavaLogo(Graphics2D gfx) {
LOGGER.debug("Showing Java logo on EV3 Brick");
try {
Rectangle bounds = gfx.getClipBounds();
final BufferedImage image = JarResource.loadImage(JarResource.JAVA_DUKE_IMAGE_NAME);
int x = (bounds.width - image.getWidth()) / 2;
int y = (bounds.height - image.getHeight()) / 2;
gfx.drawImage(image, x, y, null);
} catch (IOException e) {
LOGGER.error(e.getLocalizedMessage());
}
}
}