Skip to content

Commit

Permalink
Fix/update package api (#75)
Browse files Browse the repository at this point in the history
* Update dependency .branch() to branch:

Signed-off-by: Andy Liu <[email protected]>

* Update Float/Double print

Signed-off-by: Andy Liu <[email protected]>

* Update Float/Double print

Signed-off-by: Andy Liu <[email protected]>

* Update MCP4725

Signed-off-by: Andy Liu <[email protected]>

* Update action

Signed-off-by: Andy Liu <[email protected]>

---------

Signed-off-by: Andy Liu <[email protected]>
  • Loading branch information
andy0808 authored Oct 29, 2024
1 parent 12ecdad commit b730cc0
Show file tree
Hide file tree
Showing 91 changed files with 496 additions and 327 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ name: build
on:
push:
branches:
- main
- 'fix/**'
- 'feature/**'
- 'fix/**'
- develop
- main
- 'release/**'
paths:
- 'Sources/**'
- 'Examples/**'
- 'Tests/**'
pull_request:
branches:
- main
- 'release/**'
schedule:
- cron: '1 0 * * 4'

Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/host_test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
name: host test


on:
push:
branches:
- main
- 'fix/**'
- 'feature/**'
- 'fix/**'
- develop
- main
- 'release/**'
paths:
- 'Sources/**'
- 'Examples/**'
- 'Tests/**'
pull_request:
branches:
- main
- 'release/**'
schedule:
- cron: '1 0 * * 4'


jobs:
host_test:
uses: madmachineio/actions/.github/workflows/host_test.yml@main
uses: madmachineio/actions/.github/workflows/host_test.yml@main
2 changes: 1 addition & 1 deletion Examples/ADT7410/ReadTemp/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
Expand Down
9 changes: 8 additions & 1 deletion Examples/ADT7410/ReadTemp/Sources/ReadTemp/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,12 @@ while (true) {
sleep(ms: 2000)
sensor.setNumberOfFaults(.ONE)

print("Tempature is \(sensor.readCelcius()) C")
let temp = getDoubleString(sensor.readCelcius())
print("Temperature is " + temp + "°C")
}

func getDoubleString(_ num: Double) -> String {
let int = Int(num)
let frac = Int((num - Double(int)) * 100)
return "\(int).\(frac)"
}
10 changes: 5 additions & 5 deletions Examples/ADXL345/I2CReadAcceleration/Package.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// swift-tools-version:5.3
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "I2CReadAcceleration",
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/madmachineio/SwiftIO.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadBoards.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadDrivers.git", .branch("main")),
.package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
.executableTarget(
name: "I2CReadAcceleration",
dependencies: [
"SwiftIO",
Expand Down
10 changes: 5 additions & 5 deletions Examples/ADXL345/SPIReadAcceleration/Package.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// swift-tools-version:5.3
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "SPIReadAcceleration",
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/madmachineio/SwiftIO.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadBoards.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadDrivers.git", .branch("main")),
.package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
.executableTarget(
name: "SPIReadAcceleration",
dependencies: [
"SwiftIO",
Expand Down
10 changes: 5 additions & 5 deletions Examples/AHTx0/ReadValues/Package.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// swift-tools-version:5.3
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "ReadValues",
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/madmachineio/SwiftIO.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadBoards.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadDrivers.git", .branch("main")),
.package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
.executableTarget(
name: "ReadValues",
dependencies: [
"SwiftIO",
Expand Down
14 changes: 10 additions & 4 deletions Examples/AHTx0/ReadValues/Sources/ReadValues/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ let i2c = I2C(Id.I2C0)
let humiture = AHTx0(i2c)

while true {
let temperature = humiture.readCelsius()
let humidity = humiture.readHumidity()
print("temperature: \(temperature)°C")
print("humidity: \(humidity)%")
let temperature = getFloatString(humiture.readCelsius())
let humidity = getFloatString(humiture.readHumidity())
print("temperature: " + temperature + "°C")
print("humidity: " + humidity + "%")
sleep(ms: 1000)
}

func getFloatString(_ num: Float) -> String {
let int = Int(num)
let frac = Int((num - Float(int)) * 100)
return "\(int).\(frac)"
}
8 changes: 4 additions & 4 deletions Examples/AMG88xx/ReadTemperatures/Package.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// swift-tools-version:5.7
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "ReadTemperatures",
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/madmachineio/SwiftIO.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadBoards.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadDrivers.git", .branch("main")),
.package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
8 changes: 4 additions & 4 deletions Examples/AMG88xx/ThermalImage/Package.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// swift-tools-version:5.7
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "ThermalImage",
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/madmachineio/SwiftIO.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadBoards.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadDrivers.git", .branch("main")),
.package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
10 changes: 5 additions & 5 deletions Examples/APDS9960/ColorDetection/Package.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// swift-tools-version:5.3
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "ColorDetection",
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/madmachineio/SwiftIO.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadBoards.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadDrivers.git", .branch("main")),
.package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
.executableTarget(
name: "ColorDetection",
dependencies: [
"SwiftIO",
Expand Down
10 changes: 5 additions & 5 deletions Examples/APDS9960/GestureDetection/Package.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// swift-tools-version:5.3
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "GestureDetection",
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/madmachineio/SwiftIO.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadBoards.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadDrivers.git", .branch("main")),
.package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
.executableTarget(
name: "GestureDetection",
dependencies: [
"SwiftIO",
Expand Down
10 changes: 5 additions & 5 deletions Examples/APDS9960/ProximityDetection/Package.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// swift-tools-version:5.3
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "ProximityDetection",
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/madmachineio/SwiftIO.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadBoards.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadDrivers.git", .branch("main")),
.package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
.executableTarget(
name: "ProximityDetection",
dependencies: [
"SwiftIO",
Expand Down
8 changes: 4 additions & 4 deletions Examples/AS7341/ReadAll/Package.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// swift-tools-version:5.7
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "ReadAll",
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/madmachineio/SwiftIO.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadBoards.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadDrivers.git", .branch("main")),
.package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
8 changes: 4 additions & 4 deletions Examples/AS7341/ReadOneByOne/Package.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// swift-tools-version:5.7
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "ReadOneByOne",
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/madmachineio/SwiftIO.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadBoards.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadDrivers.git", .branch("main")),
.package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
10 changes: 5 additions & 5 deletions Examples/BH1750/ReadLux/Package.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// swift-tools-version:5.3
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "ReadLux",
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/madmachineio/SwiftIO.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadBoards.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadDrivers.git", .branch("main")),
.package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
.executableTarget(
name: "ReadLux",
dependencies: [
"SwiftIO",
Expand Down
9 changes: 8 additions & 1 deletion Examples/BH1750/ReadLux/Sources/ReadLux/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ let i2c = I2C(Id.I2C0)
let sensor = BH1750(i2c)

while true {
print("Lux: \(sensor.readLux())")
let luxString = getFloatString(sensor.readLux())
print("Lux: " + luxString)
sleep(ms: 1000)
}

func getFloatString(_ num: Float) -> String {
let int = Int(num)
let frac = Int((num - Float(int)) * 100)
return "\(int).\(frac)"
}
10 changes: 5 additions & 5 deletions Examples/BME680/I2CReadValues/Package.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// swift-tools-version:5.3
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "I2CReadValues",
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/madmachineio/SwiftIO.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadBoards.git", .branch("main")),
.package(url: "https://github.com/madmachineio/MadDrivers.git", .branch("main")),
.package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
.executableTarget(
name: "I2CReadValues",
dependencies: [
"SwiftIO",
Expand Down
14 changes: 10 additions & 4 deletions Examples/BME680/I2CReadValues/Sources/I2CReadValues/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ let i2c = I2C(Id.I2C0)
let sensor = BME680(i2c)

while true {
print("Temperature: \(sensor.readTemperature())")
print("Humiture: \(sensor.readHumidity())")
print("Pressure: \(sensor.readPressure())")
print("Gas: \(sensor.readGasResistance())")
print("Temperature: \(getDoubleString(sensor.readTemperature()))")
print("Humiture: \(getDoubleString(sensor.readHumidity()))")
print("Pressure: \(getDoubleString(sensor.readPressure()))")
print("Gas: \(getDoubleString(sensor.readGasResistance()))")
sleep(ms: 2000)
}

func getDoubleString(_ num: Double) -> String {
let int = Int(num)
let frac = Int((num - Double(int)) * 100)
return "\(int).\(frac)"
}
Loading

0 comments on commit b730cc0

Please sign in to comment.