Skip to content

Commit

Permalink
Merge pull request #6 from Skyler84:standalone
Browse files Browse the repository at this point in the history
Standalone
  • Loading branch information
Skyler84 authored Aug 21, 2023
2 parents 2b12f05 + 16808ae commit ee96139
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function(add_simple_example NAME)
target_link_libraries(${filename}_example PRIVATE gui)
add_executable(${filename}_example_app main.cpp)
target_compile_definitions(${filename}_example_app PRIVATE CLASSNAME=${NAME}View INCLUDE="examples/${filename}_view.hpp")
target_link_libraries(${filename}_example_app PRIVATE gui ${filename}_example)
target_link_libraries(${filename}_example_app PRIVATE gui ${filename}_example pico_bootrom)
if(NOT ${filename} STREQUAL all)
target_link_libraries(all_example PUBLIC ${filename}_example)
endif()
Expand Down
19 changes: 12 additions & 7 deletions examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "pico/stdio.h"
#include "hardware/watchdog.h"
#include "pico/time.h"
#include "pico/bootrom.h"

#include "drivers/button.hpp"
#include "buttons.hpp"
Expand All @@ -23,28 +24,32 @@ MyButton buttons[4] = {

extern "C" bool tud_connected();

void wait_stdio_usb_connected_timeout(long timeout_ms){
void wait_stdio_usb_connected_timeout(long timeout_ms, long startup_delay_ms){
if(!tud_connected())
return;
absolute_time_t timeout = make_timeout_time_ms(timeout_ms);

while(!stdio_usb_connected() && absolute_time_diff_us(get_absolute_time(), timeout) > 0){
watchdog_update();
}
if(stdio_usb_connected)
sleep_ms(1000);
timeout = make_timeout_time_ms(startup_delay_ms);
while(stdio_usb_connected() && absolute_time_diff_us(get_absolute_time(), timeout) > 0){
watchdog_update();
}
}

int main(){

stdio_init_all();

wait_stdio_usb_connected_timeout(2500);

while(!(tud_connected() && stdio_usb_connected())){
watchdog_update();
if(watchdog_enable_caused_reboot()) {
reset_usb_boot(0,0);
}

watchdog_enable(200, 1);

wait_stdio_usb_connected_timeout(2500, 500);

MyButton::init_all();
auto &controller = ViewController::get();
CLASSNAME v{nullptr};
Expand Down

0 comments on commit ee96139

Please sign in to comment.