
/*
	TIM_SSD1306_I2C.h

	Minimal SSD1306 driver for 128x64 OLED using I2C.
	Arduino/ESP8266 version.
*/

#ifndef __TIM_SSD1306_I2C_H__
#define __TIM_SSD1306_I2C_H__

#include <Arduino.h>
#include <Wire.h>

/*  I2C Configuration  */
#define SSD1306_I2C_ADDR  0x3C    /* Unshifted 7-bit I2C address */

/*  Screen Size  */
#define SSD1306_WIDTH     128
#define SSD1306_HEIGHT    64

/*  Buffer size  */
#define SSD1306_BUFFER_SIZE   (SSD1306_WIDTH * SSD1306_HEIGHT / 8)

/*  Enumeration for screen colors  */
typedef enum {
	Black = 0x00,   /* Pixel Off  */
	White = 0x01    /* Pixel On   */
} SSD1306_COLOR;

/*  Public API  */

/*  Initialize the OLED screen  */
void ssd1306_Init(void);

/*  Set display contrast  */
void ssd1306_SetContrast(uint8_t value);

/*
	Fill the whole screen buffer with the given color.
	Call ssd1306_UpdateScreen() to push to the display.
*/
void ssd1306_FillScreen(SSD1306_COLOR color);

/*
	Update the OLED from the screen buffer.

	Only the bounding rectangle of all "dirty" regions since the last
	update is sent over I2C.
*/
void ssd1306_UpdateScreen(void);

/*
	Draw a single pixel into the screen buffer.

	x, y   = pixel coordinates
	color  = Black or White
*/
void ssd1306_DrawPixel(uint8_t x, uint8_t y, SSD1306_COLOR color);

/*
	Draw a bitmap in your vertical-byte format:

	- Each byte = 8 vertical pixels (bit 0 = top, bit 7 = bottom)
	- Bitmap is stored column-by-column
	- For height h, there are (h / 8) "pages"

	x, y   = top-left pixel position
	w, h   = width and height in pixels (h must be multiple of 8)
*/
void ssd1306_DrawBitmap(uint8_t x, uint8_t y, const uint8_t* bitmap, uint8_t w, uint8_t h);

/*-------------------------------------------------------------
	Public: Draw raw bitmap (full screen)
	-------------------------------------------------------------*/
void ssd1306_DrawSplashRaw(const uint8_t* bitmap);



/*
	Font helpers (same header format you already use):

	font[0] = 0x00 (fixed font type)
	font[1] = width in pixels
	font[2] = height in pixels (multiple of 8)
	font[3] = first ASCII character code
*/

/*
	Print a single character at (x, row), where row is in 8-pixel units.

	x       = column (0..127)
	r       = row index (0..7), each row = 8 vertical pixels
	c       = character to draw
	color   = Black or White
	font    = pointer to font array
*/
void ssd1306_PrintChar(uint8_t x, uint8_t r, char c, SSD1306_COLOR color, const uint8_t* font);

/*
	Print a string starting at (x, row).
*/
uint8_t ssd1306_PrintString(uint8_t x, uint8_t r, const char* str, SSD1306_COLOR color, const uint8_t* font);
/*
	Print a string horizontally centered on the screen in row r.
*/
void ssd1306_PrintStringCentered(uint8_t r, const char* str, SSD1306_COLOR color, const uint8_t* font);

/*
	Print a number (0–255) horizontally centered on the screen in row r.
*/
void ssd1306_PrintNumberCentered(uint8_t r, uint8_t number, SSD1306_COLOR color, const uint8_t* font);

/*
	Integer to string helper (0–255).
*/
void intToStr(uint8_t num, char* str);

/*-------------------------------------------------------------
	Public: float to string (0–6 decimal places)
-------------------------------------------------------------*/
void floatToStr(float value, char* str, uint8_t decimals);






#endif  /* __TIM_SSD1306_I2C_H__ */
