Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge dev into main 🔀 #1

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"projectName": "<insert the repo's name>",
"projectOwner": "<insert the repo's owner/orgs>"
}
111 changes: 105 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,60 @@ env:
JAVA_VERSION: 17

jobs:
ci:
lint:
runs-on: macos-13
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
fetch-depth: 1

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Lint
run: yarn lint

verify-ios:
runs-on: macos-13
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'

- name: Set up Xcode
run: sudo xcode-select --switch /Applications/Xcode_14.2.app

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Lint
run: yarn lint

- name: Verify
run: yarn verify:ios

verify-android:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'

- name: Setup Java
uses: actions/setup-java@v3
with:
Expand All @@ -33,8 +71,69 @@ jobs:
- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Lint
run: yarn lint

- name: Verify
run: yarn verify
run: yarn verify:android

create-pr:
runs-on: ubuntu-latest
needs: [lint, verify-ios, verify-android]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Configure Git Action bot
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"

- name: Create pull or update pull request
uses: actions/github-script@v6
with:
github-token: ${{ secrets.CREATE_PR_TOKEN }}
script: |
const head = context.payload.ref.replace('refs/heads/', '');
const base = 'main';
const title = 'Merge ' + head + ' into ' + base + ' 🔀';
const body = 'This is an automated PR';

async function run() {
try {
const { data: pulls } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: context.repo.owner + ':' + head,
base: base
});

if (pulls.length > 0) {
const pullNumber = pulls[0].number;
console.log(`Updating existing PR #${pullNumber}`);

await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullNumber,
title: title,
body: body
});
} else {
console.log('Creating new PR');
await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
head: head,
base: base
});
}
} catch (error) {
console.error('Error processing pull request:', error);
throw error;
}
}

run();
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
"cSpell.words": ["Bootloader", "Buttonless", "Softdevice"],
"[swift]": {
"editor.defaultFormatter": "vknabel.vscode-swiftformat"
}
},
"java.configuration.updateBuildConfiguration": "automatic"
}
2 changes: 1 addition & 1 deletion CapacitorCommunityNordicDfu.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '13.0'
s.dependency 'Capacitor'
s.swift_version = '5.1'
s.dependency 'iOSDFULibrary', '~> 4.13.0'
s.dependency 'iOSDFULibrary', '~> 4.14.0'
end
64 changes: 46 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
<p align="center"><br><img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" /></p>
<h3 align="center">Nordic DFU</h3>
<p align="center"><strong><code>@capacitor-community/nordic-dfu</code></strong></p>
<p align="center"><strong><code>capacitor-community-nordic-dfu</code></strong></p>
<p align="center">
Capacitor plugin to interface with Nordic DFU's <a href="https://github.com/NordicSemiconductor/IOS-DFU-Library">IOS-DFU-Library</a> and <a href="https://github.com/NordicSemiconductor/Android-DFU-Library">Android-DFU-Library</a>.
</p>

<p align="center">
<img src="https://img.shields.io/maintenance/yes/2020?style=flat-square" />
<a href="https://github.com/capacitor-community/example/actions?query=workflow%3A%22CI%22"><img src="https://img.shields.io/github/workflow/status/capacitor-community/example/CI?style=flat-square" /></a>
<a href="https://www.npmjs.com/package/@capacitor-community/example"><img src="https://img.shields.io/npm/l/@capacitor-community/example?style=flat-square" /></a>
<br>
<a href="https://www.npmjs.com/package/@capacitor-community/example"><img src="https://img.shields.io/npm/dw/@capacitor-community/example?style=flat-square" /></a>
<a href="https://www.npmjs.com/package/@capacitor-community/example"><img src="https://img.shields.io/npm/v/@capacitor-community/example?style=flat-square" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-0-orange?style=flat-square" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:END -->
<img src="https://img.shields.io/maintenance/yes/2023?style=flat-square" />
<a href="https://github.com/robsonos/nordic-dfu/actions/workflows/ci.yaml"
><img
alt="GitHub Workflow Status (with event)"
src="https://img.shields.io/github/actions/workflow/status/robsonos/nordic-dfu/ci.yaml"
/></a>
<a href="https://www.npmjs.com/package/capacitor-community-nordic-dfu"
><img src="https://img.shields.io/npm/l/capacitor-community-nordic-dfu?style=flat-square"
/></a>
<br />
<a href="https://www.npmjs.com/package/capacitor-community-nordic-dfu"
><img
alt="Downloads from npmjs"
src="https://img.shields.io/npm/dw/capacitor-community-nordic-dfu?style=flat-square"
/></a>
<a href="https://www.npmjs.com/package/capacitor-community-nordic-dfu"
><img alt="Version from npmjs" src="https://img.shields.io/npm/v/capacitor-community-nordic-dfu?style=flat-square"
/></a>
<a href="#contributors"
><img
alt="GitHub contributors from allcontributors.org"
src="https://img.shields.io/github/all-contributors/robsonos/nordic-dfu"
/></a>
</p>

## Table of Contents
Expand All @@ -23,6 +37,7 @@
- [Installation](#installation)
- [Permissions](#permissions)
- [API](#api)
- [Contributors](#contributors)

## Maintainers

Expand All @@ -33,7 +48,7 @@
## Installation

```bash
npm install @capacitor-community/nordic-dfu
npm install capacitor-community-nordic-dfu
npx cap sync
```

Expand Down Expand Up @@ -221,13 +236,15 @@ The DFU update object that is passed to the DFUStateChanged event

Contains data related to the DFU update process, such as progress and speed.

| Prop | Type | Description | Since |
| ----------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`percent`** | <code>number</code> | The current status of upload (0-99). | 1.0.0 |
| **`speed`** | <code>number</code> | The current speed in bytes per millisecond. | 1.0.0 |
| **`avgSpeed`** | <code>number</code> | The average speed in bytes per millisecond. | 1.0.0 |
| **`currentPart`** | <code>number</code> | The number of parts being sent. In case the ZIP file contains a Soft Device and/or a Bootloader together with the application the SD+BL are sent as part 1, then the service starts again and send the application as part 2. | 1.0.0 |
| **`partsTotal`** | <code>number</code> | The total number of parts. | 1.0.0 |
| Prop | Type | Description | Since |
| ------------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`percent`** | <code>number</code> | The current status of upload (0-99). | 1.0.0 |
| **`speed`** | <code>number</code> | The current speed in bytes per millisecond. | 1.0.0 |
| **`avgSpeed`** | <code>number</code> | The average speed in bytes per millisecond. | 1.0.0 |
| **`currentPart`** | <code>number</code> | The number of parts being sent. In case the ZIP file contains a Soft Device and/or a Bootloader together with the application the SD+BL are sent as part 1, then the service starts again and send the application as part 2. | 1.0.0 |
| **`partsTotal`** | <code>number</code> | The total number of parts. | 1.0.0 |
| **`duration`** | <code>number</code> | The total time elapsed since the start of the DFU process in milliseconds | 1.0.1 |
| **`remainingTime`** | <code>number</code> | The estimated remaining time to the end of the DFU process in milliseconds | 1.0.1 |


### Type Aliases
Expand Down Expand Up @@ -259,3 +276,14 @@ Contains data related to the DFU update process, such as progress and speed.
| **`DFU_FAILED`** | <code>'DFU_FAILED'</code> | The DFU process has failed. | 1.0.0 |

</docgen-api>

## Contributors

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ dependencies {
testImplementation "junit:junit:$junitVersion"
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
implementation "no.nordicsemi.android:dfu:2.3.0"
implementation "no.nordicsemi.android:dfu:2.4.1"
}
15 changes: 15 additions & 0 deletions android/src/main/java/com/example/plugin/nordicdfu/NordicDfu.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public void setDFUEventListener(@Nullable DfuEventListener dfuEventListener) {
@Nullable
private DfuEventListener dfuEventListener;

private long startTime = 0;

public NordicDfu(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
DfuServiceInitiator.createDfuNotificationChannel(context);
Expand Down Expand Up @@ -60,6 +62,8 @@ public void onDfuProcessStarting(@NonNull final String deviceAddress) {

@Override
public void onDfuProcessStarted(@NonNull final String deviceAddress) {
startTime = System.currentTimeMillis();

JSObject ret = new JSObject();
ret.put("deviceAddress", deviceAddress);
dfuEventListener.onDfuEvent("DFU_PROCESS_STARTED", ret);
Expand All @@ -81,13 +85,24 @@ public void onProgressChanged(
final int currentPart,
final int partsTotal
) {
long currentTime = System.currentTimeMillis();
long duration = currentTime - startTime;
long remainingTime = 0;

if (percent > 0) {
long estimatedTotalTime = (duration * 100) / percent;
remainingTime = estimatedTotalTime - duration;
}

JSObject ret = new JSObject();
ret.put("deviceAddress", deviceAddress);
ret.put("percent", percent);
ret.put("speed", speed);
ret.put("avgSpeed", avgSpeed);
ret.put("currentPart", currentPart);
ret.put("partsTotal", partsTotal);
ret.put("duration", duration);
ret.put("remainingTime", remainingTime);
dfuEventListener.onDfuEvent("DFU_PROGRESS", ret);
}

Expand Down
6 changes: 3 additions & 3 deletions example/android/variables.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
minSdkVersion = 22
compileSdkVersion = 33
targetSdkVersion = 33
compileSdkVersion = 34
targetSdkVersion = 34
androidxActivityVersion = '1.7.0'
androidxAppCompatVersion = '1.6.1'
androidxCoordinatorLayoutVersion = '1.2.0'
Expand All @@ -13,4 +13,4 @@ ext {
androidxJunitVersion = '1.1.5'
androidxEspressoCoreVersion = '3.5.1'
cordovaAndroidVersion = '10.1.1'
}
}
21 changes: 21 additions & 0 deletions example/ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,25 @@ end

post_install do |installer|
assertDeploymentTarget(installer)

# Get main project development team id
dev_team = ""
project = installer.aggregate_targets.first.user_project
project.targets.each do |target|
target.build_configurations.each do |config|
if dev_team.empty? && !config.build_settings['DEVELOPMENT_TEAM'].nil?
dev_team = config.build_settings['DEVELOPMENT_TEAM']
end
end
end

# Apply development team to all pod targets
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['DEVELOPMENT_TEAM'] = dev_team
config.build_settings['CODE_SIGN_STYLE'] = 'Automatic'
config.build_settings['CODE_SIGN_IDENTITY'] = 'iPhone Developer'
config.build_settings['PROVISIONING_PROFILE_SPECIFIER'] = ''
end
end
end
2 changes: 2 additions & 0 deletions example/src/app/scan/dfu/dfu.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
Average Speed: {{ (update?.data?.avgSpeed ?? 0)* 1000 / 1024 | number }} kBps <br />
Current part: {{ (update?.data?.currentPart ?? 0)}} <br />
Total Parts: {{ (update?.data?.partsTotal ?? 0)}} <br />
Duration: {{ (update?.data?.duration ?? 0) | number }} <br />
Remaining time: {{ (update?.data?.remainingTime ?? 0) | number }} <br />
</ion-item>
<ion-progress-bar
*ngIf="update && update.data && update.data.percent"
Expand Down
2 changes: 1 addition & 1 deletion ios/Plugin/NordicDfu.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Capacitor
import CoreBluetooth
import iOSDFULibrary
import NordicDFU

@objc public class NordicDfu: NSObject {}
Loading
Loading