Skip to content

Commit cbe69af

Browse files
committed
feat: adds card APIs for dfu, illumination, io and led
1 parent aadeeb2 commit cbe69af

3 files changed

Lines changed: 150 additions & 4 deletions

File tree

API.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
| `card.binary.put` | card.binaryPut |
1515
| `card.carrier` | card.carrier |
1616
| `card.contact` | card.contact |
17-
| `card.dfu` | NOT IMPLEMENTED |
18-
| `card.illumination` | NOT IMPLEMENTED |
19-
| `card.io` | NOT IMPLEMENTED |
20-
| `card.led` | NOT IMPLEMENTED |
17+
| `card.dfu` | card.dfu |
18+
| `card.illumination` | card.illumination |
19+
| `card.io` | card.io |
20+
| `card.led` | card.led |
2121
| `card.location` | card.location |
2222
| `card.location.mode` | card.locationMode |
2323
| `card.location.track` | card.locationTrack |

notecard/card.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,3 +541,114 @@ def auxSerial(card, mode=None, duration=None, rate=None, limit=None, max=None, m
541541
if minutes:
542542
req["minutes"] = minutes
543543
return card.Transaction(req)
544+
545+
546+
@validate_card_object
547+
def dfu(card, name=None, on=None, off=None, seconds=None, stop=None, start=None, mode=None):
548+
"""Configure a Notecard for Notecard Outboard Firmware Update.
549+
550+
Args:
551+
card (Notecard): The current Notecard object.
552+
name (string): One of the supported classes of host MCU. Supported MCU classes are
553+
'esp32', 'stm32', 'stm32-bi', 'mcuboot', '-'.
554+
on (bool): Set to True to enable Notecard Outboard Firmware Update.
555+
off (bool): Set to True to disable Notecard Outboard Firmware Update from occurring.
556+
seconds (int): When used with 'off':True, disable Notecard Outboard Firmware Update
557+
operations for the specified number of seconds.
558+
stop (bool): Set to True to disable the host RESET that is normally performed on the
559+
host MCU when the Notecard starts up.
560+
start (bool): Set to True to enable the host RESET.
561+
mode (string): Optional mode for alternative DFU configuration.
562+
563+
Returns:
564+
dict: The result of the Notecard request containing:
565+
"name": Current MCU class configured for DFU
566+
"""
567+
req = {"req": "card.dfu"}
568+
if name:
569+
req["name"] = name
570+
if on is not None:
571+
req["on"] = on
572+
if off is not None:
573+
req["off"] = off
574+
if seconds:
575+
req["seconds"] = seconds
576+
if stop is not None:
577+
req["stop"] = stop
578+
if start is not None:
579+
req["start"] = start
580+
if mode:
581+
req["mode"] = mode
582+
return card.Transaction(req)
583+
584+
585+
@validate_card_object
586+
def illumination(card):
587+
"""Retrieve an illumination reading from an OPT3001 ambient light sensor connected to Notecard's I2C bus.
588+
589+
Args:
590+
card (Notecard): The current Notecard object.
591+
592+
Returns:
593+
dict: The result of the Notecard request containing:
594+
"value": An illumination reading (in lux) from the attached OPT3001 sensor.
595+
596+
Note:
597+
If no OPT3001 sensor is detected, this request returns an "illumination sensor is not available" error.
598+
"""
599+
req = {"req": "card.illumination"}
600+
return card.Transaction(req)
601+
602+
603+
@validate_card_object
604+
def io(card, i2c=None, mode=None):
605+
"""Override the Notecard's I2C address and change behaviors of the onboard LED and USB port.
606+
607+
Args:
608+
card (Notecard): The current Notecard object.
609+
i2c (int): The alternate address to use for I2C communication. Pass -1 to reset to the default address.
610+
mode (string): Mode to change LED or USB behavior. Options include:
611+
"-usb" - Disable the Notecard's USB port. Re-enable with "usb" or "+usb"
612+
"+busy" - LED will be on when Notecard is awake, off when asleep
613+
"-busy" - Reset "+busy" to default (LED blinks only during flash operations)
614+
"i2c-master-disable" - Disable Notecard acting as an I2C master
615+
"i2c-master-enable" - Re-enable I2C master functionality
616+
617+
Returns:
618+
dict: The result of the Notecard request.
619+
"""
620+
req = {"req": "card.io"}
621+
if i2c is not None:
622+
req["i2c"] = i2c
623+
if mode:
624+
req["mode"] = mode
625+
return card.Transaction(req)
626+
627+
628+
@validate_card_object
629+
def led(card, mode=None, on=None, off=None):
630+
"""Control connected LEDs or manage a single connected NeoPixel.
631+
632+
Args:
633+
card (Notecard): The current Notecard object.
634+
mode (string): Used to specify the color of the LED or NeoPixel to control.
635+
For LEDs: 'red', 'green', 'yellow'
636+
For NeoPixels: 'red', 'green', 'blue', 'yellow', 'cyan', 'magenta', 'orange', 'white', 'gray'
637+
on (bool): Set to True to turn the specified LED or NeoPixel on.
638+
off (bool): Set to True to turn the specified LED or NeoPixel off.
639+
640+
Returns:
641+
dict: The result of the Notecard request.
642+
643+
Note:
644+
Requires the card.aux API to be configured in 'led' or 'neo' mode first.
645+
Not supported by Notecard LoRa for regular LEDs.
646+
"""
647+
req = {"req": "card.led"}
648+
if mode:
649+
req["mode"] = mode
650+
if on is not None:
651+
req["on"] = on
652+
if off is not None:
653+
req["off"] = off
654+
return card.Transaction(req)

test/fluent_api/test_card.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,41 @@
174174
'ms': 500,
175175
'minutes': 5
176176
}
177+
),
178+
(
179+
card.dfu,
180+
'card.dfu',
181+
{
182+
'name': 'esp32',
183+
'on': True,
184+
'off': False,
185+
'seconds': 300,
186+
'stop': True,
187+
'start': False,
188+
'mode': 'secure'
189+
}
190+
),
191+
(
192+
card.illumination,
193+
'card.illumination',
194+
{}
195+
),
196+
(
197+
card.io,
198+
'card.io',
199+
{
200+
'i2c': 24,
201+
'mode': '+busy'
202+
}
203+
),
204+
(
205+
card.led,
206+
'card.led',
207+
{
208+
'mode': 'red',
209+
'on': True,
210+
'off': False
211+
}
177212
)
178213
]
179214
)

0 commit comments

Comments
 (0)