#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"

#include "ssd1306.h"
#include "font8x8_basic.h"

#define TAG "SSD1306"

#define poulet_width 32
#define poulet_height 32
uint8_t poulet_bits[] = {
    0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x7f, 0xff, 0xff, 0xfa, 0x4f, 0xff, 0xff, 0xe3, 0x0f, 0xff, 
	0xff, 0xc3, 0xe7, 0xff, 0xff, 0xdf, 0xe1, 0xff, 0xff, 0xcf, 0xf1, 0xff, 0xff, 0x8f, 0xf9, 0xff, 
	0xfe, 0x04, 0x38, 0x7f, 0xfe, 0x31, 0x00, 0x7f, 0xfe, 0x0c, 0xc1, 0xff, 0xff, 0x9e, 0x4c, 0x7f, 
	0xff, 0x9e, 0x66, 0x3f, 0xff, 0x31, 0x36, 0x3f, 0xfe, 0x31, 0xb3, 0x3f, 0xfe, 0x31, 0x98, 0x7f, 
	0xfc, 0x11, 0x99, 0xff, 0xf8, 0x0f, 0xd9, 0xff, 0xf0, 0x07, 0xdc, 0xff, 0xfc, 0x03, 0xcd, 0xbf, 
	0xfc, 0x0b, 0xcd, 0xbf, 0xfc, 0x19, 0xcd, 0xbf, 0xfc, 0x09, 0xcf, 0x3f, 0xf8, 0x01, 0xce, 0x3f, 
	0xfc, 0x23, 0xcc, 0x7f, 0xfc, 0x7f, 0xd9, 0x9f, 0xfc, 0x3f, 0x93, 0x9f, 0xfc, 0x0f, 0x26, 0x3f, 
	0xfe, 0x66, 0x0c, 0x7f, 0xff, 0x30, 0x99, 0xff, 0xff, 0xf3, 0xa3, 0xff, 0xff, 0xff, 0xaf, 0xff
};
void app_main(void)
{
	SSD1306_t dev;

	ESP_LOGI(TAG, "INTERFACE is i2c");
	ESP_LOGI(TAG, "CONFIG_SDA_GPIO=%d",CONFIG_SDA_GPIO);
	ESP_LOGI(TAG, "CONFIG_SCL_GPIO=%d",CONFIG_SCL_GPIO);
	ESP_LOGI(TAG, "CONFIG_RESET_GPIO=%d",CONFIG_RESET_GPIO);
	i2c_master_init(&dev, CONFIG_SDA_GPIO, CONFIG_SCL_GPIO, CONFIG_RESET_GPIO);

	ESP_LOGI(TAG, "Panel is 128x32");
	ssd1306_init(&dev, 128, 32);

	ssd1306_contrast(&dev, 0xff);
	while(1) {
		ssd1306_clear_screen(&dev, false);
		ssd1306_display_text(&dev, 1, "Hubert", 6, false);
		ssd1306_display_text(&dev, 2, "Hackin''", 8, false);
		ssd1306_bitmaps(&dev, 127-32, 0, poulet_bits, 32, 32, true);

		vTaskDelay(5000 / portTICK_PERIOD_MS);

		ssd1306_clear_screen(&dev, false);
		ssd1306_display_text(&dev, 0, "Social Level xFF", 16, false);
		ssd1306_display_text(&dev, 1, "Animation     -1", 16, false);
		ssd1306_display_text(&dev, 2, "Sponsor      NaN", 16, false);
		vTaskDelay(5000 / portTICK_PERIOD_MS);
	}
}
