//
// Created by Matthew on 2023/12/27.
//

#ifndef MICROPHOTO_GPIOCONTROL_H
#define MICROPHOTO_GPIOCONTROL_H

#include <string>

#define CMD_GET_LIGHT_ADC                       101
#define CMD_SET_LIGHT_ADC                       102
#define CMD_GET_KEY_LOCKSTATE                   103
#define CMD_GET_BAT_ADC                         104
#define CMD_SET_FLASH_LED                       105
#define CMD_SET_NETWORK_STATE                   106
#define CMD_SET_OTG_STATE                       107
#define CMD_GET_OTG_STATE                       108
#define CMD_GET_CHARGING_VOL_STATE              110
#define CMD_GET_CHARGING_SHUNT_VOLTAGE_STATE    111
#define CMD_GET_CHARGING_BUS_VOLTAGE_STATE      112
#define CMD_GET_CHARGING_POWER_STATE            113
#define CMD_GET_CHARGING_CURRENT_STATE          114
#define CMD_GET_BAT_VOL_STATE                   115
#define CMD_GET_BAT_SHUNT_VOLTAGE_STATE         116
#define CMD_GET_BAT_BUS_VOLTAGE_STATE           117
#define CMD_GET_BAT_POWER_STATE                 118
#define CMD_GET_BAT_CURRENT_STATE               119
#define CMD_SET_485_STATE                       121
#define CMD_SET_SPI_MODE                        123
#define CMD_SET_SPI_BITS_PER_WORD               124
#define CMD_SET_SPI_MAXSPEEDHZ                  125
#define CMD_SET_PWM_BEE_STATE                   126
#define CMD_SET_ALM_MODE                        128
#define CMD_SET_SPI_POWER                       129
#define CMD_SET_485_EN_STATE					131
#define CMD_SET_CAM_3V3_EN_STATE				132
#define CMD_SET_12V_EN_STATE					133
#define CMD_SET_SYSTEM_RESET  		            202

class GpioControl
{
public:

    static void setInt(int cmd, int value);
    static int getInt(int cmd);
    static void setLong(int cmd, long value);
    static long getLong(int cmd);
    static void setString(int cmd, const std::string& value);
    static std::string getString(int cmd);

    static void setOtgState(bool on)
    {
        setInt(CMD_SET_OTG_STATE, on ? 1 : 0);
    }

    static bool getOtgState()
    {
        return getInt(CMD_SET_OTG_STATE) != 0;
    }

    static void setCam3V3Enable(bool enabled)
    {
        setInt(CMD_SET_CAM_3V3_EN_STATE, enabled ? 1 : 0);
    }

    static void reboot()
    {
        setInt(CMD_SET_SYSTEM_RESET, 1);
    }

    static void setLightAdc(int i)
    {
        setInt(CMD_SET_LIGHT_ADC, i);
    }

    static int getLightAdc()
    {
        return getInt(CMD_GET_LIGHT_ADC);
    }

    static int getChargingVoltage()
    {
        return getInt(CMD_GET_CHARGING_VOL_STATE);
    }

    static int getChargingShuntVoltage()
    {
        return getInt(CMD_GET_CHARGING_SHUNT_VOLTAGE_STATE);
    }

    static int getChargingBusVoltage() {
        return getInt(CMD_GET_CHARGING_BUS_VOLTAGE_STATE);
    }

    static int getChargingPower() {
        return getInt(CMD_GET_CHARGING_POWER_STATE);
    }

    static int getChargingCurrent() {
        return getInt(CMD_GET_CHARGING_CURRENT_STATE);
    }

    static int getBatteryVoltage() {
        return getInt(CMD_GET_BAT_VOL_STATE);
    }

    static int getBatteryShuntVoltage() {
        return getInt(CMD_GET_BAT_SHUNT_VOLTAGE_STATE);
    }

    static int getBatteryBusVoltage() {
        return getInt(CMD_GET_BAT_BUS_VOLTAGE_STATE);
    }

    static int getBatteryPower() {
        return getInt(CMD_GET_BAT_POWER_STATE);
    }

    static int getBatteryCurrent() {
        return getInt(CMD_GET_BAT_CURRENT_STATE);
    }

    static void set485WriteMode() {
        setInt(CMD_SET_485_STATE, 1);
    }

    static void set485ReadMode() {
        setInt(CMD_SET_485_STATE, 0);
    }

    static void setSpiMode(int i) {
        setInt(CMD_SET_SPI_MODE, i);
    }

    static void setSpiBitsPerWord(int i) {
        setInt(CMD_SET_SPI_BITS_PER_WORD, i);
    }

    static void setSpiMaxSpeedHz(long j) {
        setLong(CMD_SET_SPI_MAXSPEEDHZ, j);
    }

    static void setBeeOn(bool z) {
        setInt(CMD_SET_PWM_BEE_STATE, z ? 1 : 0);
    }

    static void setJidianqiState(bool z) {
        setInt(CMD_SET_ALM_MODE, z ? 1 : 0);
    }

    static void setSpiPower(bool on) {
        setInt(CMD_SET_SPI_POWER, on ? 1 : 0);
    }

    static void setRS485Enable(bool z) {
        setInt(CMD_SET_485_EN_STATE, z ? 1 : 0);
    }


    static void set12VEnable(bool z) {
        setInt(CMD_SET_12V_EN_STATE, z ? 1 : 0);
    }

};


#endif //MICROPHOTO_GPIOCONTROL_H
