app_example.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <stdio.h>
  2. #include "flipper.h"
  3. #include "debug.h"
  4. void furi_widget(void* param);
  5. void furi_test_app(void* param);
  6. void furi_next_test_app(void* param);
  7. /*
  8. widget simply print ping message
  9. */
  10. void furi_widget(void* param) {
  11. FILE* debug_uart = get_debug();
  12. fprintf(debug_uart, "start furi widget: %s\n", (char*)param);
  13. while(1) {
  14. fprintf(debug_uart, "furi widget\n");
  15. delay(10);
  16. }
  17. }
  18. /*
  19. it simply start, then start child widget, wait about 1 sec (with ping evey 200 ms),
  20. kill the widget, continue with 500 ms ping.
  21. */
  22. void furi_test_app(void* param) {
  23. uint8_t cnt = 0;
  24. while(1) {
  25. fprintf(debug_uart, "furi test app %d\n", cnt);
  26. delay(10);
  27. if(cnt == 2) {
  28. fprintf(debug_uart, "go to next app\n");
  29. furiac_switch(furi_next_test_app, "next_test", NULL);
  30. fprintf(debug_uart, "unsuccessful switch\n");
  31. while(1) {
  32. delay(1000);
  33. }
  34. }
  35. cnt++;
  36. }
  37. }
  38. void furi_next_test_app(void* param) {
  39. FILE* debug_uart = get_debug();
  40. fprintf(debug_uart, "start next test app\n");
  41. delay(10);
  42. fprintf(debug_uart, "exit next app\n");
  43. furiac_exit(NULL);
  44. while(1) {
  45. // this code must not be called
  46. fprintf(debug_uart, "next app: something went wrong\n");
  47. delay(10);
  48. }
  49. }
  50. /*
  51. FILE* debug_uart = get_debug();
  52. fprintf(debug_uart, "hello Flipper!\n");
  53. GpioPin red_led = {LED_RED_GPIO_Port, LED_RED_Pin};
  54. app_gpio_init(red_led, GpioModeOutput);
  55. while(1) {
  56. delay(100);
  57. app_gpio_write(red_led, true);
  58. delay(100);
  59. app_gpio_write(red_led, false);
  60. }
  61. */