• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pybricks / pybricks-micropython / 6675885095

28 Oct 2023 08:38AM UTC coverage: 56.053% (+10.0%) from 46.074%
6675885095

push

github

laurensvalk
pybricks.hubs.MoveHub: Use standard hub init.

The Move Hub cannot have true vector axes, but we can still use this API to initialize the hub using numeric indices.

This ensures we can use the custom orientation not just in tilt, but also in acceleration like we do on other hubs.

3616 of 6451 relevant lines covered (56.05%)

20895680.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.94
/lib/pbio/sys/command.c
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) 2022-2023 The Pybricks Authors
3

4
#include <assert.h>
5
#include <stdint.h>
6

7
#include <pbdrv/reset.h>
8
#include <pbio/protocol.h>
9

10
#include "./bluetooth.h"
11
#include "./program_load.h"
12
#include "./program_stop.h"
13

14
/**
15
 * Parses binary data for command and dispatches handler for command.
16
 * @param [in]  data    The raw command data.
17
 * @param [in]  size    The size of @p data in bytes.
18
 */
19
pbio_pybricks_error_t pbsys_command(const uint8_t *data, uint32_t size) {
1✔
20
    assert(data);
1✔
21
    assert(size);
1✔
22

23
    pbio_pybricks_command_t cmd = data[0];
1✔
24

25
    switch (cmd) {
1✔
26
        case PBIO_PYBRICKS_COMMAND_STOP_USER_PROGRAM:
27
            pbsys_program_stop(false);
28
            return PBIO_PYBRICKS_ERROR_OK;
29
        case PBIO_PYBRICKS_COMMAND_START_USER_PROGRAM:
30
            return pbio_pybricks_error_from_pbio_error(pbsys_program_load_start_user_program());
×
31
        case PBIO_PYBRICKS_COMMAND_START_REPL:
32
            return pbio_pybricks_error_from_pbio_error(pbsys_program_load_start_repl());
×
33
        case PBIO_PYBRICKS_COMMAND_WRITE_USER_PROGRAM_META:
×
34
            return pbio_pybricks_error_from_pbio_error(pbsys_program_load_set_program_size(
×
35
                pbio_get_uint32_le(&data[1])));
36
        case PBIO_PYBRICKS_COMMAND_WRITE_USER_RAM:
×
37
            return pbio_pybricks_error_from_pbio_error(pbsys_program_load_set_program_data(
×
38
                pbio_get_uint32_le(&data[1]), &data[5], size - 5));
39
        case PBIO_PYBRICKS_COMMAND_REBOOT_TO_UPDATE_MODE:
40
            pbdrv_reset(PBDRV_RESET_ACTION_RESET_IN_UPDATE_MODE);
41
            return PBIO_PYBRICKS_ERROR_OK;
42
        case PBIO_PYBRICKS_COMMAND_WRITE_STDIN:
1✔
43
            #if PBSYS_CONFIG_BLUETOOTH
44
            if (pbsys_bluetooth_rx_get_free() < size - 1) {
1✔
45
                return PBIO_PYBRICKS_ERROR_BUSY;
46
            }
47
            pbsys_bluetooth_rx_write(&data[1], size - 1);
1✔
48
            #endif
49
            // If no consumers are configured, goes to "/dev/null" without error
50
            return PBIO_PYBRICKS_ERROR_OK;
1✔
51
        default:
×
52
            return PBIO_PYBRICKS_ERROR_INVALID_COMMAND;
×
53
    }
54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc