Skip to content

Commit

Permalink
added arduino-file, dynamic UI-Scaling & pom-build
Browse files Browse the repository at this point in the history
  • Loading branch information
Paulsenik committed Feb 20, 2024
1 parent 633b423 commit debff47
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 16 deletions.
54 changes: 54 additions & 0 deletions arduino-pedal/arduino-pedal.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
int leftPin = A0;
int rightPin = A1;
int leftValue = 0;
int rightValue = 0;

const long minPressDelay = 100;

long lastPressedLeft = 0;
long lastPressedRight = 0;

bool leftPressed = false;
bool rightPressed = false;

void setup() {
Serial.begin(9600);
}

void loop() {

leftValue = analogRead(leftPin);
rightValue = analogRead(rightPin);

if(leftValue < 50){
if(lastPressedLeft + minPressDelay < millis()){
if(!leftPressed){
Serial.println("+Left");
leftPressed = true;
}
}
}else{
if(leftPressed){
Serial.println("-Left");
leftPressed = false;
lastPressedLeft = millis();
}
}

if(rightValue < 50){
if(lastPressedRight + minPressDelay < millis()){
if(!rightPressed){
Serial.println("+Right");
rightPressed = true;
}
}
}else{
if(rightPressed){
Serial.println("-Right");
rightPressed = false;
lastPressedRight = millis();
}
}

delay(1);
}
34 changes: 24 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

<groupId>de.paulsenik</groupId>
<artifactId>inputsink</artifactId>
<version>1.0.0</version>
<version>0.1.0</version>
<packaging>jar</packaging>

<name>inputsink</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<repositories>
Expand All @@ -20,26 +22,38 @@
<url>https://jitpack.io</url>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<source>14</source>
<target>14</target>
<appendAssemblyId>false
</appendAssemblyId> <!--only compiles to jar with dependency-->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>de.paulsenik.inputsink.Inputsink</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.paulsenik</groupId>
<artifactId>java-project-library</artifactId>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/paulsenik/inputsink/Inputsink.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

public class Inputsink {

public static final String VERSION = "v0.1.0";

public static void main(String[] args) throws AWTException {
new InputService();
new KeyPressService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void initElements(UI f, Trigger t) {
});

actionList = new PUIList(f, 1);
actionList.setSliderWidth(5);
actionList.setShowedElements(4);
actionList.doPaintOverOnHover(false);
actionList.doPaintOverOnPress(false);
actionList.showSlider(false);
Expand Down Expand Up @@ -100,6 +100,9 @@ private void updateActions() {
public synchronized void setBounds(int x, int y, int w, int h) {
super.setBounds(x, y, w, h);

b = h/5;
p = b/2;

triggerName.setBounds(x + p, y + p, w / 2 - p * 2, b);
deleteInputMapping.setBounds(x + p, y + h - p - b, b, b);
addActionButton.setBounds(x + w / 2 - p - b, y + h - p - b, b, b);
Expand Down
30 changes: 25 additions & 5 deletions src/main/java/de/paulsenik/inputsink/ui/UI.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package de.paulsenik.inputsink.ui;

import de.paulsenik.inputsink.Inputsink;
import de.paulsenik.inputsink.serivces.InputService;
import de.paulsenik.inputsink.serivces.SaveService;
import de.paulsenik.inputsink.serivces.UserPromptService;
import de.paulsenik.inputsink.trigger.Trigger;
import de.paulsenik.jpl.ui.PUIElement;
import de.paulsenik.jpl.ui.PUIList;
import de.paulsenik.jpl.ui.PUIText;
import de.paulsenik.jpl.ui.core.PUICanvas;
import de.paulsenik.jpl.ui.core.PUIFrame;
import de.paulsenik.jpl.ui.core.PUIPaintable;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
Expand All @@ -31,8 +36,9 @@ public class UI extends PUIFrame {
private PUIText addInputButton;
private PUIList inputList;

private int m = 10; // border-margin
private int bSize = 50;
private int m = 20; // border-margin
private int bSize = 90;
int topBar = 110;

public UI() {
super("Inputsink", 1000, 800, false);
Expand Down Expand Up @@ -60,6 +66,12 @@ public UI() {
private void initElements() {
String port = InputService.instance.getSerialPort();

new PUICanvas(this, (g, x, y, w, h) -> {
g.setColor(Color.white);
g.setFont(new Font("Consolas", Font.BOLD, 10));
g.drawString(Inputsink.VERSION, x, h);
});

arduinoButton = new PUIText(this,
ARDUINO_BUTTON_TEXT + ((port == null || !InputService.instance.isSerialConnected()) ? "---"
: port));
Expand Down Expand Up @@ -99,11 +111,19 @@ private void initElements() {
}

public void updateElements(int w, int h) {
arduinoButton.setBounds(m, m, 300, bSize);
bSize = Math.min(h / 14, w / 10);
topBar = m * 2 + bSize;

if (h > w && w != 0) {
inputList.setShowedElements(h / w * 4);
} else {
inputList.setShowedElements(3);
}

arduinoButton.setBounds(m, m, w - bSize - m * 3, bSize);
inputList.setSliderWidth(bSize);
int topBar = m * 2 + bSize;
addInputButton.setBounds(w - m - bSize, m, bSize, bSize);
inputList.setBounds(m, topBar, w - m * 2, h - topBar + m);
inputList.setBounds(m, topBar, w - m * 2, h - topBar - m * 4);
updateInputList();
}

Expand Down

0 comments on commit debff47

Please sign in to comment.