Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed errors in Power Source values #2559

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 40 additions & 20 deletions app/src/main/java/io/pslab/activity/PowerSourceActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,13 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
monitorLongClicks(upPV3, downPV3);
monitorLongClicks(upPCS, downPCS);

updateDisplay(displayPV1, limitDigits(mapProgressToPower(retrievePowerValues(Pin.PV1),
updatePower(displayPV1, limitDigits(mapProgressToPower(retrievePowerValues(Pin.PV1),
PV1_CONTROLLER_MAX, PV1_VOLTAGE_RANGE.getUpper(), PV1_VOLTAGE_RANGE.getLower())), Pin.PV1);
updateDisplay(displayPV2, limitDigits(mapProgressToPower(retrievePowerValues(Pin.PV2),
updatePower(displayPV2, limitDigits(mapProgressToPower(retrievePowerValues(Pin.PV2),
PV2_CONTROLLER_MAX, PV2_VOLTAGE_RANGE.getUpper(), PV2_VOLTAGE_RANGE.getLower())), Pin.PV2);
updateDisplay(displayPV3, limitDigits(mapProgressToPower(retrievePowerValues(Pin.PV3),
updatePower(displayPV3, limitDigits(mapProgressToPower(retrievePowerValues(Pin.PV3),
PV3_CONTROLLER_MAX, PV3_VOLTAGE_RANGE.getUpper(), PV3_VOLTAGE_RANGE.getLower())), Pin.PV3);
updateDisplay(displayPCS, limitDigits(mapProgressToPower(retrievePowerValues(Pin.PCS),
updatePower(displayPCS, limitDigits(mapProgressToPower(retrievePowerValues(Pin.PCS),
PCS_CONTROLLER_MAX, PCS_CURRENT_RANGE.getUpper(), PCS_CURRENT_RANGE.getLower())), Pin.PCS);

if (getIntent().getExtras() != null && getIntent().getExtras().getBoolean(KEY_LOG)) {
Expand Down Expand Up @@ -527,17 +527,16 @@ private void monitorControllers(Croller controller, final Pin pin, int controlle

@Override
public void onProgressChanged(Croller croller, int progress) {
setMappedPower(pin, progress);
this.progress = progress;
removeCursor();
}

@Override
public void onStartTrackingTouch(Croller croller) { /**/ }

@Override
public void onStopTrackingTouch(Croller croller) {
setPower(pin);
setMappedPower(pin, progress);
removeCursor();
/*
V6 hardware has two pairs of paired channels:
0: PCS & PVS2
Expand All @@ -554,6 +553,8 @@ public void onStopTrackingTouch(Croller croller) {
} else {
controllerPV3.setProgress((int) (progress * 3.3 / 10));
}
updateDisplay(displayPV3, limitDigits(mapProgressToPower((int) (progress * 3.3 / 10), PV3_CONTROLLER_MAX,
PV3_VOLTAGE_RANGE.getUpper(), PV3_VOLTAGE_RANGE.getLower())), Pin.PV3);
break;
case PV2:
if (PCS_CONTROLLER_MAX - (progress / 2) > PCS_CONTROLLER_MAX) {
Expand All @@ -563,6 +564,8 @@ public void onStopTrackingTouch(Croller croller) {
} else {
controllerPCS.setProgress(PCS_CONTROLLER_MAX - (progress / 2));
}
updateDisplay(displayPCS, limitDigits(mapProgressToPower(PCS_CONTROLLER_MAX - (progress / 2), PCS_CONTROLLER_MAX,
PCS_CURRENT_RANGE.getUpper(), PCS_CURRENT_RANGE.getLower())), Pin.PCS);
break;
case PV3:
if ((int) (progress * 10 / 3.3) > PV1_CONTROLLER_MAX) {
Expand All @@ -572,6 +575,8 @@ public void onStopTrackingTouch(Croller croller) {
} else {
controllerPV1.setProgress((int) (progress * 10 / 3.3));
}
updateDisplay(displayPV1, limitDigits(mapProgressToPower((int) (progress * 3.3 / 10), PV1_CONTROLLER_MAX,
PV1_VOLTAGE_RANGE.getUpper(), PV1_VOLTAGE_RANGE.getLower())), Pin.PV1);
break;
case PCS:
if (PV2_CONTROLLER_MAX - (progress * 2) > PV2_CONTROLLER_MAX) {
Expand All @@ -581,6 +586,8 @@ public void onStopTrackingTouch(Croller croller) {
} else {
controllerPV2.setProgress(PV2_CONTROLLER_MAX - (progress * 2));
}
updateDisplay(displayPV2, limitDigits(mapProgressToPower(PV2_CONTROLLER_MAX - (progress * 2), PV2_CONTROLLER_MAX,
PV2_VOLTAGE_RANGE.getUpper(), PV2_VOLTAGE_RANGE.getLower())), Pin.PV2);
break;
default:
break;
Expand Down Expand Up @@ -689,28 +696,28 @@ private void incrementValue(Pin pin) {
case PV1:
if (voltagePV1 < PV1_VOLTAGE_RANGE.getUpper()) {
voltagePV1 += STEP;
updateDisplay(displayPV1, voltagePV1, Pin.PV1);
updatePower(displayPV1, voltagePV1, Pin.PV1);
updateController(controllerPV1, Pin.PV1);
}
break;
case PV2:
if (voltagePV2 < PV2_VOLTAGE_RANGE.getUpper()) {
voltagePV2 += STEP;
updateDisplay(displayPV2, voltagePV2, Pin.PV2);
updatePower(displayPV2, voltagePV2, Pin.PV2);
updateController(controllerPV2, Pin.PV2);
}
break;
case PV3:
if (voltagePV3 < PV3_VOLTAGE_RANGE.getUpper()) {
voltagePV3 += STEP;
updateDisplay(displayPV3, voltagePV3, Pin.PV3);
updatePower(displayPV3, voltagePV3, Pin.PV3);
updateController(controllerPV3, Pin.PV3);
}
break;
case PCS:
if (currentPCS < PCS_CURRENT_RANGE.getUpper()) {
currentPCS += STEP;
updateDisplay(displayPCS, currentPCS, Pin.PCS);
updatePower(displayPCS, currentPCS, Pin.PCS);
updateController(controllerPCS, Pin.PCS);
}
break;
Expand All @@ -729,28 +736,28 @@ private void decrementValue(Pin pin) {
case PV1:
if (voltagePV1 > PV1_VOLTAGE_RANGE.getLower()) {
voltagePV1 -= STEP;
updateDisplay(displayPV1, voltagePV1, Pin.PV1);
updatePower(displayPV1, voltagePV1, Pin.PV1);
updateController(controllerPV1, Pin.PV1);
}
break;
case PV2:
if (voltagePV2 > PV2_VOLTAGE_RANGE.getLower()) {
voltagePV2 -= STEP;
updateDisplay(displayPV2, voltagePV2, Pin.PV2);
updatePower(displayPV2, voltagePV2, Pin.PV2);
updateController(controllerPV2, Pin.PV2);
}
break;
case PV3:
if (voltagePV3 > PV3_VOLTAGE_RANGE.getLower()) {
voltagePV3 -= STEP;
updateDisplay(displayPV3, voltagePV3, Pin.PV3);
updatePower(displayPV3, voltagePV3, Pin.PV3);
updateController(controllerPV3, Pin.PV3);
}
break;
case PCS:
if (currentPCS > PCS_CURRENT_RANGE.getLower()) {
currentPCS -= STEP;
updateDisplay(displayPCS, currentPCS, Pin.PCS);
updatePower(displayPCS, currentPCS, Pin.PCS);
updateController(controllerPCS, Pin.PCS);
}
break;
Expand Down Expand Up @@ -796,13 +803,26 @@ private void updateController(Croller controller, Pin pin) {
* @param value signed power value
* @param pin assigned power pin
*/
private void updateDisplay(TextView display, float value, Pin pin) {
private void updatePower(TextView display, float value, Pin pin) {
String displayText = (value >= 0 ? "+" : "-").concat(String.format(Locale.getDefault(),
"%.2f", Math.abs(value))).concat(pin.equals(Pin.PCS) ? " mA" : " V");
display.setText(displayText);
setPower(pin);
}

/**
* Updates display with user set values
*
* @param display text view corresponding to power values
* @param value signed power value
* @param pin assigned power pin
*/
private void updateDisplay(TextView display, float value, Pin pin) {
String displayText = (value >= 0 ? "+" : "-").concat(String.format(Locale.getDefault(),
"%.2f", Math.abs(value))).concat(pin.equals(Pin.PCS) ? " mA" : " V");
display.setText(displayText);
}

/**
* Updates display and calculate power value determined by knob position
*
Expand All @@ -815,22 +835,22 @@ private void setMappedPower(Pin pin, int progress) {
case PV1:
voltagePV1 = limitDigits(mapProgressToPower(progress, PV1_CONTROLLER_MAX,
PV1_VOLTAGE_RANGE.getUpper(), PV1_VOLTAGE_RANGE.getLower()));
updateDisplay(displayPV1, voltagePV1, pin);
updatePower(displayPV1, voltagePV1, pin);
break;
case PV2:
voltagePV2 = limitDigits(mapProgressToPower(progress, PV2_CONTROLLER_MAX,
PV2_VOLTAGE_RANGE.getUpper(), PV2_VOLTAGE_RANGE.getLower()));
updateDisplay(displayPV2, voltagePV2, pin);
updatePower(displayPV2, voltagePV2, pin);
break;
case PV3:
voltagePV3 = limitDigits(mapProgressToPower(progress, PV3_CONTROLLER_MAX,
PV3_VOLTAGE_RANGE.getUpper(), PV3_VOLTAGE_RANGE.getLower()));
updateDisplay(displayPV3, voltagePV3, pin);
updatePower(displayPV3, voltagePV3, pin);
break;
case PCS:
currentPCS = limitDigits(mapProgressToPower(progress, PCS_CONTROLLER_MAX,
PCS_CURRENT_RANGE.getUpper(), PCS_CURRENT_RANGE.getLower()));
updateDisplay(displayPCS, currentPCS, pin);
updatePower(displayPCS, currentPCS, pin);
break;
default:
break;
Expand Down
Loading