Skip to content

Commit 1b38088

Browse files
committed
updated smplaes
1 parent 352bbe9 commit 1b38088

3 files changed

Lines changed: 51 additions & 18 deletions

File tree

README.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,50 @@ This library uses the [serial-to-i2c bridge](// https://dev.blues.io/guides-and-
77

88
** This library has a minimal surface and most messages have not been mapped to types. See [Notecard API](https://dev.blues.io/api-reference/notecard-api/introduction/) for a full list. **
99

10-
## Usage
10+
## Setup
1111

12-
Add the library to your project:
12+
Add the library to your DeviceScript project:
1313

1414
```bash
1515
npm install --save pelikhan/devicescript-note
1616
```
1717

18-
## [Contributing](./CONTRIBUTING.md)
18+
## Configuration
19+
20+
Add the notehub product UID into your settings.
21+
22+
```yaml
23+
# .env.defaults
24+
NOTE_PUID=your-product-uid
25+
```
26+
27+
By default, DeviceScript will use the deviceid as a serial number; but you can override this setting.
28+
29+
```yaml
30+
# .env.defaults
31+
NOTE_PUID=your-product-uid
32+
NOTE_SN=your-serial-number
33+
```
34+
35+
## Usage
36+
37+
- Connect the notecard to your I2C pins and power it up.
38+
- Start by calling `init` for the initial handshake with the notecard.
39+
40+
```ts
41+
import { delay, millis } from "@devicescript/core"
42+
import { init, request } from "devicescript-note"
43+
44+
// configure product UID and serial number
45+
await init()
46+
47+
while (true) {
48+
// send node.add request
49+
const res = await request({ req: "note.add", body: { time: millis() } })
50+
console.log(res)
51+
// take a break
52+
await delay(10000)
53+
}
54+
```
55+
56+
## [Contributing](./CONTRIBUTING.md)

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { I2CError, i2c } from "@devicescript/i2c"
44
import { readSetting } from "@devicescript/settings"
55

66
function debug(msg: string) {
7-
console.debug(`notes> ` + msg)
7+
//console.debug(`notes> ` + msg)
88
}
99

1010
/**

src/main.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
import { pins, board } from "@dsboard/adafruit_qt_py_c3"
2-
import { delay } from "@devicescript/core"
3-
import { HubLogRequest, NoteAddRequest, init, request } from "."
1+
import { delay, millis } from "@devicescript/core"
2+
import { init, request } from "."
43

5-
await init({ mode: "continuous", sync: true })
4+
// configure product UID and serial number
5+
await init()
66

7-
let i = 0
87
while (true) {
9-
await delay(5000)
10-
await request<HubLogRequest>({ req: "hub.log", text: "counter: " + i })
11-
await request(<NoteAddRequest>{
12-
req: "note.add",
13-
body: {
14-
i,
15-
},
16-
})
17-
console.log(await request({ req: "hub.status" }))
8+
// send node.add request
9+
const res = await request({ req: "note.add", body: { time: millis() } })
10+
console.log(res)
11+
// take a break
12+
await delay(10000)
1813
}

0 commit comments

Comments
 (0)