Skip to content

Commit

Permalink
🦄 cleanup and touchup
Browse files Browse the repository at this point in the history
  • Loading branch information
johntalton committed Dec 21, 2023
1 parent d2bf6bb commit 665a9fb
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 38 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/RELEASE.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jobs:
# Publish to NPM
- uses: actions/setup-node@v3
with:
node-version: '14'
registry-url: 'https://registry.npmjs.org/'
- run: npm install
- run: npm run build --if-present
Expand All @@ -19,10 +18,10 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

# Publish to GitHub
- uses: actions/setup-node@v3
with:
node-version: '14'
registry-url: 'https://npm.pkg.github.com/'
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - uses: actions/setup-node@v3
# with:
# node-version: '14'
# registry-url: 'https://npm.pkg.github.com/'
# - run: npm publish
# env:
# NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31 changes: 24 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"name": "@johntalton/i2c-bus-mcp2221",
"version": "2.0.0",
"version": "2.0.1",
"description": "",
"type": "module",
"exports": {
"import": "./lib/index.js",
"require": null
},
"files": [
"lib/**/*.js"
"lib/**/*.js",
"lib/**/*.d.ts",
"lib/**/*.d.ts.map"
],
"scripts": {
"lint": "npm --silent run lint:ts",
"lint": "npm run lint:ts",
"lint:ts": "./node_modules/.bin/eslint --no-inline-config --report-unused-disable-directives --ext .ts src/*.ts",
"test": "npm run test:mocha",
"test:mocha": "mocha",
Expand All @@ -30,11 +32,28 @@
"node": true
},
"rules": {
"no-tabs": "off",
"indent": [
"error",
"tab"
],
"max-len": [
"warn",
{
"code": 120
}
],
"class-methods-use-this": [ "warn" ],
"spellcheck/spell-checker": [
"warn",
{
"ignoreRequire": true,
"identifiers": false,
"minLength": 4,
"skipWords": [
"mcp2221"
]
}
]
}
},
Expand Down Expand Up @@ -64,17 +83,15 @@
"devDependencies": {
"@johntalton/eslint-config": "^2.0.0",
"@types/chai": "^4.2.14",
"@typescript-eslint/eslint-plugin": "^5.14.0",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.21",
"@typescript-eslint/eslint-plugin": "^5.14.0",
"c8": "^7.3.0",
"chai": "^4.2.0",
"eslint": "^8.11.0",
"eslint-plugin-fp": "^2.3.0",

"eslint-plugin-immutable": "^1.0.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsdoc": "^38.0.3",
"eslint-plugin-mocha": "^10.0.3",
"eslint-plugin-no-loops": "^0.3.0",
"eslint-plugin-no-use-extend-native": "^0.5.0",
Expand All @@ -89,6 +106,6 @@
},
"dependencies": {
"@johntalton/and-other-delights": "^6.0.0",
"@johntalton/mcp2221": "file:../mcp2221"
"@johntalton/mcp2221": "^3.0.3"
}
}
20 changes: 10 additions & 10 deletions src/i2c-bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,26 @@ export class I2CBusMCP2221 implements I2CBus {
async readI2cBlock(address: number, cmd: number, length: number, _bufferSource: I2CBufferSource): Promise<I2CReadResult> {
const opaque = this.options.opaquePrefix
console.log('readI2cBlock ', address, cmd, length)
const { status } = await this.device.i2c.writeData({ opaque, address, buffer: Uint8Array.from([ cmd ]) })
if (status !== 'success') { throw new Error('write failed: ' + status) }
const { status } = await this.device.i2c.writeData({ opaque, address, buffer: Uint8Array.from([cmd]) })
if(status !== 'success') { throw new Error('write failed: ' + status) }
const statis = await this.device.common.status({ opaque })
console.log('readI2cblock - wriete command', statis)
console.log('readI2cBlock - write command', statis)

const result = await this.device.i2c.readData({ opaque, address, length }) // length
console.log('readI2cblock - request read', { result })
//if(result.status !== 'success') { throw new Error('not successfull readData') }
// if(result.status !== 'success') { throw new Error('not successfull readData') }
const statis2 = await this.device.common.status({ opaque })
console.log(statis2)

await delayMs(100)

const data = await this.device.i2c.readGetData({ opaque })
console.log('readI2cBlock - get data', data)
//if(data.status !== 'success') { throw new Error('not successfull readData') }
// if(data.status !== 'success') { throw new Error('not successful readData') }

const { buffer, readBackBytes, validData } = data

if (!validData) {
if(!validData) {
console.log('invalid data', validData)
return {
bytesRead: -1,
Expand Down Expand Up @@ -104,8 +104,8 @@ export class I2CBusMCP2221 implements I2CBus {
// if (status !== 'success') { throw new Error('write cmd failed') }
// console.log('writeI2cBlock - write command', cmd)

const { status: status2 } = await this.device.i2c.writeData({ opaque, address, buffer: Uint8Array.from([ cmd, ...userData ]) })
if (status2 !== 'success') { throw new Error('write failed') }
const { status: status2 } = await this.device.i2c.writeData({ opaque, address, buffer: Uint8Array.from([cmd, ...userData]) })
if(status2 !== 'success') { throw new Error('write failed') }


const foo = await this.device.common.status({ opaque })
Expand Down Expand Up @@ -151,8 +151,8 @@ export class I2CBusMCP2221 implements I2CBus {

const res = await this.device.i2c.writeData({ opaque, address, buffer: bufferSource })

if(res.statusCode != 0) {
console.log({ code: res.statusCode, state: res.i2cState})
if(res.statusCode !== 0) {
console.log({ code: res.statusCode, state: res.i2cState })
throw new Error('write data no good')
}

Expand Down
24 changes: 12 additions & 12 deletions test/i2c-bus.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import { I2CBusMCP2221 } from '@johntalton/i2c-bus-mcp2221'


describe('I2CBusMCP2221', () => {
it('should', async () => {
const binding = {
read: byteLength => console.log({ byteLength }),
write: bufferSource => console.log({ bufferSource })
}
it('should', async () => {
const binding = {
read: byteLength => console.log({ byteLength }),
write: bufferSource => console.log({ bufferSource })
}

const device = MCP2221A.from(binding)
const bus /* {I2CBus} */ = I2CBusMCP2221.from(device)
const device = MCP2221A.from(binding)
const bus /* {I2CBus} */ = I2CBusMCP2221.from(device)

const address = 0x77
const cmd = 0x00
const buffer = new Uint8Array(1)
const result = await bus.readI2cBlock(address, cmd, buffer.byteLength, buffer)
const address = 0x77
const cmd = 0x00
const buffer = new Uint8Array(1)
const result = await bus.readI2cBlock(address, cmd, buffer.byteLength, buffer)

})
})
})
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"alwaysStrict": true,

"incremental": true,
"watch": false,

"target": "ESNext",
"module": "ESNext",
Expand Down

0 comments on commit 665a9fb

Please sign in to comment.