#ifndef LED_OPERATION_H
#define LED_OPERATION_H

#include "tm1640_gpio.h"
#include <stdio.h>
#include <ctype.h>

/* LED groups defination */
#define LED_GROUPS_NUM  16
#define LED_GPID1       0
#define LED_GPID2       1
#define LED_GPID3       2
#define LED_GPID4       3
#define LED_GPID5       4
#define LED_GPID6       5
#define LED_GPID7       6
#define LED_GPID8       7
#define LED_GPID9       8
#define LED_GPID10      9
#define LED_GPID11      10
#define LED_GPID12      11
#define LED_GPID13      12
#define LED_GPID14      13
#define LED_GPID15      14
#define LED_GPID16      15

/* Seg groups defination */
#define SOC_TEN_DIGIT_1         LED_GPID1
#define SOC_TEN_DIGIT_2         LED_GPID2
#define SOC_UNIT_DIGIT_1        LED_GPID3
#define SOC_UNIT_DIGIT_2        LED_GPID4

/* Rack Run State */
// LED_GPID5
#define STANDBY_ON		0b00001111
#define STANDBY_OFF		0b11110000
#define CHARGING_ON		0b11110000
#define CHARGING_OFF	0b00001111

// LED_GPID6
#define DISCHARGING_ON	0b00001111
#define DISCHARGING_OFF	0b11110000

// Wifi  G6 H6 A7 B
#define WIFI_G6_ON       0b11000000
#define WIFI_G6_OFF      0b00111111
#define WIFI_G7_ON       0b00000011
#define WIFI_G7_OFF      0b11111100

// Sun  C7 D7 E7 F7
#define SUN_ON          0b00111100
#define SUN_OFF         0b11000011

/* Warning */
// E_MARK  A16 B16 C16 D16
#define EXCLAMATORY_MART_ON     0b00001111   
#define EXCLAMATORY_MART_OFF    0b11110000  

/* SOC*/
// PERSENT --- H3 H4    
#define PERCENT_ON            0b10000000
#define PERCENT_OFF           0b01111111

// HUNDRED_UP --- E6 F6
#define HUNDRED_UP_ON           0b00110000
#define HUNDRED_UP_OFF          0b11001111

// HUNDRED_DOWN --- H1 H2
#define HUNDRED_DOWN_ON         0b10000000
#define HUNDRED_DOWN_OFF        0b01111111

#define DIGITAL_TUBE_OFF        0b10000000

// outside circle g7 h7 8 9 10 11
#define G7_H7_ON           0b11000000
#define G7_H7_OFF          0b00111111
#define G8_ON              0b11111111
#define G8_OFF             0b00000000
#define G9_ON              0b11111111
#define G9_OFF             0b00000000
#define G10_ON             0b11111111
#define G10_OFF            0b00000000
#define G11_ON             0b11111111
#define G11_OFF            0b00000000

// persent circle
#define BLUE_10_GROUP_ID       LED_GPID12
#define BLUE_10_ON             0b00000011
#define BLUE_10_OFF            0b11111100

#define BLUE_20_GROUP_ID       LED_GPID12
#define BLUE_20_ON             0b00001100
#define BLUE_20_OFF            0b11110011

#define BLUE_30_GROUP_ID       LED_GPID12
#define BLUE_30_ON             0b00110000
#define BLUE_30_OFF            0b11001111

#define BLUE_40_GROUP_ID       LED_GPID12
#define BLUE_40_ON             0b11000000
#define BLUE_40_OFF            0b00111111

#define BLUE_50_GROUP_ID       LED_GPID13
#define BLUE_50_ON             0b00000011
#define BLUE_50_OFF            0b11111100

#define BLUE_60_GROUP_ID       LED_GPID13
#define BLUE_60_ON             0b00001100
#define BLUE_60_OFF            0b11110011

#define BLUE_70_GROUP_ID       LED_GPID13
#define BLUE_70_ON             0b00110000
#define BLUE_70_OFF            0b11001111

#define BLUE_80_GROUP_ID       LED_GPID13
#define BLUE_80_ON             0b11000000
#define BLUE_80_OFF            0b00111111

#define BLUE_90_GROUP_ID       LED_GPID14
#define BLUE_90_ON             0b00000011
#define BLUE_90_OFF            0b11111100

#define BLUE_100_GROUP_ID      LED_GPID14
#define BLUE_100_ON            0b00001100
#define BLUE_100_OFF           0b11110011


void turn_led_on(tm1640_gpio *gpio_handler, unsigned char group_id, unsigned char code);
void turn_led_off(tm1640_gpio *gpio_handler, unsigned char group_id, unsigned char code);
void set_digital_tube(tm1640_gpio *gpio_handler, int group_id, int val);
void clean_digital_tube(tm1640_gpio *gpio_handler, int group_id);

#endif  /* LED_OPERATION_H */