-
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 #5 from Pi4J/release/2.3.0
Release/2.3.0
- Loading branch information
Showing
12 changed files
with
503 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<!-- | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<!-- | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<!-- | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<!-- | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="Test" type="GradleRunConfiguration" factoryName="Gradle"> | ||
<ExternalSystemSettings> | ||
<option name="executionName"/> | ||
<option name="externalProjectPath" value="$PROJECT_DIR$"/> | ||
<option name="externalSystemIdString" value="GRADLE"/> | ||
<option name="scriptParameters" value=""/> | ||
<option name="taskDescriptions"> | ||
<list/> | ||
</option> | ||
<option name="taskNames"> | ||
<list> | ||
<option value=":lib:check"/> | ||
</list> | ||
</option> | ||
<option name="vmOptions"/> | ||
</ExternalSystemSettings> | ||
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess> | ||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess> | ||
<DebugAllEnabled>false</DebugAllEnabled> | ||
<method v="2"/> | ||
</configuration> | ||
</component> |
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
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,66 @@ | ||
import com.pi4j.io.gpio.digital.DigitalState | ||
import com.pi4j.io.gpio.digital.PullResistance | ||
import com.pi4j.ktx.console | ||
import com.pi4j.ktx.io.digital.digitalInput | ||
import com.pi4j.ktx.io.digital.digitalOutput | ||
import com.pi4j.ktx.io.digital.onLow | ||
import com.pi4j.ktx.io.digital.piGpioProvider | ||
import com.pi4j.ktx.pi4jAsync | ||
import kotlinx.coroutines.delay | ||
|
||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
private const val PIN_BUTTON = 24 // PIN 18 = BCM 24 | ||
private const val PIN_LED = 22 // PIN 15 = BCM 22 | ||
private var pressCount = 0 | ||
|
||
/** | ||
* This application blinks a led and counts the number the button is pressed. The blink speed increases with each | ||
* button press, and after 5 presses the application finishes. | ||
* | ||
* This example fully describes the basic usage of Pi4J-Kotlin + Coroutines | ||
* | ||
* @author Muhammad Hashim (mhashim6) (<a href="https://mhashim6.me">https://mhashim6.me</a>) | ||
*/ | ||
fun main() { | ||
pi4jAsync { | ||
console { | ||
digitalInput(PIN_BUTTON) { | ||
id("button") | ||
name("Press button") | ||
pull(PullResistance.PULL_DOWN) | ||
debounce(3000L) | ||
piGpioProvider() | ||
}.onLow { | ||
pressCount++ | ||
+"Button was pressed for the ${pressCount}th time" | ||
} | ||
|
||
digitalOutput(PIN_LED) { | ||
id("led") | ||
name("LED Flasher") | ||
shutdown(DigitalState.LOW) | ||
initial(DigitalState.LOW) | ||
piGpioProvider() | ||
}.run { | ||
while (pressCount < 5) { | ||
+"LED ${state()}" | ||
toggle() | ||
delay(500L / (pressCount + 1)) | ||
} | ||
} | ||
} | ||
} | ||
} |
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,85 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import com.pi4j.ktx.console | ||
import com.pi4j.ktx.io.i2c | ||
import com.pi4j.ktx.io.linuxFsI2CProvider | ||
import com.pi4j.ktx.io.setPin | ||
import com.pi4j.ktx.pi4j | ||
import com.pi4j.ktx.utils.binStr | ||
import java.lang.Thread.sleep | ||
|
||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
private const val TCA9534_REG_ADDR_OUT_PORT: Int = 0x01 | ||
private const val TCA9534_REG_ADDR_CFG: Int = 0x03 | ||
|
||
/** | ||
* @author Muhammad Hashim (mhashim6) (<a href="https://mhashim6.me">https://mhashim6.me</a>) on 28/12/2022 | ||
*/ | ||
fun main() { | ||
pi4j { | ||
i2c(1, 0x3f) { | ||
id("TCA9534") | ||
linuxFsI2CProvider() | ||
}.use { tca9534Dev -> | ||
val config = tca9534Dev.readRegister(TCA9534_REG_ADDR_CFG) | ||
check(config >= 0) { | ||
"Failed to read configuration from address 0x${"%02x".format(TCA9534_REG_ADDR_CFG)}" | ||
} | ||
|
||
var currentState = tca9534Dev.readRegister(TCA9534_REG_ADDR_OUT_PORT) | ||
if (config != 0x00) { | ||
println( | ||
"TCA9534 is not configured as OUTPUT, setting register 0x${"%02x".format(TCA9534_REG_ADDR_CFG)} to 0x00" | ||
) | ||
currentState = 0x00 | ||
tca9534Dev.writeRegister(TCA9534_REG_ADDR_OUT_PORT, currentState) | ||
tca9534Dev.writeRegister(TCA9534_REG_ADDR_CFG, 0x00) | ||
} | ||
|
||
tca9534Dev.run { | ||
// bit 8, is pin 1 on the board itself, so set pins in reverse: | ||
console { | ||
currentState = setPin(currentState, 8, TCA9534_REG_ADDR_OUT_PORT) | ||
+"Setting TCA9534 to new state ${currentState.binStr()}" | ||
sleep(500L) | ||
currentState = setPin(currentState, 8, TCA9534_REG_ADDR_OUT_PORT, false) | ||
+"Setting TCA9534 to new state ${currentState.binStr()}" | ||
sleep(500L) | ||
currentState = setPin(currentState, 7, TCA9534_REG_ADDR_OUT_PORT) | ||
+"Setting TCA9534 to new state ${currentState.binStr()}" | ||
sleep(500L) | ||
currentState = setPin(currentState, 7, TCA9534_REG_ADDR_OUT_PORT, false) | ||
+"Setting TCA9534 to new state ${currentState.binStr()}" | ||
sleep(500L) | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.