@typecad/hal 1.0.0-alpha.12 → 1.0.0-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/gpio.d.ts CHANGED
@@ -7,6 +7,19 @@ export declare class OutputPin {
7
7
  low(): void;
8
8
  toggle(): void;
9
9
  write(value: number | boolean): void;
10
+ /**
11
+ * Returns the level the program last drove onto this output pin.
12
+ *
13
+ * The transpiler tracks every write (high/low/write/toggle and the
14
+ * asOutput initial value) and lowers this to a compile-time constant
15
+ * when the state is statically known, or to a tracked shadow variable
16
+ * the generated writes keep updated. No hardware pin read is performed —
17
+ * reading back an OUTPUT-only pin is not portable (e.g. Zephyr), so this
18
+ * reports software truth, not electrical truth.
19
+ */
20
+ read(): boolean;
21
+ isHigh(): boolean;
22
+ isLow(): boolean;
10
23
  pulse(durationMs: number): void;
11
24
  tone(frequency: number): ToneChain;
12
25
  toneFor(frequency: number, duration: number): void;
package/dist/gpio.js CHANGED
@@ -19,6 +19,25 @@ export class OutputPin {
19
19
  write(value) {
20
20
  gpioWrite(this._pin, value);
21
21
  }
22
+ /**
23
+ * Returns the level the program last drove onto this output pin.
24
+ *
25
+ * The transpiler tracks every write (high/low/write/toggle and the
26
+ * asOutput initial value) and lowers this to a compile-time constant
27
+ * when the state is statically known, or to a tracked shadow variable
28
+ * the generated writes keep updated. No hardware pin read is performed —
29
+ * reading back an OUTPUT-only pin is not portable (e.g. Zephyr), so this
30
+ * reports software truth, not electrical truth.
31
+ */
32
+ read() {
33
+ return gpioRead(this._pin);
34
+ }
35
+ isHigh() {
36
+ return this.read();
37
+ }
38
+ isLow() {
39
+ return !this.read();
40
+ }
22
41
  pulse(durationMs) {
23
42
  gpioWrite(this._pin, 1);
24
43
  rawCpp(`delay(${durationMs});`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typecad/hal",
3
- "version": "1.0.0-alpha.12",
3
+ "version": "1.0.0-alpha.13",
4
4
  "description": "TypeCAD hardware abstraction layer — GPIO, I2C, SPI, UART as regular TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -50,9 +50,9 @@
50
50
  },
51
51
  "author": "typecad0",
52
52
  "devDependencies": {
53
- "@typecad/expect": "1.0.0-alpha.12",
54
- "@typecad/board-arduino-uno": "1.0.0-alpha.12",
55
- "@typecad/mcu-atmega328p": "1.0.0-alpha.12"
53
+ "@typecad/expect": "1.0.0-alpha.13",
54
+ "@typecad/board-arduino-uno": "1.0.0-alpha.13",
55
+ "@typecad/mcu-atmega328p": "1.0.0-alpha.13"
56
56
  },
57
57
  "sideEffects": false,
58
58
  "exports": {
package/src/gpio.ts CHANGED
@@ -29,6 +29,28 @@ export class OutputPin {
29
29
  gpioWrite(this._pin, value);
30
30
  }
31
31
 
32
+ /**
33
+ * Returns the level the program last drove onto this output pin.
34
+ *
35
+ * The transpiler tracks every write (high/low/write/toggle and the
36
+ * asOutput initial value) and lowers this to a compile-time constant
37
+ * when the state is statically known, or to a tracked shadow variable
38
+ * the generated writes keep updated. No hardware pin read is performed —
39
+ * reading back an OUTPUT-only pin is not portable (e.g. Zephyr), so this
40
+ * reports software truth, not electrical truth.
41
+ */
42
+ read(): boolean {
43
+ return gpioRead(this._pin) as unknown as boolean;
44
+ }
45
+
46
+ isHigh(): boolean {
47
+ return this.read();
48
+ }
49
+
50
+ isLow(): boolean {
51
+ return !this.read();
52
+ }
53
+
32
54
  pulse(durationMs: number): void {
33
55
  gpioWrite(this._pin, 1);
34
56
  rawCpp(`delay(${durationMs});`);