-
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.
- Loading branch information
Showing
8 changed files
with
180 additions
and
38 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,56 @@ | ||
<!-- | ||
SPDX-License-Identifier: GPL-2.0-or-later | ||
Copyright (C) 2024 Oren Sokoler (https://github.com/orenskl) | ||
--> | ||
|
||
<project name="adc" basedir="." default="bin"> | ||
|
||
<property environment="env"/> | ||
<fail unless="env.JAVA_PICO_HOME" message="Please set JAVA_PICO_HOME to the location of the pjvm base directory"/> | ||
<property name="pjvm.dir" value="${env.JAVA_PICO_HOME}"/> | ||
|
||
<property name="src.dir" value="src"/> | ||
<property name="build.dir" value="build"/> | ||
<property name="classes.dir" value="${build.dir}/classes"/> | ||
<property name="jar.dir" value="${build.dir}/jar"/> | ||
<property name="main-class" value="Main"/> | ||
|
||
<target name="clean"> | ||
<delete dir="${build.dir}"/> | ||
</target> | ||
|
||
<target name="compile"> | ||
<mkdir dir="${classes.dir}"/> | ||
<javac target="1.4" source="1.4" srcdir="${src.dir}" destdir="${classes.dir}" | ||
bootclasspath="${pjvm.dir}/lib/classes.jar" includeantruntime="false"/> | ||
</target> | ||
|
||
<target name="preverify" depends="compile"> | ||
<echo message="Preverifying classes"/> | ||
<exec executable="${pjvm.dir}/bin/preverify"> | ||
<arg value="-d"/> | ||
<arg value="${classes.dir}.preverify"/> | ||
<arg value="-classpath"/> | ||
<arg value="${pjvm.dir}/lib/classes.jar"/> | ||
<arg value="${classes.dir}"/> | ||
</exec> | ||
</target> | ||
|
||
<target name="jar" depends="preverify"> | ||
<mkdir dir="${jar.dir}"/> | ||
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}.preverify" compress="false" /> | ||
</target> | ||
|
||
<target name="bin" depends="jar"> | ||
<echo message="Wrapping JAR"/> | ||
<exec executable="${pjvm.dir}/bin/wrapjar.sh"> | ||
<arg value="${jar.dir}/${ant.project.name}.jar"/> | ||
<arg value="${jar.dir}/${ant.project.name}.jar.bin"/> | ||
</exec> | ||
</target> | ||
|
||
<target name="clean-build" depends="clean,bin"/> | ||
|
||
</project> |
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,29 @@ | ||
/* | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-or-later | ||
* Copyright (C) 2024 Oren Sokoler (https://github.com/orenskl) | ||
* | ||
*/ | ||
|
||
import pico.hardware.ADCChannel; | ||
|
||
class Main { | ||
|
||
/* A simple ADC test */ | ||
private static final int ADC_CHANNEL = 2; | ||
|
||
public static void main(String[] args) { | ||
System.out.println("ADC example"); | ||
ADCChannel a = new ADCChannel(ADC_CHANNEL); | ||
while (true) { | ||
int value = a.read(); | ||
System.out.println("ADC Channel " + ADC_CHANNEL + " value is " + value); | ||
try { | ||
Thread.sleep(500); | ||
} catch (Exception e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
} |
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
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,53 @@ | ||
/* | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-or-later | ||
* Copyright (C) 2024 Oren Sokoler (https://github.com/orenskl) | ||
* | ||
*/ | ||
|
||
package pico.hardware; | ||
|
||
/** | ||
* A <code>ADCChannel</code> class represents a single Analog To Digital | ||
* conversion channel, the channel number is hardware specific and is not | ||
* decoded or encoded in anyway, it is passed to the hardware level as is. | ||
* The values that are read from the ADC are integers and are the direct | ||
* read of the ADC, e.g. if the ADC is a 12 bit ADC then the values you | ||
* could get are from 0 to 4095. | ||
*/ | ||
|
||
public class ADCChannel { | ||
|
||
/** | ||
* The ADC channel number | ||
*/ | ||
private int channel; | ||
|
||
/** | ||
* | ||
* Constructor for a single ADC channel | ||
* | ||
* @param channel The channel number | ||
* | ||
*/ | ||
public ADCChannel ( int channel ) { | ||
this.channel = channel; | ||
adc_init(channel); | ||
} | ||
|
||
/** | ||
* Perform a single conversion and read its value from the ADC channel | ||
* | ||
* @return the ADC channel digital value | ||
*/ | ||
public int read () { | ||
return adc_read(this.channel); | ||
} | ||
|
||
/* | ||
* Natives for the device hardware | ||
*/ | ||
private static native void adc_init ( int channel ); | ||
private static native int adc_read ( int channel ); | ||
|
||
} |
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
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