rework of lightning
This commit is contained in:
parent
df123d7120
commit
0aecd7e80b
@ -56,13 +56,14 @@ public class ManualDriveActivity extends AppCompatActivity {
|
|||||||
ToggleButton m1ControlButton = (ToggleButton) findViewById(R.id.m1_control_button);
|
ToggleButton m1ControlButton = (ToggleButton) findViewById(R.id.m1_control_button);
|
||||||
ToggleButton m2ControlButton = (ToggleButton) findViewById(R.id.m2_control_button);
|
ToggleButton m2ControlButton = (ToggleButton) findViewById(R.id.m2_control_button);
|
||||||
|
|
||||||
mapButtonCoil.put(h1ControlButton, 65);
|
mapButtonCoil.put(h1ControlButton, 64);
|
||||||
mapButtonCoil.put(h2ControlButton, 70);
|
mapButtonCoil.put(h2ControlButton, 70);
|
||||||
mapButtonCoil.put(m1ControlButton, 66);
|
mapButtonCoil.put(m1ControlButton, 66);
|
||||||
mapButtonCoil.put(m2ControlButton, 67);
|
mapButtonCoil.put(m2ControlButton, 67);
|
||||||
|
|
||||||
LocalBroadcastManager.getInstance(this).registerReceiver(coilWriterMessageReceiver, new IntentFilter("readVmCoil2"));
|
LocalBroadcastManager.getInstance(this).registerReceiver(coilWriterMessageReceiver, new IntentFilter("readVmCoil2"));
|
||||||
// LocalBroadcastManager.getInstance(this).registerReceiver(coilWriterMessageReceiver, new IntentFilter("checkCoilValue"));
|
// LocalBroadcastManager.getInstance(this).registerReceiver(coilWriterMessageReceiver, new IntentFilter("checkCoilValue"));
|
||||||
|
LocalBroadcastManager.getInstance(this).registerReceiver(coilMessageReceiver, new IntentFilter("readOnlyCoil"));
|
||||||
|
|
||||||
// manual drive button
|
// manual drive button
|
||||||
ToggleButton manualDriveOverrideButton = (ToggleButton) findViewById(R.id.manual_override_button);
|
ToggleButton manualDriveOverrideButton = (ToggleButton) findViewById(R.id.manual_override_button);
|
||||||
@ -102,7 +103,7 @@ public class ManualDriveActivity extends AppCompatActivity {
|
|||||||
button.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
button.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
if (isChecked) {
|
if (isChecked && manualMode) {
|
||||||
// writing the value true
|
// writing the value true
|
||||||
Intent serviceIntent = new Intent(getApplicationContext(), MyIntentService.class);
|
Intent serviceIntent = new Intent(getApplicationContext(), MyIntentService.class);
|
||||||
serviceIntent.setAction("write.coil");
|
serviceIntent.setAction("write.coil");
|
||||||
@ -164,24 +165,175 @@ public class ManualDriveActivity extends AppCompatActivity {
|
|||||||
Runnable refreshCoil = new Runnable() {
|
Runnable refreshCoil = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
System.out.println("pass "+manualMode);
|
|
||||||
if (manualMode) {
|
|
||||||
for (Map.Entry<Integer, Boolean> entry : mapCoilCheckStatus.entrySet()) {
|
|
||||||
System.out.println("entry : " + entry.getKey() + " value :" + entry.getValue());
|
|
||||||
if (entry.getValue() == true) { // if the thing is toggle
|
|
||||||
Intent serviceIntent = new Intent(getApplicationContext(), MyIntentService.class);
|
Intent serviceIntent = new Intent(getApplicationContext(), MyIntentService.class);
|
||||||
serviceIntent.setAction("read.coil");
|
serviceIntent.setAction("read.coil");
|
||||||
serviceIntent.putExtra("extra.ip.address", state.getIpAddress());
|
serviceIntent.putExtra("extra.ip.address", state.getIpAddress());
|
||||||
serviceIntent.putExtra("extra.ip.port", state.getPort());
|
serviceIntent.putExtra("extra.ip.port", state.getPort());
|
||||||
serviceIntent.putExtra("extra.ref", state.getMapMappingValue().get(entry.getKey()));
|
serviceIntent.putExtra("extra.ref", GlobalState.InputConfig.Q_COIL.getStartReference());
|
||||||
serviceIntent.putExtra("extra.count", 1);
|
serviceIntent.putExtra("extra.count", GlobalState.InputConfig.Q_COIL.getCount());
|
||||||
serviceIntent.putExtra("extra.intent.name", "read");
|
serviceIntent.putExtra("extra.intent.name", "readOnlyCoil");
|
||||||
getApplicationContext().startService(serviceIntent);
|
getApplicationContext().startService(serviceIntent);
|
||||||
}
|
|
||||||
}
|
coilHandler.postDelayed(this, 3000);
|
||||||
}
|
|
||||||
coilHandler.postDelayed(this, 2000);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// on message receive, update the view with values
|
||||||
|
private BroadcastReceiver coilMessageReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
String action = intent.getAction();
|
||||||
|
Bundle bundle = intent.getExtras();
|
||||||
|
boolean[] booleanArray = bundle.getBooleanArray("coilValues");
|
||||||
|
|
||||||
|
// ========== Button ============
|
||||||
|
ToggleButton h1ControlButton = findViewById(R.id.h1_control_button);
|
||||||
|
ToggleButton h2ControlButton = findViewById(R.id.h2_control_button);
|
||||||
|
Button pu1ControlButton = findViewById(R.id.pu1_control_button);
|
||||||
|
Button pu2ControlButton = findViewById(R.id.pu2_control_button);
|
||||||
|
Button sp1ControlButton = findViewById(R.id.sp1_control_button);
|
||||||
|
Button b1ControlButton = findViewById(R.id.b1_control_button);
|
||||||
|
ToggleButton m1ControlButton = findViewById(R.id.m1_control_button);
|
||||||
|
ToggleButton m2ControlButton = findViewById(R.id.m2_control_button);
|
||||||
|
|
||||||
|
// ============= Light ===============
|
||||||
|
ImageView manualLightOn = findViewById(R.id.manual_override_status_light_on);
|
||||||
|
ImageView manualLightOff = findViewById(R.id.manual_override_status_light_off);
|
||||||
|
|
||||||
|
ImageView h1StatusLightOn = findViewById(R.id.h1_status_light_on);
|
||||||
|
ImageView h1StatusLightOff = findViewById(R.id.h1_status_light_off);
|
||||||
|
ImageView h2StatusLightOn = findViewById(R.id.h2_status_light_on);
|
||||||
|
ImageView h2StatusLightOff = findViewById(R.id.h2_status_light_off);
|
||||||
|
|
||||||
|
ImageView pu1StatusLightOn = findViewById(R.id.pu1_status_light_on);
|
||||||
|
ImageView pu1StatusLightOff = findViewById(R.id.pu1_status_light_off);
|
||||||
|
ImageView pu2StatusLightOn = findViewById(R.id.pu2_status_light_on);
|
||||||
|
ImageView pu2StatusLightOff = findViewById(R.id.pu2_status_light_off);
|
||||||
|
|
||||||
|
ImageView sp1StatusLightOn = findViewById(R.id.sp1_status_light_on);
|
||||||
|
ImageView sp1StatusLightOff = findViewById(R.id.sp1_status_light_off);
|
||||||
|
ImageView b1StatusLightOn = findViewById(R.id.b1_status_light_on);
|
||||||
|
ImageView b1StatusLightOff = findViewById(R.id.b1_status_light_off);
|
||||||
|
|
||||||
|
ImageView m1StatusLightOn = findViewById(R.id.m1_status_light_on);
|
||||||
|
ImageView m1StatusLightOff = findViewById(R.id.m1_status_light_off);
|
||||||
|
ImageView m2StatusLightOn = findViewById(R.id.m2_status_light_on);
|
||||||
|
ImageView m2StatusLightOff = findViewById(R.id.m2_status_light_off);
|
||||||
|
|
||||||
|
if (manualMode) {
|
||||||
|
h1ControlButton.setEnabled(true);
|
||||||
|
h2ControlButton.setEnabled(true);
|
||||||
|
m1ControlButton.setEnabled(true);
|
||||||
|
m2ControlButton.setEnabled(true);
|
||||||
|
pu1ControlButton.setEnabled(true);
|
||||||
|
pu2ControlButton.setEnabled(true);
|
||||||
|
sp1ControlButton.setEnabled(true);
|
||||||
|
b1ControlButton.setEnabled(true);
|
||||||
|
|
||||||
|
manualLightOn.setVisibility(View.VISIBLE);
|
||||||
|
manualLightOff.setVisibility(View.INVISIBLE);
|
||||||
|
// lightning
|
||||||
|
// ======== h1 =========
|
||||||
|
if (booleanArray[0] == true) {
|
||||||
|
h1StatusLightOn.setVisibility(View.VISIBLE);
|
||||||
|
h1StatusLightOff.setVisibility(View.INVISIBLE);
|
||||||
|
} else {
|
||||||
|
h1StatusLightOn.setVisibility(View.INVISIBLE);
|
||||||
|
h1StatusLightOff.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======== h2 ======
|
||||||
|
if (booleanArray[1] == true) {
|
||||||
|
h2StatusLightOn.setVisibility(View.VISIBLE);
|
||||||
|
h2StatusLightOff.setVisibility(View.INVISIBLE);
|
||||||
|
} else {
|
||||||
|
h2StatusLightOn.setVisibility(View.INVISIBLE);
|
||||||
|
h2StatusLightOff.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======== m1 ======
|
||||||
|
if (booleanArray[2] == true) {
|
||||||
|
m1StatusLightOn.setVisibility(View.VISIBLE);
|
||||||
|
m1StatusLightOff.setVisibility(View.INVISIBLE);
|
||||||
|
} else {
|
||||||
|
m1StatusLightOn.setVisibility(View.INVISIBLE);
|
||||||
|
m1StatusLightOff.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======== m2 ======
|
||||||
|
if (booleanArray[3] == true) {
|
||||||
|
m2StatusLightOn.setVisibility(View.VISIBLE);
|
||||||
|
m2StatusLightOff.setVisibility(View.INVISIBLE);
|
||||||
|
} else {
|
||||||
|
m2StatusLightOn.setVisibility(View.INVISIBLE);
|
||||||
|
m2StatusLightOff.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======== pu1 ======
|
||||||
|
if (booleanArray[4] == true) {
|
||||||
|
pu1StatusLightOn.setVisibility(View.VISIBLE);
|
||||||
|
pu1StatusLightOff.setVisibility(View.INVISIBLE);
|
||||||
|
} else {
|
||||||
|
pu1StatusLightOn.setVisibility(View.INVISIBLE);
|
||||||
|
pu1StatusLightOff.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======== pu2 ======
|
||||||
|
if (booleanArray[5] == true) {
|
||||||
|
pu2StatusLightOn.setVisibility(View.VISIBLE);
|
||||||
|
pu2StatusLightOff.setVisibility(View.INVISIBLE);
|
||||||
|
} else {
|
||||||
|
pu2StatusLightOn.setVisibility(View.INVISIBLE);
|
||||||
|
pu2StatusLightOff.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======== m2 ======
|
||||||
|
if (booleanArray[6] == true) {
|
||||||
|
sp1StatusLightOn.setVisibility(View.VISIBLE);
|
||||||
|
sp1StatusLightOff.setVisibility(View.INVISIBLE);
|
||||||
|
} else {
|
||||||
|
sp1StatusLightOn.setVisibility(View.INVISIBLE);
|
||||||
|
sp1StatusLightOff.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======== m2 ======
|
||||||
|
if (booleanArray[7] == true) {
|
||||||
|
b1StatusLightOn.setVisibility(View.VISIBLE);
|
||||||
|
b1StatusLightOff.setVisibility(View.INVISIBLE);
|
||||||
|
} else {
|
||||||
|
b1StatusLightOn.setVisibility(View.INVISIBLE);
|
||||||
|
b1StatusLightOff.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
h1ControlButton.setEnabled(false);
|
||||||
|
h2ControlButton.setEnabled(false);
|
||||||
|
m1ControlButton.setEnabled(false);
|
||||||
|
m2ControlButton.setEnabled(false);
|
||||||
|
pu1ControlButton.setEnabled(false);
|
||||||
|
pu2ControlButton.setEnabled(false);
|
||||||
|
sp1ControlButton.setEnabled(false);
|
||||||
|
b1ControlButton.setEnabled(false);
|
||||||
|
|
||||||
|
manualLightOn.setVisibility(View.INVISIBLE);
|
||||||
|
manualLightOff.setVisibility(View.VISIBLE);
|
||||||
|
// switch all off
|
||||||
|
h1StatusLightOn.setVisibility(View.INVISIBLE);
|
||||||
|
h1StatusLightOff.setVisibility(View.INVISIBLE);
|
||||||
|
h2StatusLightOn.setVisibility(View.INVISIBLE);
|
||||||
|
h2StatusLightOff.setVisibility(View.INVISIBLE);
|
||||||
|
m1StatusLightOn.setVisibility(View.INVISIBLE);
|
||||||
|
m1StatusLightOff.setVisibility(View.INVISIBLE);
|
||||||
|
m2StatusLightOn.setVisibility(View.INVISIBLE);
|
||||||
|
m2StatusLightOff.setVisibility(View.INVISIBLE);
|
||||||
|
pu1StatusLightOn.setVisibility(View.INVISIBLE);
|
||||||
|
pu1StatusLightOff.setVisibility(View.INVISIBLE);
|
||||||
|
pu2StatusLightOn.setVisibility(View.INVISIBLE);
|
||||||
|
pu2StatusLightOff.setVisibility(View.INVISIBLE);
|
||||||
|
sp1StatusLightOn.setVisibility(View.INVISIBLE);
|
||||||
|
sp1StatusLightOff.setVisibility(View.INVISIBLE);
|
||||||
|
b1StatusLightOn.setVisibility(View.INVISIBLE);
|
||||||
|
b1StatusLightOff.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user