Skip to content

Commit

Permalink
Param: add persistent_clear method
Browse files Browse the repository at this point in the history
Clear the current value of the specified persistent parameter from
eeprom. The supplied callback will be called with `True` as an
argument on success, and with `False` as an argument on failure.
  • Loading branch information
jonasdn committed Nov 12, 2021
1 parent fc22c12 commit 8763d3e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cflib/crazyflie/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@

MISC_PERSISTENT_STORE = 3
MISC_PERSISTENT_GET_STATE = 4
MISC_PERSISTENT_CLEAR = 5

# One element entry in the TOC

Expand Down Expand Up @@ -357,6 +358,27 @@ def get_value(self, complete_name, timeout=60):
[group, name] = complete_name.split('.')
return self.values[group][name]

def persistent_clear(self, complete_name, callback=None):
"""
Clear the current value of the specified persistent parameter from
eeprom. The supplied callback will be called with `True` as an
argument on success and with `False` as an argument on failure.
@param complete_name The 'group.name' name of the parameter to store
@param callback Optional callback should take boolean status as arg
"""
element = self.toc.get_element_by_complete_name(complete_name)

def new_packet_cb(pk):
if pk.channel == MISC_CHANNEL and pk.data[0] == MISC_PERSISTENT_CLEAR:
callback(pk.data[3] == 0)

self.cf.add_port_callback(CRTPPort.PARAM, new_packet_cb)
pk = CRTPPacket()
pk.set_header(CRTPPort.PARAM, MISC_CHANNEL)
pk.data = struct.pack('<BH', MISC_PERSISTENT_CLEAR, element.ident)
self.cf.send_packet(pk, expected_reply=(tuple(pk.data[:3])))

def persistent_store(self, complete_name, callback=None):
"""
Store the current value of the specified persistent parameter to
Expand Down

0 comments on commit 8763d3e

Please sign in to comment.