class CardSettings():
    """THIS CLASS IS USED TO STORE TE SETTINGS OF THE CARD
    but only stores data. It does not send any commands to real hardware"""
    DAC_RAMP_DIRECTION = "UP"
    DAC_RAMP_STEP = 1
    DAC_RAMP_DELAY = 0.1
    DAC_RAMP_MIN_VALUE = 0
    DAC_RAMP_MAX_VALUE = 4095
    VOLTAGE_REFERENCE = 3.3
    VOLTAGE_READ_AVERAGES = 0
    DAC_VALUE = 0
    ADC_VALUE = 0

    def parseConfigurationMessage(self,message:str) -> bool:
        message = message.split(";")[1:-1]
        for parameters in message:
            parameter = parameters.split(":")[0]
            data = parameters.split(":")[1]
            print(parameter,data)
            match parameter:
                case "DAC_RAMP_DIRECTION":
                    self.setRampDirection(data)
                case "DAC_RAMP_STEP":
                    self.setRampStep(int(data))
                case "DAC_RAMP_DELAY_2500_NS":
                    self.setRampDelay(int(data))
                case "DAC_RAMP_MIN_VALUE":
                    self.setRampMinValue(int(data))
                case "DAC_RAMP_MAX_VALUE":
                    self.setRampMaxValue(int(data))
                case "VOLTAGE_REFERENCE":
                    self.setVoltageReference(float(data))
                case "VOLTAGE_READ_AVERAGES":
                    self.setVoltageReadAverages(int(data))
                case "DAC_VALUE":
                    self.setDACValue(int(data))
                case "ADC_VALUE":
                    self.setADCValue(int(data))

    def setRampDirection(self,direction:str):
        self.DAC_RAMP_DIRECTION = direction
    
    def setRampStep(self,step:int):
        self.DAC_RAMP_STEP = step

    def setRampDelay(self,delay:int):
        self.DAC_RAMP_DELAY = delay
    
    def setRampMinValue(self,min_value:int):
        self.DAC_RAMP_MIN_VALUE = min_value
    
    def setRampMaxValue(self,max_value:int):
        self.DAC_RAMP_MAX_VALUE = max_value
    
    def setVoltageReference(self,voltage_reference:float):
        self.VOLTAGE_REFERENCE = voltage_reference

    def setVoltageReadAverages(self,voltage_read_averages:int):
        self.VOLTAGE_READ_AVERAGES = voltage_read_averages

    def setDACValue(self,dac_value:int):
        self.DAC_VALUE = dac_value
    
    def setADCValue(self,adc_value:int):
        self.ADC_VALUE = adc_value


card = CardSettings()
card.parseConfigurationMessage("OK;DAC_RAMP_DIRECTION:0;DAC_RAMP_MIN_VALUE:0;DAC_RAMP_MAX_VALUE:4095;DAC_RAMP_STEP:1;DAC_RAMP_DELAY_2500_NS:2;VOLTAGE_READ_AVERAGES:10;VOLTAGE_REFERENCE:3.300000;")