oled.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * oled.c
  3. *
  4. * Created on: Jan 12, 2021
  5. * Author: David Original work by Jose (PTDreamer), 2017
  6. */
  7. #include <stdlib.h>
  8. #include "oled.h"
  9. static screen_t *screens = NULL;
  10. static screen_t *current_screen;
  11. static RE_State_t* RE_State;
  12. RE_Rotation_t (*RE_GetData)(RE_State_t*);
  13. RE_Rotation_t RE_Rotation;
  14. void oled_addScreen(screen_t *screen, uint8_t index) {
  15. screen->index = index;
  16. screen->next_screen = NULL;
  17. screen->init = NULL;
  18. screen->draw = NULL;
  19. screen->onExit = NULL;
  20. screen->onEnter = NULL;
  21. screen->processInput = NULL;
  22. screen->widgets = NULL;
  23. screen->current_widget = NULL;
  24. if(screens == NULL) {
  25. screens = screen;
  26. }
  27. else {
  28. screen_t *temp = screens;
  29. while(temp->next_screen) {
  30. temp = temp->next_screen;
  31. }
  32. temp->next_screen = screen;
  33. }
  34. }
  35. void oled_draw() {
  36. #ifndef Soft_SPI
  37. if(oled.status!=oled_idle) { return; } // If Oled busy, skip update
  38. #endif
  39. current_screen->draw(current_screen);
  40. update_display();
  41. }
  42. void oled_update() {
  43. if(current_screen->update)
  44. current_screen->update(current_screen);
  45. oled_draw();
  46. }
  47. void oled_init(RE_Rotation_t (*GetData)(RE_State_t*), RE_State_t *State) {
  48. RE_State = State;
  49. RE_GetData = GetData;
  50. screen_t *scr = screens;
  51. while(scr) {
  52. if(scr->index == 0) {
  53. scr->init(scr);
  54. current_screen = scr;
  55. return;
  56. }
  57. }
  58. }
  59. static RE_State_t* RE_State;
  60. void oled_processInput(void) {
  61. RE_Rotation = (*RE_GetData)(RE_State);
  62. int ret = current_screen->processInput(current_screen, RE_Rotation, RE_State);
  63. if(ret != -1) {
  64. screen_t *scr = screens;
  65. while(scr) {
  66. if(scr->index == ret) {
  67. FillBuffer(BLACK, fill_dma);
  68. scr->refresh=screenRefresh_alreadyErased; // Changed screen, force full display erase using dma
  69. if(current_screen->onExit)
  70. current_screen->onExit(scr);
  71. if(scr->onEnter)
  72. scr->onEnter(current_screen);
  73. scr->init(scr);
  74. if(scr->update)
  75. scr->update(scr);
  76. current_screen = scr;
  77. return;
  78. }
  79. scr = scr->next_screen;
  80. }
  81. }
  82. }
  83. void oled_handle(void){
  84. oled_processInput();
  85. oled_update();
  86. }