Skip to content

Commit

Permalink
Merge branch 'rc/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Activelook-dev committed Dec 10, 2021
2 parents 9bb889c + e3176c9 commit 56b032b
Show file tree
Hide file tree
Showing 25 changed files with 1,934 additions and 156 deletions.
23 changes: 13 additions & 10 deletions Classes/Internal/CommandID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ internal enum CommandID: UInt8 {

case gaugeDisplay = 0x70
case gaugeSave = 0x71

case gaugeDelete = 0x72
case gaugeList = 0x73
case gaugeGet = 0x74

case pageSave = 0x80
case pageGet = 0x81
case pageDelete = 0x82
Expand All @@ -91,13 +94,13 @@ internal enum CommandID: UInt8 {
case rConfigID = 0xA2
case setConfigID = 0xA3

// case cfgWrite = 0xD0
// case cfgRead = 0xD1
// case cfgSet = 0xD2
// case cfgList = 0xD3
// case cfgRename = 0xD4
// case cfgDelete = 0xD5
// case cfgDeleteOldest = 0xD6
// case cfgFreeSpace = 0xD7
// case cfdGetNb = 0xD8
case cfgWrite = 0xD0
case cfgRead = 0xD1
case cfgSet = 0xD2
case cfgList = 0xD3
case cfgRename = 0xD4
case cfgDelete = 0xD5
case cfgDeleteLessUsed = 0xD6
case cfgFreeSpace = 0xD7
case cfdGetNb = 0xD8
}
13 changes: 13 additions & 0 deletions Classes/Internal/Data+HexEncodedString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,16 @@ extension Data {
return map { String(format: "%02hhx", $0) }.joined()
}
}

extension StringProtocol {
var hexaData: Data { .init(hexa) }
var hexaBytes: [UInt8] { .init(hexa) }
private var hexa: UnfoldSequence<UInt8, Index> {
sequence(state: startIndex) { startIndex in
guard startIndex < self.endIndex else { return nil }
let endIndex = self.index(startIndex, offsetBy: 2, limitedBy: self.endIndex) ?? self.endIndex
defer { startIndex = endIndex }
return UInt8(self[startIndex..<endIndex], radix: 16)
}
}
}
8 changes: 8 additions & 0 deletions Classes/Internal/Int+ActiveLook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ limitations under the License.
import Foundation

extension Int {

var asUInt8Array: [UInt8] {
let firstByte = UInt8(truncatingIfNeeded: self >> 24)
let secondByte = UInt8(truncatingIfNeeded: self >> 16)
let thirdByte = UInt8(truncatingIfNeeded: self >> 8)
let fourthByte = UInt8(truncatingIfNeeded: self)
return [firstByte, secondByte, thirdByte, fourthByte]
}

internal static func fromUInt16ByteArray(bytes: [UInt8]) -> Int {
guard bytes.count >= 2 else { return 0 }
Expand Down
21 changes: 11 additions & 10 deletions Classes/Public/ActiveLookTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ limitations under the License.
import Foundation

/// Available test patterns
public enum TestPattern: UInt8 {
public enum DemoPattern: UInt8 {
case fill = 0x00
case rect = 0x01
case cross = 0x01
case image = 0x02
}

/// Available states for the glasses' green LED
Expand All @@ -38,14 +39,14 @@ public enum SensorMode: UInt8 {

/// Rotation / orientation of text being displayed
public enum TextRotation: UInt8 {
case topLR = 0x00
case topRL = 0x01
case rightTB = 0x02
case rightBT = 0x03
case bottomRL = 0x04
case bottomLR = 0x05
case leftBT = 0x06
case leftTB = 0x07
case bottomRL = 0x00
case bottomLR = 0x01
case leftBT = 0x02
case leftTB = 0x03
case topLR = 0x04
case topRL = 0x05
case rightTB = 0x06
case rightBT = 0x07
}

/// The Flow Control state.
Expand Down
68 changes: 68 additions & 0 deletions Classes/Public/ConfigurationDescription.swift
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
}
}
60 changes: 60 additions & 0 deletions Classes/Public/ConfigurationElementsInfo.swift
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)
}
}
41 changes: 41 additions & 0 deletions Classes/Public/FontInfo.swift
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
}
}
40 changes: 40 additions & 0 deletions Classes/Public/FreeSpace.swift
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)
}
}
65 changes: 65 additions & 0 deletions Classes/Public/GaugeInfo.swift
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)
}
}
Loading

0 comments on commit 56b032b

Please sign in to comment.