#include <stdint.h>

// === Tosta CMDS ===

#define BT1P	'A'
#define BT1R	'a'
#define BT2P	'B'
#define BT2R	'b'
#define BT3P	'C'
#define BT3R	'c'
#define BT4P	'D'
#define BT4R	'd'

#define JSBP	'E'
#define JSBR	'e'
#define JSLP	'F'
#define JSLR	'f'
#define JSRP	'G'
#define JSRR	'g'
#define JSUP	'H'
#define JSUR	'h'
#define JSDP	'I'
#define JSDR	'i'

#define ENBP	'J'
#define ENBR	'j'
#define ENRH	'+'
#define ENLH	'-'

#define TYP_INT		0
#define TYP_FLOAT	1
#define TYP_ALPHA	2
#define TYP_LIST	3
#define TYP_NED		4
#define TYP_HID		5

#define MENU_PAGE_SOM		0
#define MENU_PAGE_DEFAULT	0
#define MENU_PAGE_AUDIO		1
#define MENU_PAGE_EOM		1

#define MENU_PAGE_MEM		2
#define MENU_PAGE_ALL		255

#define SAT		0
#define WRAP		1

#define MENU_NAME_ROW		0
#define MENU_NAME_COL		0

#define DISPLAY_BL_DIM		0
#define DISPLAY_ROWS		6
#define DISPLAY_COLS		14

#define DISPLAY_X_SIZE		48
#define DISPLAY_Y_SIZE		84
#define DISPLAY_STANDBY_TIMER	30000

// ==== MENU =======

typedef void (*menu_set_function)(void);
typedef void (*menu_print_function)(uint8_t a);

struct menu_item {
	uint8_t page;
        char name[14];
        uint8_t type;
        uint8_t size;
        uint8_t row;
        uint8_t col;
        uint32_t step;
        uint32_t min;
        uint32_t max;
        uint8_t wrap;
	char prefix[4];
	char suffix[4];
        uint32_t *varptr;
        menu_set_function set_function_ptr;
        menu_print_function print_function_ptr;
};

extern uint8_t menu_item, menu_page;
extern uint8_t menu_last_item[MENU_PAGE_EOM + 1];

extern char modulation_list[4][4];
extern char status_list[3][3];

extern struct menu_item items[];
// extern struct menu_item tabs[];

extern uint8_t menu_item_count;
// extern uint8_t tabs_count;

// funcs

void encoder_increment(void);
void encoder_decrement(void);
void joystick_dx(void);
void joystick_sx(void);
void set_menu_item(uint8_t mode);

void print_integer(uint8_t item_idx);
void print_string(uint8_t item_idx);
void print_modulation(uint8_t item_idx);
void print_bar(uint8_t item_idx);
void print_frequency(uint8_t item_idx);

char * valToStr(uint32_t val, char *buf, uint8_t bufSize, char sepChar);

uint8_t sat_subu8b(uint8_t x, uint8_t y);
void menu_item_up(void);
void menu_item_down(void);
