-
Notifications
You must be signed in to change notification settings - Fork 9
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
25 changed files
with
1,934 additions
and
156 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
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
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,68 @@ | ||
/* | ||
|
||
Copyright 2021 Microoled | ||
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 Foundation | ||
|
||
/// Information about free space. | ||
public class ConfigurationDescription { | ||
|
||
/// The configuration name | ||
public let name: String | ||
|
||
/// The configuration size | ||
public let size: UInt32 | ||
|
||
/// The configuration version | ||
public let version: UInt32 | ||
|
||
/// The configuration usage count | ||
public let usageCnt: UInt8 | ||
|
||
/// The configuration install count | ||
public let installCnt: UInt8 | ||
|
||
/// The configuration flag for system configuration | ||
public let isSystem: Bool | ||
|
||
init(_ name: String, _ size: UInt32, _ version: UInt32, _ usageCnt: UInt8, _ installCnt: UInt8, _ isSystem: Bool) { | ||
self.name = name | ||
self.size = size | ||
self.version = version | ||
self.usageCnt = usageCnt | ||
self.installCnt = installCnt | ||
self.isSystem = isSystem | ||
} | ||
|
||
internal static func fromCommandResponseData(_ data: CommandResponseData) -> [ConfigurationDescription] { | ||
var results: [ConfigurationDescription] = [] | ||
let offset = 0 | ||
while (offset < data.count) { | ||
let subData = data.suffix(from: offset) | ||
let nameSize = subData.firstIndex(of: 0) ?? 0 | ||
|
||
guard subData.count >= nameSize+11 else { return results } | ||
|
||
let name = String(decoding: Array(subData[0...nameSize-1]), as: UTF8.self) | ||
let size = UInt32.fromUInt32ByteArray(bytes: Array(subData[nameSize+1...nameSize+4])) | ||
let version = UInt32.fromUInt32ByteArray(bytes: Array(subData[nameSize+5...nameSize+8])) | ||
let usageCnt = subData[nameSize+9] | ||
let installCnt = subData[nameSize+10] | ||
let isSystem = subData[nameSize+11] != 0 | ||
|
||
results.append(ConfigurationDescription(name, size, version, usageCnt, installCnt, isSystem)) | ||
} | ||
return results | ||
} | ||
} |
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,60 @@ | ||
/* | ||
|
||
Copyright 2021 Microoled | ||
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 Foundation | ||
|
||
/// Information about free space. | ||
public class ConfigurationElementsInfo { | ||
|
||
/// The configuration version | ||
public let version: UInt32 | ||
|
||
/// The number of image in this configuration | ||
public let nbImg: UInt8 | ||
|
||
/// The number of layout in this configuration | ||
public let nbLayout: UInt8 | ||
|
||
/// The number of font in this configuration | ||
public let nbFont: UInt8 | ||
|
||
/// The number of page in this configuration | ||
public let nbPage: UInt8 | ||
|
||
/// The number of gauge in this configuration | ||
public let nbGauge: UInt8 | ||
|
||
init(_ version: UInt32, _ nbImg: UInt8, _ nbLayout: UInt8, _ nbFont: UInt8, _ nbPage: UInt8, _ nbGauge: UInt8) { | ||
self.version = version | ||
self.nbImg = nbImg | ||
self.nbLayout = nbLayout | ||
self.nbFont = nbFont | ||
self.nbPage = nbPage | ||
self.nbGauge = nbGauge | ||
} | ||
|
||
internal static func fromCommandResponseData(_ data: CommandResponseData) -> ConfigurationElementsInfo { | ||
guard data.count >= 9 else { return ConfigurationElementsInfo(0, 0, 0, 0, 0, 0) } | ||
|
||
let version = UInt32.fromUInt32ByteArray(bytes: Array(data[0...3])) | ||
let nbImg = data[4] | ||
let nbLayout = data[5] | ||
let nbFont = data[6] | ||
let nbPage = data[7] | ||
let nbGauge = data[8] | ||
|
||
return ConfigurationElementsInfo(version, nbImg, nbLayout, nbFont, nbPage, nbGauge) | ||
} | ||
} |
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,41 @@ | ||
/* | ||
|
||
Copyright 2021 Microoled | ||
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 Foundation | ||
|
||
/// Data describing a font that can be saved on the device. | ||
public class FontInfo { | ||
|
||
/// The id of the font | ||
public let id: UInt8 | ||
|
||
/// The height of characters in pixels | ||
public let height: UInt8 | ||
|
||
public init(id: UInt8, height: UInt8) { | ||
self.id = id | ||
self.height = height | ||
} | ||
|
||
internal static func fromCommandResponseData(_ data: CommandResponseData) -> [FontInfo] { | ||
var results: [FontInfo] = [] | ||
var offset = 0 | ||
while (offset < data.count) { | ||
results.append(FontInfo(id: data[offset], height: data[offset+1])) | ||
offset += 2 | ||
} | ||
return results | ||
} | ||
} |
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,40 @@ | ||
/* | ||
|
||
Copyright 2021 Microoled | ||
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 Foundation | ||
|
||
/// Information about free space. | ||
public class FreeSpace { | ||
|
||
/// The total available space | ||
public let totalSize: UInt32 | ||
|
||
/// The available free space | ||
public let freeSpace: UInt32 | ||
|
||
init(_ totalSize: UInt32, _ freeSpace: UInt32) { | ||
self.totalSize = totalSize | ||
self.freeSpace = freeSpace | ||
} | ||
|
||
internal static func fromCommandResponseData(_ data: CommandResponseData) -> FreeSpace { | ||
guard data.count >= 8 else { return FreeSpace(0, 0) } | ||
|
||
let totalSpace = UInt32.fromUInt32ByteArray(bytes: Array(data[0...3])) | ||
let freeSpace = UInt32.fromUInt32ByteArray(bytes: Array(data[4...7])) | ||
|
||
return FreeSpace(totalSpace, freeSpace) | ||
} | ||
} |
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,65 @@ | ||
/* | ||
|
||
Copyright 2021 Microoled | ||
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 Foundation | ||
|
||
/// Information about free space. | ||
public class GaugeInfo { | ||
|
||
/// The x coordinate of the gauge | ||
public let x: Int | ||
|
||
/// The y coordinate of the gauge | ||
public let y: Int | ||
|
||
/// The radius of the gauge | ||
public let r: UInt16 | ||
|
||
/// The internal radius of the gauge | ||
public let rin: UInt16 | ||
|
||
/// The start angle of the gauge | ||
public let start: UInt8 | ||
|
||
/// The end angle of the gauge | ||
public let end: UInt8 | ||
|
||
/// The orientation of the gauge | ||
public let clockwise: Bool | ||
|
||
init(_ x: Int, _ y: Int, _ r: UInt16, _ rin: UInt16, _ start: UInt8, _ end: UInt8, _ clockwise: Bool) { | ||
self.x = x | ||
self.y = y | ||
self.r = r | ||
self.rin = rin | ||
self.start = start | ||
self.end = end | ||
self.clockwise = clockwise | ||
} | ||
|
||
internal static func fromCommandResponseData(_ data: CommandResponseData) -> GaugeInfo { | ||
guard data.count >= 10 else { return GaugeInfo(0, 0, 0, 0, 0, 0, false) } | ||
|
||
let x = Int.fromUInt16ByteArray(bytes: Array(data[0...1])) | ||
let y = Int.fromUInt16ByteArray(bytes: Array(data[2...3])) | ||
let r = UInt16.fromUInt16ByteArray(bytes: Array(data[4...5])) | ||
let rin = UInt16.fromUInt16ByteArray(bytes: Array(data[6...7])) | ||
let start = data[8] | ||
let end = data[9] | ||
let clockwise = data[10] != 0 | ||
|
||
return GaugeInfo(x, y, r, rin, start, end, clockwise) | ||
} | ||
} |
Oops, something went wrong.