#define  M_PI ((float)3.141592654)
#define NB_LEDS_PER_STRIP 60
#define NB_LINES 20
#define NB_COLUMNS NB_LEDS_PER_STRIP
#define NB_PIXELS (NB_LINES*NB_COLUMNS)
#define RAW_SIZE (NB_PIXELS*3)
#define ONE_LINE_RAW_SIZE (NB_COLUMNS*3)

extern uint32_t gSecondCounter;

float getTime(void);
void setOffsetX(float X);
float updateOffsetX(float *time);
void setSpeedRPS(float RPS);
void waitBlocking(uint16_t x_us);
void setPC13asInput(void);
void setPC13asOutput(void);
uint8_t blueButtonIsDepressed(void);

void myWait1ms(int dtms);
void crash(uint8_t crash_code);
void lowPowerCrash(uint8_t crash_code);
void powerDownListeningWifi(void); // in main.c

// Crash Codes
#define CC_CODE_SINCOS 0x01
#define CC_UNKNOWN_HAL_STATUS_CODE 0x02
#define CC_TO_MANY_COMMANDS 0x03
#define CC_SW_ERROR_CMD_MNGR 0x04
#define CC_UNMANAGED_WF_SP_STATE 0x05
#define CC_SW_ERROR_ROLLOVER 0x06
#define CC_MUST_INCREASE_PARSER_BUFFER_SIZE 0x07
#define CC_DMA_TIM8_CH1_FAILED 0x08
#define CC_DMA_TIM8_CH3_FAILED 0x09
#define CC_MEMMANAGE_FAULT 0x0A
#define CC_BUS_FAULT 0x0B
#define CC_USAGE_FAULT 0x0C
#define CC_WIFI_STARTUP_FAILED 0x0D
#define CC_SERIAL_OVERFLOW_TX_WIFI 0x0E
#define CC_SERIAL_OVERFLOW_TX_PC 0x0F
#define CC_MAIN_POWER_UP_FAILED 0x10
#define CC_ERROR_HANDLER_MAIN 0x11
#define CC_ERROR_HANDLER_WIFI_UART_INIT 0x12


#define CC_HARD_FAULT 0xFF


#define RunLedOn() HAL_GPIO_WritePin(GLED_GPIO_Port,GLED_Pin,GPIO_PIN_SET)
#define RunLedOff() HAL_GPIO_WritePin(GLED_GPIO_Port,GLED_Pin,GPIO_PIN_RESET)
#define RunLedToggle() HAL_GPIO_TogglePin(GLED_GPIO_Port,GLED_Pin)

#define powerUp() HAL_GPIO_WritePin(PS_ON_GPIO_Port,PS_ON_Pin,GPIO_PIN_SET)
#define powerDown() HAL_GPIO_WritePin(PS_ON_GPIO_Port,PS_ON_Pin,GPIO_PIN_RESET)

#define isPowerOK() (HAL_GPIO_ReadPin(PW_KO_GPIO_Port,PW_KO_Pin)==GPIO_PIN_RESET)
