Sudah bisa DigitalOutput, DigitalInput. Juga sudah menambahkan class NanoPi.
This commit is contained in:
4
.idea/artifacts/JavaInRaspi_jar.xml
generated
4
.idea/artifacts/JavaInRaspi_jar.xml
generated
@@ -1,8 +1,10 @@
|
|||||||
<component name="ArtifactManager">
|
<component name="ArtifactManager">
|
||||||
<artifact type="jar" build-on-make="true" name="JavaInRaspi:jar">
|
<artifact type="jar" name="JavaInRaspi:jar">
|
||||||
<output-path>$PROJECT_DIR$/out/artifacts/JavaInRaspi_jar</output-path>
|
<output-path>$PROJECT_DIR$/out/artifacts/JavaInRaspi_jar</output-path>
|
||||||
<root id="archive" name="JavaInRaspi.jar">
|
<root id="archive" name="JavaInRaspi.jar">
|
||||||
<element id="module-output" name="JavaInRaspi" />
|
<element id="module-output" name="JavaInRaspi" />
|
||||||
|
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/net/java/dev/jna/jna/5.15.0/jna-5.15.0.jar" path-in-jar="/" />
|
||||||
|
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/tinylog/tinylog/1.3.6/tinylog-1.3.6.jar" path-in-jar="/" />
|
||||||
</root>
|
</root>
|
||||||
</artifact>
|
</artifact>
|
||||||
</component>
|
</component>
|
||||||
10
.idea/libraries/net_java_dev_jna.xml
generated
Normal file
10
.idea/libraries/net_java_dev_jna.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="net.java.dev.jna" type="repository">
|
||||||
|
<properties maven-id="net.java.dev.jna:jna:5.15.0" />
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/net/java/dev/jna/jna/5.15.0/jna-5.15.0.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</component>
|
||||||
10
.idea/libraries/sun_jna.xml
generated
Normal file
10
.idea/libraries/sun_jna.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="sun.jna" type="repository">
|
||||||
|
<properties maven-id="com.sun.jna:jna:3.0.9" />
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/com/sun/jna/jna/3.0.9/jna-3.0.9.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</component>
|
||||||
10
.idea/libraries/tinylog.xml
generated
Normal file
10
.idea/libraries/tinylog.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="tinylog" type="repository">
|
||||||
|
<properties maven-id="org.tinylog:tinylog:1.3.6" />
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/tinylog/tinylog/1.3.6/tinylog-1.3.6.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</component>
|
||||||
@@ -3,9 +3,12 @@
|
|||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="jdk" jdkName="liberica-21" jdkType="JavaSDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="tinylog" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="net.java.dev.jna" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
3
lib/META-INF/MANIFEST.MF
Normal file
3
lib/META-INF/MANIFEST.MF
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Main-Class: Main
|
||||||
|
|
||||||
BIN
lib/linux-aarch64/libbass.so
Normal file
BIN
lib/linux-aarch64/libbass.so
Normal file
Binary file not shown.
BIN
lib/linux-arm/libbass.so
Normal file
BIN
lib/linux-arm/libbass.so
Normal file
Binary file not shown.
BIN
lib/linux-armhf/libbass.so
Normal file
BIN
lib/linux-armhf/libbass.so
Normal file
Binary file not shown.
BIN
lib/linux-x86-64/libbass.so
Normal file
BIN
lib/linux-x86-64/libbass.so
Normal file
Binary file not shown.
BIN
lib/linux-x86/libbass.so
Normal file
BIN
lib/linux-x86/libbass.so
Normal file
Binary file not shown.
BIN
lib/win32-arm64/bass.dll
Normal file
BIN
lib/win32-arm64/bass.dll
Normal file
Binary file not shown.
BIN
lib/win32-x86-64/bass.dll
Normal file
BIN
lib/win32-x86-64/bass.dll
Normal file
Binary file not shown.
BIN
lib/win32-x86/bass.dll
Normal file
BIN
lib/win32-x86/bass.dll
Normal file
Binary file not shown.
@@ -10,5 +10,4 @@ public class AudioFileProperties {
|
|||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package Audio;
|
package Audio;
|
||||||
|
import org.pmw.tinylog.Logger;
|
||||||
import org.tinylog.Logger;
|
|
||||||
|
|
||||||
public class AudioPlayer {
|
public class AudioPlayer {
|
||||||
Bass bass;
|
Bass bass;
|
||||||
int deviceid = -1;
|
int deviceid = -1;
|
||||||
|
|
||||||
|
public boolean isInited() {
|
||||||
|
return inited;
|
||||||
|
}
|
||||||
|
|
||||||
boolean inited = false;
|
boolean inited = false;
|
||||||
|
|
||||||
public AudioPlayer(){
|
public AudioPlayer(){
|
||||||
@@ -42,6 +46,26 @@ public class AudioPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int FindOutputDevice(String devName){
|
||||||
|
Logger.info("Detecting Output Devices...");
|
||||||
|
int DevNum = -1;
|
||||||
|
int ii = 1;
|
||||||
|
while (true){
|
||||||
|
Bass.BASS_DEVICEINFO info = new Bass.BASS_DEVICEINFO();
|
||||||
|
if (bass.BASS_GetDeviceInfo(ii, info)){
|
||||||
|
// Logger.info("Device {} = {}, flags = {}", ii, info.name, Integer.toHexString(info.flags));
|
||||||
|
if (info.name.contains(devName)){
|
||||||
|
DevNum = ii;
|
||||||
|
Logger.info(devName+ " is found at " + ii);
|
||||||
|
break;
|
||||||
|
}else {ii++;}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DevNum;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open Output Device
|
* Open Output Device
|
||||||
* @param device device id, starts from 1
|
* @param device device id, starts from 1
|
||||||
|
|||||||
23
src/Audio/AudioRecorder.java
Normal file
23
src/Audio/AudioRecorder.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package Audio;
|
||||||
|
|
||||||
|
public class AudioRecorder {
|
||||||
|
public void startRecording(String filename, int duration, PlaybackEvent event){
|
||||||
|
System.out.println("Recording started");
|
||||||
|
AudioFileProperties prop = new AudioFileProperties(1, filename);
|
||||||
|
event.onPlaybackStart(prop);
|
||||||
|
System.out.println("Recording finished");
|
||||||
|
event.onPlaybackFinished(prop);
|
||||||
|
}
|
||||||
|
public void stopRecording(){
|
||||||
|
System.out.println("Recording stopped");
|
||||||
|
}
|
||||||
|
public void pauseRecording(){
|
||||||
|
System.out.println("Recording paused");
|
||||||
|
}
|
||||||
|
public void resumeRecording(){
|
||||||
|
System.out.println("Recording resumed");
|
||||||
|
}
|
||||||
|
public void loopRecording(){
|
||||||
|
System.out.println("Recording looped");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -80,7 +80,7 @@ public class GeneralCode {
|
|||||||
|
|
||||||
// Helper method to write to a file
|
// Helper method to write to a file
|
||||||
private static boolean writeToFile(String filePath, String value) {
|
private static boolean writeToFile(String filePath, String value) {
|
||||||
System.out.println("writing value : "+filePath+" " + value);
|
// System.out.println("writing value : "+filePath+" " + value);
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))) {
|
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))) {
|
||||||
writer.write(value);
|
writer.write(value);
|
||||||
|
|||||||
@@ -2,27 +2,88 @@ import Device.NanoPi;
|
|||||||
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
import Audio.*;
|
||||||
|
import org.pmw.tinylog.Logger;
|
||||||
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
static int btnBuffVal;
|
||||||
|
static AudioPlayer AP = new AudioPlayer();
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
var npi = new NanoPi();
|
var npi = new NanoPi();
|
||||||
DigitalInput talkButton = new DigitalInput(npi.GetGPIO(12));
|
int Freq = 44100;
|
||||||
DigitalOutput LED1 = new DigitalOutput(npi.GetGPIO(20),true);
|
|
||||||
System.out.println("is initialized :"+ talkButton.getIsInitialized());
|
|
||||||
System.out.println("Test Program GPIO di linux");
|
|
||||||
|
|
||||||
|
|
||||||
|
DigitalInput talkButton = new DigitalInput(npi.GetGPIO(12));
|
||||||
|
DigitalOutput LED1 = new DigitalOutput(npi.GetGPIO(20),false);
|
||||||
|
int devIndx = AP.FindOutputDevice("USB");
|
||||||
|
if (devIndx != -1){
|
||||||
|
if (AP.OpenDevice(devIndx,Freq)){
|
||||||
|
AP.setMasterVolume(50);
|
||||||
|
}
|
||||||
|
}else Logger.error("Failed to find USB Device");
|
||||||
|
|
||||||
|
if (AP.isInited()) {
|
||||||
|
System.out.println("Main Timer is started!");
|
||||||
Timer MainTimer = new Timer();
|
Timer MainTimer = new Timer();
|
||||||
MainTimer.schedule(new TimerTask() {
|
MainTimer.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
System.out.println(btnBuffVal);
|
||||||
if(talkButton.ReadState() == 1 ){
|
if(talkButton.ReadState() == 1 ){
|
||||||
LED1.SetHigh();
|
//button is release
|
||||||
|
if (btnBuffVal > 2){
|
||||||
|
//button is pressed
|
||||||
|
ButtonIsShortPressed();
|
||||||
|
}
|
||||||
|
btnBuffVal = 0;
|
||||||
}else{
|
}else{
|
||||||
LED1.SetLow();
|
//button is pressed
|
||||||
}
|
btnBuffVal = btnBuffVal + 1;
|
||||||
}
|
|
||||||
},0,1000);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},0,500);
|
||||||
|
}else{
|
||||||
|
System.out.println("Stop Program!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static PlaybackEvent pe = new PlaybackEvent() {
|
||||||
|
@Override
|
||||||
|
public void onPlaybackStart(AudioFileProperties prop) {
|
||||||
|
Logger.info("Playback Started{}", prop.filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlaybackFinished(AudioFileProperties prop) {
|
||||||
|
Logger.info("Playback Finished{}", prop.filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlaybackFailure(AudioFileProperties prop, String reason) {
|
||||||
|
Logger.info("Playback Failed{} Reason: {}", prop.filename, reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlaybackLooped(AudioFileProperties prop) {
|
||||||
|
Logger.info("Playback Looped{}", prop.filename);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private static void ButtonIsShortPressed(){
|
||||||
|
//play file here
|
||||||
|
System.out.println("Button is pressed");
|
||||||
|
playFile("/home/pi/test.wav");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void playFile(String filename){
|
||||||
|
AudioFileProperties prop = AP.OpenAudioFile(filename);
|
||||||
|
if (prop!=null){
|
||||||
|
AP.PlayAudioFile(prop, false, pe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user