Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/actions/setup-node…
Browse files Browse the repository at this point in the history
…-4.0.2
  • Loading branch information
johntalton authored Mar 26, 2024
2 parents 64f4f18 + 1e19860 commit 6fbbd40
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 35 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@johntalton/and-other-delights",
"version": "6.2.0",
"version": "7.0.0",
"description": "",
"main": "src/aod.mjs",
"exports": {
Expand Down Expand Up @@ -79,11 +79,11 @@
"@types/chai": "^4.2.11",
"@types/mocha": "^10.0.6",
"@types/node": "^20.10.5",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"auditjs": "^4.0.18",
"c8": "^8.0.1",
"chai": "^4.3.3",
"c8": "^9.1.0",
"chai": "^5.1.0",
"eslint": "^8.22.0",
"eslint-import-resolver-typescript": "^3.4.1",
"eslint-plugin-fp": "^2.3.0",
Expand Down
54 changes: 29 additions & 25 deletions src/busutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* eslint-disable no-loops/no-loops */
/* eslint-disable fp/no-loops */
/* eslint-disable immutable/no-let */
import { I2CAddressedBus } from './i2c-addressed'
import { I2CAddressedTransactionBus } from './i2c-addressedtransaction.js'

export type Block = [number, number]
export type BlockList = Array<Block>
Expand Down Expand Up @@ -50,7 +50,7 @@ export class BusUtil {
* @returns A Promise the resolves to the read Buffer.
*
**/
static async readI2cBlocks(abus: I2CAddressedBus, blocks: BlockList, sourceBufferOrNull: UtilBufferSource | undefined = undefined): Promise<ArrayBuffer> {
static async readI2cBlocks(atbus: I2CAddressedTransactionBus, blocks: BlockList, sourceBufferOrNull: UtilBufferSource | undefined = undefined): Promise<ArrayBuffer> {

Check warning on line 53 in src/busutil.ts

View workflow job for this annotation

GitHub Actions / Test (16, ubuntu-latest)

This line has a length of 168. Maximum allowed is 120

Check warning on line 53 in src/busutil.ts

View workflow job for this annotation

GitHub Actions / Test (20, ubuntu-latest)

This line has a length of 168. Maximum allowed is 120
BusUtil.assertNormalBlock(blocks)

const totalLength = BusUtil.sourceDataLength(blocks)
Expand All @@ -60,16 +60,18 @@ export class BusUtil {
new Uint8Array(sourceBuffer.buffer, sourceBuffer.byteOffset, sourceBuffer.byteLength) :
new Uint8Array(sourceBuffer)

let cursor = 0
for (const block of blocks) {
const [reg, len] = block
try {
const abuffer = await abus.readI2cBlock(reg, len)
buffer.set(new Uint8Array(abuffer), cursor)
cursor += len
} catch (e) { console.warn({ e }); throw e }
}
return buffer.buffer
return atbus.transaction(async abus => {
let cursor = 0

Check warning on line 64 in src/busutil.ts

View workflow job for this annotation

GitHub Actions / Test (16, ubuntu-latest)

Number constants declarations must use 'const'

Check warning on line 64 in src/busutil.ts

View workflow job for this annotation

GitHub Actions / Test (20, ubuntu-latest)

Number constants declarations must use 'const'
for (const block of blocks) {
const [reg, len] = block
try {
const abuffer = await abus.readI2cBlock(reg, len)
buffer.set(new Uint8Array(abuffer), cursor)
cursor += len
} catch (e) { console.warn({ e }); throw e }
}
return buffer.buffer
})
}

/**
Expand All @@ -88,7 +90,7 @@ export class BusUtil {
* this call over async interfaces will not always result as expected.
**/
static writeI2cBlocks(
abus: I2CAddressedBus,
atbus: I2CAddressedTransactionBus,
blocks: BlockList,
sourceBuffer: UtilBufferSource): Promise<void> {

Expand All @@ -106,18 +108,20 @@ export class BusUtil {
throw new Error('max address is outside buffer length')
}

return Promise.all(blocks.map(([reg, len]) => {
return abus.writeI2cBlock(reg, buffer.subarray(reg, reg + len))
.then(() => len)
}))
.then(lengths => lengths.reduce((acc, item) => acc + item, 0))
.then(bytesWritten => {
if (bytesWritten !== totalLength) {
throw new Error('bytes written mismatch')
}

return // eslint-disable-line no-useless-return
})
return atbus.transaction(async abus => {
return Promise.all(blocks.map(([reg, len]) => {
return abus.writeI2cBlock(reg, buffer.subarray(reg, reg + len))
.then(() => len)

Check warning on line 114 in src/busutil.ts

View workflow job for this annotation

GitHub Actions / Test (16, ubuntu-latest)

Prefer await to then()/catch()/finally()

Check warning on line 114 in src/busutil.ts

View workflow job for this annotation

GitHub Actions / Test (20, ubuntu-latest)

Prefer await to then()/catch()/finally()
}))
.then(lengths => lengths.reduce((acc, item) => acc + item, 0))

Check warning on line 116 in src/busutil.ts

View workflow job for this annotation

GitHub Actions / Test (16, ubuntu-latest)

Prefer await to then()/catch()/finally()

Check warning on line 116 in src/busutil.ts

View workflow job for this annotation

GitHub Actions / Test (16, ubuntu-latest)

No magic number: 0

Check warning on line 116 in src/busutil.ts

View workflow job for this annotation

GitHub Actions / Test (20, ubuntu-latest)

Prefer await to then()/catch()/finally()

Check warning on line 116 in src/busutil.ts

View workflow job for this annotation

GitHub Actions / Test (20, ubuntu-latest)

No magic number: 0
.then(bytesWritten => {

Check warning on line 117 in src/busutil.ts

View workflow job for this annotation

GitHub Actions / Test (16, ubuntu-latest)

Prefer await to then()/catch()/finally()

Check warning on line 117 in src/busutil.ts

View workflow job for this annotation

GitHub Actions / Test (20, ubuntu-latest)

Prefer await to then()/catch()/finally()
if (bytesWritten !== totalLength) {
throw new Error('bytes written mismatch')
}

return // eslint-disable-line no-useless-return
})
})
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/i2c-addressedtransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ export class I2CAddressedTransactionBus extends I2CAddressedBus {

async transaction<T>(cb: AddressedTransactionCallback<T>): Promise<T> {
// eslint-disable-next-line promise/prefer-await-to-callbacks
return this.#bus.transaction((tbus: TransactionBusProxy) => cb(new AddressedTransactionBusProxy(tbus, this.address)))
return this.#bus.transaction(async (tbus: TransactionBusProxy) => cb(new AddressedTransactionBusProxy(tbus, this.address)))
}
}
8 changes: 4 additions & 4 deletions src/i2c-transactionbus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class I2CTransactionBus extends I2CProxyBus implements I2CBus {
#queue: Promise<unknown>
#nextTransactionID

static from(bus: I2CBus) { console.log('HEREHERE'); return new I2CTransactionBus(bus) }
static from(bus: I2CBus) { return new I2CTransactionBus(bus) }

constructor(bus: I2CBus) {
super(bus)
Expand All @@ -34,14 +34,14 @@ export class I2CTransactionBus extends I2CProxyBus implements I2CBus {
get name() { return `TransactionBus(${this.bus.name})` }

async transaction<T>(cb: TransactionCallback<T>): Promise<T> {
console.log('*** transaction created')
//console.log('*** transaction created')

Check failure on line 37 in src/i2c-transactionbus.ts

View workflow job for this annotation

GitHub Actions / Test (16, ubuntu-latest)

Expected exception block, space or tab after '//' in comment

Check failure on line 37 in src/i2c-transactionbus.ts

View workflow job for this annotation

GitHub Actions / Test (20, ubuntu-latest)

Expected exception block, space or tab after '//' in comment
const id = this.#nextTransactionID += 1
const proxyBus = new TransactionBusProxy(this.bus, id)
const nextQ = this.#queue
.then(() => console.log('*** transaction start', id))
//.then(() => console.log('*** transaction start', id))

Check failure on line 41 in src/i2c-transactionbus.ts

View workflow job for this annotation

GitHub Actions / Test (16, ubuntu-latest)

Expected exception block, space or tab after '//' in comment

Check failure on line 41 in src/i2c-transactionbus.ts

View workflow job for this annotation

GitHub Actions / Test (20, ubuntu-latest)

Expected exception block, space or tab after '//' in comment
// eslint-disable-next-line promise/prefer-await-to-callbacks, promise/no-callback-in-promise
.then(async () => cb(proxyBus))
.then(result => { console.log('*** transaction end', id); return result })
//.then(result => { console.log('*** transaction end', id); return result })

Check failure on line 44 in src/i2c-transactionbus.ts

View workflow job for this annotation

GitHub Actions / Test (16, ubuntu-latest)

Expected exception block, space or tab after '//' in comment

Check failure on line 44 in src/i2c-transactionbus.ts

View workflow job for this annotation

GitHub Actions / Test (20, ubuntu-latest)

Expected exception block, space or tab after '//' in comment

this.#queue = nextQ

Expand Down

0 comments on commit 6fbbd40

Please sign in to comment.