pdf-icon

UIFlow Guide

UiFlow1 Blockly

Event

Unit

UiFlow1 Project

Unit ASR

Example

Send Hello voice command, execute Print program

from m5stack import *
from m5ui import *
from uiflow import *
import unit

setScreenColor(0x222222)
asr_0 = unit.get(unit.ASR, unit.PORTC)

def asr_0_hello_event(args):
  # global params
  print('I am Fine')

asr_0.init(2)
asr_0.add_command_word(0x32, 'hello', asr_0_hello_event)
print((str('raw message:') + str((asr_0.get_current_raw_message()))))
while True:
  asr_0.handler()
  wait_ms(2)

API

asr_0.init(2)
  • Initialize Unit
def asr_0_hello_event(args):
  # global params
  pass
  • Callback function triggered when Unit ASR recognizes a command word
print((str('current command handler state:') + str((asr_0.get_command_handler()))))
  • Check if the current command has an associated handler
print((str('current command list:') + str((asr_0.get_command_list()))))
  • Get a list of all commands and their associated handlers
print((str('current command num:') + str((asr_0.get_current_command_num()))))
  • Get the current command number
print((str('current command word:') + str((asr_0.get_current_command_word()))))
  • Get the command word corresponding to the current command number
asr_0.add_command_word(0x32, 'hello', _)
  • Register custom commands and handlers
print((str('current raw message:') + str((asr_0.get_current_raw_message()))))
  • Get the raw message received in hexadecimal format
print((str('receive message:') + str((asr_0.get_received_status()))))
  • Get the message reception status
asr_0.remove_command_word('hello')
  • Remove command words from the command list by word
print((str('command word:') + str((asr_0.search_command_num('')))))
  • Search for the command number associated with a command word
print((str('command word(hex):') + str((asr_0.search_command_word(0x32)))))
  • Search for the command word associated with a command number
asr_0.send_message(0xFE)
  • Send a command via UART
asr_0.handler()
  • Update function
On This Page