#include "pico/stdlib.h"
#include <stdio.h>
#include "tinyexpr.h"
#include <u8g2.h>
#include "u8g2_pico.h"

void print_display(u8g2_t* u8g2, char* msg) {
  u8g2_ClearBuffer(u8g2);
  u8g2_ClearDisplay(u8g2);
  u8g2_SetFont(u8g2, u8g2_font_t0_11_te);
  u8g2_DrawStr(u8g2, (132/2)-8, (32/2)+4, msg);
  u8g2_UpdateDisplay(u8g2);
  puts(msg);
}

static inline void setup_display(u8g2_t* u8g2) {
  u8g2_Setup_st7565_ea_dogm132_f(u8g2, U8G2_R0, u8x8_byte_pico_hw_spi, u8x8_gpio_and_delay_pico);
  u8g2_InitDisplay(&u8g2); // send init sequence to the display, display is in sleep mode after this,
  u8g2_SetPowerSave(&u8g2, 0);
}

int main() {
  u8g2_t u8g2;
  setup_display(&u8g2);
  stdio_init_all();

  for(int i = 0; ; i++) {
    if (i % 2 == 0) {
      print_display(&u8g2, "Foo");
    } else {
      print_display(&u8g2, "Bar");
    }
    sleep_ms(1000);
  }

  return 0;
}
