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

pybricks / pybricks-micropython / 19016791193

02 Nov 2025 06:40PM UTC coverage: 57.167% (-2.6%) from 59.744%
19016791193

Pull #406

github

laurensvalk
bricks/virtualhub: Replace with embedded simulation.

Instead of using the newly introduced simhub alongside the virtualhub, we'll just replace the old one entirely now that it has reached feature parity. We can keep calling it the virtualhub.
Pull Request #406: New virtual hub for more effective debugging

41 of 48 new or added lines in 7 files covered. (85.42%)

414 existing lines in 53 files now uncovered.

4479 of 7835 relevant lines covered (57.17%)

17178392.75 hits per line

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

95.83
/lib/pbio/src/main.c
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) 2018-2021 The Pybricks Authors
3

4
/**
5
 * @addtogroup Main Library initialization and events
6
 * @{
7
 */
8

9
#include <stdbool.h>
10

11
#include <pbdrv/bluetooth.h>
12
#include <pbdrv/display.h>
13
#include <pbdrv/sound.h>
14

15
#include <pbio/battery.h>
16
#include <pbio/image.h>
17
#include <pbio/imu.h>
18
#include <pbio/light_animation.h>
19
#include <pbio/motor_process.h>
20
#include <pbio/port_interface.h>
21

22
/**
23
 * Initialize the Pybricks I/O Library. This function must be called once,
24
 * usually at the beginning of a program, before using any other functions in
25
 * the library.
26
 *
27
 * @param [in]  start_processes  Whether to start all user-level background
28
 *                               processes. This is always enabled, except in
29
 *                               tests that test one driver at a time.
30
 */
31
void pbio_init(bool start_processes) {
42✔
32

33
    pbio_battery_init();
42✔
34
    pbio_imu_init();
42✔
35

36
    if (!start_processes) {
42✔
37
        return;
6✔
38
    }
39

40
    // This will also initialize the dcmotor and servo pbio object instances.
41
    pbio_port_init();
36✔
42

43
    // Can the motor process after ports initialized above.
44
    pbio_motor_process_start();
36✔
45
}
46

47
/**
48
 * Deinitialize pbio modules that are not needed after soft-poweroff.
49
 */
50
void pbio_deinit(void) {
26✔
51
    // Power off sensors and motors, including the ones that are always powered.
52
    pbio_port_power_off();
26✔
53
}
26✔
54

55
/**
56
 * Stops resources like motors or sounds or peripheral procedures that take a
57
 * long time.
58
 *
59
 * Useful to get the system in a safe state for the user without doing a full
60
 * reset. Applications can all this to enter a user debug mode like the
61
 * MicroPython REPL.
62
 */
63
void pbio_main_soft_stop(void) {
25✔
64

65
    pbio_port_stop_user_actions(false);
25✔
66

67
    pbdrv_sound_stop();
25✔
68

69
    pbdrv_bluetooth_cancel_operation_request();
25✔
70
}
25✔
71

72
/**
73
 * Stops all application-level background processes. Called when the user
74
 * application completes to get these modules back into their default state.
75
 * Drivers and OS-level processes continue running.
76
 *
77
 * @return   ::PBIO_SUCCESS when completed
78
 *           ::PBIO_ERROR_TIMEDOUT if it could not stop processes in a reasonable
79
 *             amount of time.
80
 */
81
pbio_error_t pbio_main_stop_application_resources(void) {
25✔
82

83
    pbio_port_stop_user_actions(true);
25✔
84
    pbio_main_soft_stop();
25✔
85

86
    pbio_error_t err;
87
    pbio_os_state_t state = 0;
25✔
88
    pbio_os_timer_t timer;
89
    pbio_os_timer_set(&timer, 5000);
25✔
90

91
    // Run event loop until Bluetooth is idle or times out.
92
    while ((err = pbdrv_bluetooth_close_user_tasks(&state, &timer)) == PBIO_ERROR_AGAIN) {
25✔
UNCOV
93
        pbio_os_run_processes_and_wait_for_event();
×
94
    }
95

96
    #if PBIO_CONFIG_LIGHT
97
    pbio_light_animation_stop_all();
98
    #endif
99

100
    #if PBDRV_CONFIG_DISPLAY
101
    pbio_image_fill(pbdrv_display_get_image(), 0);
102
    pbdrv_display_update();
103
    #endif
104

105
    pbio_os_run_processes_and_wait_for_event();
25✔
106

107
    return err;
25✔
108
}
109

110
/** @} */
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

© 2026 Coveralls, Inc