Skip to content

Commit

Permalink
Develop (#29)
Browse files Browse the repository at this point in the history
* Update

Signed-off-by: Andy Liu <andy@madmachine.io>

* Update for Embedded Swift

Signed-off-by: Andy Liu <andy@madmachine.io>

* Update for Embedded Swift

Signed-off-by: Andy Liu <andy@madmachine.io>

* Update for Embedded Swift

Signed-off-by: Andy Liu <andy@madmachine.io>

* Update for Embedded Swift(Remove swift-extra-json dependenci)

Signed-off-by: Andy Liu <andy@madmachine.io>

* Update for Embedded Swift

Signed-off-by: Andy Liu <andy@madmachine.io>

* Update for Embedded Swift

Signed-off-by: Andy Liu <andy@madmachine.io>

* Update for Embedded Swift

Signed-off-by: Andy Liu <andy@madmachine.io>

* Update for Embedded Swift

Signed-off-by: Andy Liu <andy@madmachine.io>

* Update for Embedded Swift

Signed-off-by: Andy Liu <andy@madmachine.io>

* Update for Embedded Swift

Signed-off-by: Andy Liu <andy@madmachine.io>

* Update for Embedded Swift

Signed-off-by: Andy Liu <andy@madmachine.io>

---------

Signed-off-by: Andy Liu <andy@madmachine.io>
  • Loading branch information
andy0808 authored Sep 26, 2024
1 parent 0fa0409 commit b00ca76
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,11 @@ final public class LCD1602 {
mul *= 10
}
let expandValue = Int(num * Float(mul))
write(x: x, y: y, String(Float(expandValue) / Float(mul)))
let str = getFloatString(Float(expandValue) / Float(mul))
write(x: x, y: y, str)
} else {
write(x: x, y: y, String(num))
let str = getFloatString(num)
write(x: x, y: y, str)
}
}
}
Expand Down Expand Up @@ -279,3 +281,10 @@ extension LCD1602 {
}
}
}


func getFloatString(_ num: Float) -> String {
let int = Int(num)
let frac = Int((num - Float(int)) * 100)
return "\(int).\(frac)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ extension SHT3x {

// Split the 16-bit data into two 8-bit data.
// Write the data to the default address of the sensor.
private func writeCommand(_ command: Command) throws {
private func writeCommand(_ command: Command) throws(Errno) {
let value = command.rawValue
let result = i2c.write([UInt8(value >> 8), UInt8(value & 0xFF)], to: address)
if case .failure(let err) = result {
throw err
}
}

private func readRawValue(into buffer: inout [UInt8]) throws {
private func readRawValue(into buffer: inout [UInt8]) throws(Errno) {
for i in 0..<buffer.count {
buffer[i] = 0
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PWMTone

struct Music {
static let twinkle: [(note: PWMTone.Note, value: Int)] = [
static let twinkle: PWMTone.Track = [
(.C4, 4),
(.C4, 4),
(.G4, 4),
Expand Down
13 changes: 11 additions & 2 deletions Examples/MakerKit/Mission9_LCD/Sources/Mission9_LCD/LCD1602.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,11 @@ final public class LCD1602 {
mul *= 10
}
let expandValue = Int(num * Float(mul))
write(x: x, y: y, String(Float(expandValue) / Float(mul)))
let str = getFloatString(Float(expandValue) / Float(mul))
write(x: x, y: y, str)
} else {
write(x: x, y: y, String(num))
let str = getFloatString(num)
write(x: x, y: y, str)
}
}
}
Expand Down Expand Up @@ -279,3 +281,10 @@ extension LCD1602 {
}
}
}


func getFloatString(_ num: Float) -> String {
let int = Int(num)
let frac = Int((num - Float(int)) * 100)
return "\(int).\(frac)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ let pot = AnalogIn(Id.A0)

// Read the voltage value and print it out every second.
while true {
let potVoltage = pot.readVoltage()
let potVoltage = getFloatString(pot.readVoltage())
print(potVoltage)
sleep(ms: 1000)
}


func getFloatString(_ num: Float) -> String {
let int = Int(num)
let frac = Int((num - Float(int)) * 100)
return "\(int).\(frac)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ do {
print("ESP32 WiFi status: \(esp.wifiStatus)")

let ipInfo = try esp.getStationIP()
print(ipInfo)
for index in 0..<ipInfo.count {
if index != 0 {
print(".\(ipInfo[index])")
} else {
print(ipInfo[index])
}
}

} catch {
print("Error: \(error)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ do {
print("ESP32 WiFi status: \(esp.wifiStatus)")

let ipInfo = try esp.getStationIP()
print(ipInfo)
for index in 0..<ipInfo.count {
if index != 0 {
print(".\(ipInfo[index])")
} else {
print(ipInfo[index])
}
}
} catch {
print("Error: \(error)")
}
Expand Down
8 changes: 0 additions & 8 deletions Examples/SwiftIOPlayground/11WiFi/Weather/.gitignore

This file was deleted.

17 changes: 0 additions & 17 deletions Examples/SwiftIOPlayground/11WiFi/Weather/Package.mmp

This file was deleted.

28 changes: 0 additions & 28 deletions Examples/SwiftIOPlayground/11WiFi/Weather/Package.swift

This file was deleted.

124 changes: 0 additions & 124 deletions Examples/SwiftIOPlayground/11WiFi/Weather/Sources/WeatherInfo.swift

This file was deleted.

60 changes: 0 additions & 60 deletions Examples/SwiftIOPlayground/11WiFi/Weather/Sources/main.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public struct Album {

var buffer = [UInt16](repeating: 0, count: 240 * 240)

try buffer.withUnsafeMutableBytes() {
try file.read(fromAbsoluteOffest: 0, into: $0)
buffer.withUnsafeMutableBytes() {
_ = try? file.read(fromAbsoluteOffest: 0, into: $0)
}

screen.writeScreen(buffer)

try file.close()
} catch {
print(error)
print("File handle error: \(error)")
}

while true {
Expand Down
Loading

0 comments on commit b00ca76

Please sign in to comment.