This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from larsgrefer/develop
Develop
- Loading branch information
Showing
19 changed files
with
723 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
sense-hat/src/main/java/de/larsgrefer/sense_hat/BigBinaryClock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package de.larsgrefer.sense_hat; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.awt.*; | ||
import java.awt.image.BufferedImage; | ||
import java.time.LocalTime; | ||
|
||
/** | ||
* @author Lars Grefer | ||
*/ | ||
@Getter | ||
@Setter | ||
public class BigBinaryClock extends Clock { | ||
|
||
private Color hours = Color.RED; | ||
private Color minutes = Color.BLUE; | ||
|
||
public BigBinaryClock(SenseHat senseHat) { | ||
super(senseHat); | ||
} | ||
|
||
protected void drawTime(BufferedImage bufferedImage, LocalTime now) { | ||
drawNumber(bufferedImage, 0, now.getHour() / 10, hours); | ||
drawNumber(bufferedImage, 1, now.getHour() % 10, hours); | ||
|
||
drawNumber(bufferedImage, 2, now.getMinute() / 10, minutes); | ||
drawNumber(bufferedImage, 3, now.getMinute() % 10, minutes); | ||
} | ||
|
||
private void drawNumber(BufferedImage image, int column, int number, Color color) { | ||
for (int row = 3, bit = 0; bit <= 3; row--, bit++) { | ||
if (((number >>> bit) & 1) == 1) { | ||
setBigPixel(image, column, row, color); | ||
} else { | ||
setBigPixel(image, column, row, getBackground()); | ||
} | ||
} | ||
} | ||
|
||
private void setBigPixel(BufferedImage bufferedImage, int x, int y, Color color) { | ||
bufferedImage.setRGB(x * 2, y * 2, color.getRGB()); | ||
bufferedImage.setRGB(x * 2, y * 2 + 1, color.getRGB()); | ||
bufferedImage.setRGB(x * 2 + 1, y * 2, color.getRGB()); | ||
bufferedImage.setRGB(x * 2 + 1, y * 2 + 1, color.getRGB()); | ||
} | ||
|
||
|
||
} |
55 changes: 55 additions & 0 deletions
55
sense-hat/src/main/java/de/larsgrefer/sense_hat/Clock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package de.larsgrefer.sense_hat; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.awt.*; | ||
import java.awt.image.BufferedImage; | ||
import java.io.IOException; | ||
import java.time.Duration; | ||
import java.time.LocalTime; | ||
|
||
/** | ||
* Created by larsgrefer on 06.06.17. | ||
*/ | ||
@RequiredArgsConstructor | ||
@Getter | ||
@Setter | ||
@Slf4j | ||
public abstract class Clock implements Runnable { | ||
|
||
private final SenseHat senseHat; | ||
|
||
private java.time.Clock clock = java.time.Clock.systemDefaultZone(); | ||
|
||
private boolean stop = false; | ||
|
||
private Color background = Color.BLACK; | ||
|
||
@Override | ||
public void run() { | ||
BufferedImage bufferedImage = new BufferedImage(8,8,BufferedImage.TYPE_USHORT_565_RGB); | ||
|
||
while (!stop) { | ||
|
||
LocalTime now = LocalTime.now(clock); | ||
|
||
drawTime(bufferedImage, now); | ||
|
||
try { | ||
senseHat.fadeTo(bufferedImage, Duration.ofMillis(500)); | ||
} catch (IOException e) { | ||
log.error(e.getLocalizedMessage(), e); | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
|
||
public void setBackground(SenseHatColor background) { | ||
this.background = background.toColor(); | ||
} | ||
|
||
protected abstract void drawTime(BufferedImage bufferedImage, LocalTime now); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.