Example #1
0
def handle_screen_show_value(runtime: Runtime, block: Block,
                             branch: Branch) -> None:
    name = evaluate_value(block.values["name"])
    line = evaluate_value(block.values["line"])
    text = evaluate_value(block.values["text"])
    runtime.globals["brick"].clear_screen(line=line)
    runtime.globals["brick"].print("{}={}".format(name, text), line=line)
Example #2
0
def handle_motor_schedule(runtime: Runtime, block: Block,
                          branch: Branch) -> None:
    motor_label = block.fields["motor"].value
    unit = block.fields["unit"].value
    speed = evaluate_value(block.values["speed"])
    value = evaluate_value(block.values["value"])
    for port, type in parse_motor_label(motor_label):
        runtime.globals["brick"].get_motor(port, type).set_schedule(
            unit, speed, value)
Example #3
0
def handle_control_wait_us(runtime: Runtime, block: Block,
                           branch: Branch) -> None:
    #  {'type': 'control_wait_us', 'values': {'micros': BlockValue(name='micros', shadow=BlockShadow(type='math_number', fields={'NUM': BlockField(name='NUM', id=None, variable_type=None, value='4')}))}, 'fields': {}, 'statements': {}}
    us = evaluate_value(block.values["micros"])
    # TODO: Actually implement lock
    branch.lock = Event(event="interrupt", parameters={})
    log.debug("Sleeping for {}μs".format(us))
def handle_colorpause_until_color_detected_detected(runtime: Runtime,
                                                    block: Block,
                                                    branch: Branch) -> None:
    color = evaluate_value(block.values["color"])
    sensor = block.fields["this"].value
    branch.lock = Event(event="colorOnColorDetected",
                        parameters={
                            "color": color,
                            "sensor": sensor
                        })
    log.debug("Locking branch, waiting for event {}".format(branch.lock))
Example #5
0
def handle_console_log_value(runtime: Runtime, block: Block, branch: Branch) -> None:
    name = evaluate_value(block.values["name"])
    value = evaluate_value(block.values["value"])
    log.debug("Logging value {}={}".format(name, value))
    print("{}={}".format(name, value))
Example #6
0
def handle_device_pause(runtime: Runtime, block: Block,
                        branch: Branch) -> None:
    ms = evaluate_value(block.values["pause"])
    # TODO: Actually implement lock
    branch.lock = Event(event="interrupt", parameters={})
    log.debug("Sleeping for {}ms".format(ms))
Example #7
0
def handle_screen_print(runtime: Runtime, block: Block,
                        branch: Branch) -> None:
    text = evaluate_value(block.values["text"])
    line = evaluate_value(block.values["line"])
    runtime.globals["brick"].clear_screen(line=line)
    runtime.globals["brick"].print(text, line=line)
Example #8
0
def handle_screen_show_image(runtime: Runtime, block: Block,
                             branch: Branch) -> None:
    image = evaluate_value(block.values["image"])
    log.debug("Showing image {}".format(image))
Example #9
0
def handle_set_lights(runtime: Runtime, block: Block, branch: Branch) -> None:
    pattern = evaluate_value(block.values["pattern"])
    runtime.globals["brick"].set_status_light_pattern(
        StatusLightPattern(pattern))
Example #10
0
def handle_motor_run(runtime: Runtime, block: Block, branch: Branch) -> None:
    motor_label = block.fields["motor"].value
    speed = evaluate_value(block.values["speed"])
    for port, type in parse_motor_label(motor_label):
        runtime.globals["brick"].get_motor(port, type).set_speed(speed)
def handle_variables_set(runtime: Runtime, block: Block,
                         branch: Branch) -> None:
    id = block.fields["VAR"].id
    value = evaluate_value(block.values["VALUE"])
    log.debug("Setting variable '{}' to '{}'".format(id, value))
    runtime.set_variable(id, value)