示例#1
0
void calibrateI(bool charging, uint8_t point, AnalogInputs::ValueType current)
{
    AnalogInputs::ValueType maxValue;
    AnalogInputs::Name name1;
    AnalogInputs::Name name2;
    AnalogInputs::CalibrationPoint pName1;
    AnalogInputs::CalibrationPoint pName2;

    Program::dischargeOutputCapacitor();
    AnalogInputs::powerOn();
    if(testVout(false)) {

        if(charging) {
            maxValue = SMPS_UPPERBOUND_VALUE;
            name1 = AnalogInputs::IsmpsSet;
            name2 = AnalogInputs::Ismps;
            SMPS::powerOn();
            hardware::setVoutCutoff(MAX_CHARGE_V);

        } else {
            name1 = AnalogInputs::IdischargeSet;
            name2 = AnalogInputs::Idischarge;
            maxValue = DISCHARGER_UPPERBOUND_VALUE;
            Discharger::powerOn();
        }

        getCalibrationPoint(pName1, name1, point);
        getCalibrationPoint(pName2, name2, point);

        CurrentMenu menu(name1, name2, point, maxValue);
        int8_t index;
        do {
            menu.refreshValue(pName1);
            index = menu.runSimple(true);
            if(index < 0) break;
            if(index == 0) {
                setCurrentValue(name1, menu.value_);
                if(menu.runEdit()) {
                    AnalogInputs::doFullMeasurement();
                    pName1.y = current;
                    pName1.x = menu.value_;
                    pName2.y = current;
                    pName2.x = AnalogInputs::getAvrADCValue(name2);
                }
                setCurrentValue(name1, 0);
            }
        } while(true);

        if(charging)   SMPS::powerOff();
        else           Discharger::powerOff();

        //Info: we save eeprom data only when no current is flowing
        AnalogInputs::setCalibrationPoint(name1, point, pName1);
        AnalogInputs::setCalibrationPoint(name2, point, pName2);
        eeprom::restoreCalibrationCRC();
    }
    AnalogInputs::powerOff();
}
示例#2
0
int GUI_calibrate(void){
	int x_pos[4]={CAL_DOT_OFFSET,GLCD_WIDTH-CAL_DOT_OFFSET,GLCD_WIDTH-CAL_DOT_OFFSET,CAL_DOT_OFFSET};
	int y_pos[4]={CAL_DOT_OFFSET,CAL_DOT_OFFSET,GLCD_HEIGHT-CAL_DOT_OFFSET,GLCD_HEIGHT-CAL_DOT_OFFSET};
	int x_read[4];
	int y_read[4];
	float dr;
	float dp;
	
	for(int i = 0; i<4 ; i++){
		getCalibrationPoint(x_pos[i],y_pos[i],&(x_read[i]),&(y_read[i]));
		delay_ms(500);
	}
	
	dp=(((x_pos[1]+x_pos[2])-(x_pos[0]+x_pos[3]))/2);
	dr=(((x_read[1]+x_read[2])-(x_read[0]+x_read[3]))/2);
	x_scale=dr/dp;
	
	dp=(((y_pos[2]+y_pos[3])-(y_pos[0]+y_pos[1]))/2);
	dr=(((y_read[2]+y_read[3])-(y_read[0]+y_read[1]))/2);
	y_scale=dr/dp;
	
	x_offset=0;
	y_offset=0;
	
	for(int i = 0; i < 4; i++){
		x_offset+=x_read[i]-x_pos[i]*x_scale;
		y_offset+=y_read[i]-y_pos[i]*y_scale;;
	}
	x_offset/=4;
	y_offset/=4;
	
	return 1;
}
static void currentCalibration(uint8_t point)
{
    AnalogInputs::CalibrationPoint pSet;
    AnalogInputs::CalibrationPoint p;
    bool save = false;

    Program::dischargeOutputCapacitor();
    AnalogInputs::powerOn();
    if(testVout(false)) {

        getCalibrationPoint(pSet, gNameSet_, point);
        getCalibrationPoint(p, gName_, point);

        EditMenu::initialize(currentData, editCallback);
        gIexpected_ = pSet.y;
        int8_t index;
        do {
            gValue_ = pSet.x;
            index = EditMenu::run(true);
            if(index < 0) break;
            else if(index == 0) {
                powerOnCurrent();
                setCurrentValue(gValue_);
                if(EditMenu::runEdit()) {
                    AnalogInputs::doFullMeasurement();
                    pSet.y = gIexpected_;
                    pSet.x = gValue_;
                    p.y = gIexpected_;
                    p.x = AnalogInputs::getAvrADCValue(gName_);
                    save = true;
                }
                setCurrentValue(0);
                powerOffCurrent();
            } else if(index == 2 && !EditMenu::runEdit()) {
                gIexpected_ = pSet.y;
            }
        } while(true);

        //Info: we save eeprom data only when no current is flowing
        if(save) {
            AnalogInputs::setCalibrationPoint(gNameSet_, point, pSet);
            AnalogInputs::setCalibrationPoint(gName_, point, p);
            eeprom::restoreCalibrationCRC();
        }
    }
    AnalogInputs::powerOff();
}