'Droid Inventor Kit' extension library.

Overview

DroidKit

Description

- Do you know 'Droid Inventor Kit' ?

littlebits-box-1-1024x686

(Quote: ‘TURN EVERYONE INTO AN INVENTOR’: THE STORY OF THE LITTLEBITS DROID INVENTOR KIT)


'Droid Inventor Kit' is a kit to create a droid. In addition, the droid can be operated with simple programming from a smartphone. However, there is a problem. Currently, the app has been removed from the store and cannot be installed. So I decided to provide code that can operate the droid from Swift. In short, you can create your own application with this Swift package.


- Sample Screen

App Color Picker Sound Menu

You can check the operation on DroidKitDebugView.

import SwiftUI
import DroidKit

struct ContentView: View {
    
    var body: some View {
        DroidKitDebugView()
    }
}

Don't forget to add bluetooth capability permission (NSBluetoothAlwaysUsageDescription) on your project.


Code

There are 2 core code in this package.

Inspired by tinkertanker/DroidKit and are also built on a 'Concurrency' basis with AsyncBluetooth.

- DroidConnector.swift

public protocol DroidConnectorProtocol: AnyObject {
    var eventPublisher: AnyPublisher<CentralManagerEvent, Never> { get }
    
    /// CentralManager Method
    func scan() async throws
    func connect() async throws
    func disconnect() async throws
    
    /// Peripheral Method
    func discoverServices() async throws
    func discoverCharacteristics() async throws
    func setNotifyValue(with characteristic: Characteristic) async throws
    func setNotifyValues() async throws
    func writeValue(command: UInt8, payload: [UInt8]) async throws
}

This code contains the implementation around Bluetooth. You can access it, but basically you don't have to do it.

- DroidOperator.swift

public protocol DroidOperatorProtocol: AnyObject {
    var eventPublisher: AnyPublisher<CentralManagerEvent, Never> { get }
    
    /// Connection Method
    func connect() async throws
    func disconnect() async throws
    
    /// Action Method
    func action(command: DroidCommand, payload: [UInt8]) async throws
    func go(at speed: Double) async throws
    func back(at speed: Double) async throws
    func turn(by degree: Double) async throws
    func stop() async throws
    func endTurn() async throws
    func changeLEDColor(to color: UIColor) async throws
    func playSound(_ type: DroidSound) async throws
    func wait(for seconds: Double) async throws
}

This code contains the implementation around droid operation. You can operate droid.


Document

The following actions can be used.

- connect

Turn on the connection.

Task {
    do {
        try await DroidOperator.default.connect()
    } catch {
        // catch error
    }
}

- disconnect

Turn off the connection.

Task {
    do {
        try await DroidOperator.default.disconnect()
    } catch {
        // catch error
    }
}

- go

Move forward.

Task {
    do {
        try await DroidOperator.default.go(at: 0.7)
    } catch {
        // catch error
    }
}

- back

Move back.

Task {
    do {
        try await DroidOperator.default.back(at: 0.3)
    } catch {
        // catch error
    }
}

- turn

Turn towards.

Task {
    do {
        try await DroidOperator.default.turn(by: 30)
    } catch {
        // catch error
    }
}

- stop

Stop moving.

Task {
    do {
        try await DroidOperator.default.stop()
    } catch {
        // catch error
    }
}

- endTurn

Reset wheel degree.

Task {
    do {
        try await DroidOperator.default.endTurn()
    } catch {
        // catch error
    }
}

- changeLEDColor

Change body's LED ramp color.

Task {
    do {
        try await DroidOperator.default.changeLEDColor(to: .blue)
    } catch {
        // catch error
    }
}

- playSound

Play sound from droid.

Task {
    do {
        try await DroidOperator.default.playSound(.s10)
    } catch {
        // catch error
    }
}

- wait

Keep the action.

Task {
    do {
        try await DroidOperator.default.go(at: 0.7)
        try await DroidOperator.default.wait(for: 2)
        try await DroidOperator.default.stop(.move)
    } catch {
        // catch error
    }
}

Swift Package Manager

Add the following dependency to your Package.swift file:

.package(url: "https://github.com/crane-hiromu/DroidKit", "2.1.0"..<"3.0.0")

License

MIT, of course ;-) See the LICENSE file.

You might also like...
A stand-alone Swift wrapper around the libpq client library, enabling access to PostgreSQL servers.
A stand-alone Swift wrapper around the libpq client library, enabling access to PostgreSQL servers.

Perfect - PostgreSQL Connector This project provides a Swift wrapper around the libpq client library, enabling access to PostgreSQL servers. This pack

Swift library that makes easier to serialize the user's preferences (app's settings) with system User Defaults or Property List file on disk.

PersistentStorageSerializable PersistentStorageSerializable is a protocol for automatic serialization and deserialization of Swift class, struct or NS

A Library for iOS developers to check newer version of app from the app store
A Library for iOS developers to check newer version of app from the app store

swift-app-update-checker A very simple solution check new version of your application is available on store or not. Example To run the example project

A PostgreSQL client library for Swift. Does not require libpq.

PostgresClientKit PostgresClientKit provides a friendly Swift API for operating against a PostgreSQL database. Features Doesn't require libpq. Postgre

PJAlertView - This library is to make your own custom alert views to match your apps look and feel

PJAlertView - This library is to make your own custom alert views to match your apps look and feel

Easiest local storage library in Swift
Easiest local storage library in Swift

SundeedQLite SundeedQLite is the easiest offline database integration, built using Swift language Requirements iOS 12.0+ XCode 10.3+ Swift 5+ Installa

A stand-alone Swift wrapper around the SQLite 3 client library.
A stand-alone Swift wrapper around the SQLite 3 client library.

Perfect - SQLite Connector This project provides a Swift wrapper around the SQLite 3 library. This package builds with Swift Package Manager and is pa

A Swift library to fetch the schema from a SQLite3 database.
A Swift library to fetch the schema from a SQLite3 database.

SQLite3Schema A small library to fetch the schema of a SQLite database. Contains a SQLite3 helper module for Linux. TBD. Uses just the raw SQLite API.

Releases(2.2.2)
Owner
hcrane
iOS Developer / Developer Relations
hcrane
SwiftPlus - A Swift extension.

SwiftPlus SwiftPlus is made to have a package which contains everyday use extensions, functions and helper classes. Documentation You can find the doc

Knoggl 1 Apr 1, 2022
A stand-alone Swift wrapper around the mongo-c client library, enabling access to MongoDB servers.

This package is deprecated in favour of the official Mongo Swift Driver. We advise users to switch to that pack

PerfectlySoft Inc. 54 Jul 9, 2022
Elegant library to manage the interactions between view and model in Swift

An assistant to manage the interactions between view and model ModelAssistant is a mediator between the view and model. This framework is tailored to

Seyed Samad Gholamzadeh 28 Jan 29, 2022
Disk is a powerful and simple file management library built with Apple's iOS Data Storage Guidelines in mind

Disk is a powerful and simple file management library built with Apple's iOS Data Storage Guidelines in mind

Saoud Rizwan 3k Jan 3, 2023
KeyPathKit is a library that provides the standard functions to manipulate data along with a call-syntax that relies on typed keypaths to make the call sites as short and clean as possible.

KeyPathKit Context Swift 4 has introduced a new type called KeyPath, with allows to access the properties of an object with a very nice syntax. For in

Vincent Pradeilles 406 Dec 25, 2022
🧡 SQLiteOrm-Swift is an ORM library for SQLite3 built with Swift 5

?? Easy to use SQLite ORM library written with Swift

Yevgeniy Zakharov 25 Oct 6, 2022
A library that provides the ability to import/export Realm files from a variety of data container formats.

Realm Converter Realm Converter is an open source software utility framework to make it easier to get data both in and out of Realm. It has been built

Realm 212 Dec 9, 2022
Prephirences is a Swift library that provides useful protocols and convenience methods to manage application preferences, configurations and app-state. UserDefaults

Prephirences - Preϕrences Prephirences is a Swift library that provides useful protocols and convenience methods to manage application preferences, co

Eric Marchand 557 Nov 22, 2022
TypedDefaults is a utility library to type-safely use NSUserDefaults.

TypedDefaults TypedDefaults is a utility library to type-safely use NSUserDefaults. Motivation The talk Keep Calm and Type Erase On by Gwendolyn Westo

Kazunobu Tasaka 110 Feb 6, 2022
A stand-alone Swift wrapper around the MySQL client library, enabling access to MySQL servers.

Perfect - MySQL Connector This project provides a Swift wrapper around the MySQL client library, enabling access to MySQL database servers. This packa

PerfectlySoft Inc. 118 Jan 1, 2023