/* MultiWii EZ-GUI
Copyright (C) <2012> Bartosz Szczygiel (eziosoft)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ezio.multiwii.other;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockActivity;
import com.ezio.multiwii.R;
import com.ezio.multiwii.app.App;
public class PadOtherCaliActivity {
public Activity mContext;
public App app;
Handler mHandler = new Handler();
private boolean killme = false;
EditText EditTextPowerMeterAlarm;
EditText EditTextSelectSettings;
EditText EditTextSetSerialBoudRate;
EditText EditTextMinThrottle;
EditText EditTextMaxThrottle;
EditText EditTextMinCommand;
EditText EditTextFailsafeThrottle;
EditText EditTextVBatsScale;
EditText EditTextBatWarning1;
EditText EditTextBatWarning2;
EditText EditTextBatCritical;
TextView TextViewVolt;
EditText EditTextDeclination;
TextView textViewArmedCount;
Button ButtonRxBIND;
private Runnable update = new Runnable() {
@Override
public void run() {
app.mw.ProcessSerialData(app.loggingON);
app.frskyProtocol.ProcessSerialData(false);
app.Frequentjobs();
app.mw.SendRequest(app.MainRequestMethod);
if (!killme)
mHandler.postDelayed(update, app.RefreshRate);
}
};
protected void onCreate(Bundle savedInstanceState) {
EditTextPowerMeterAlarm = (EditText) mContext.findViewById(R.id.editTextPowerMeterAlarm);
EditTextSelectSettings = (EditText) mContext.findViewById(R.id.editTextSelectSettingNumber);
ButtonRxBIND = (Button) mContext.findViewById(R.id.buttonRXBIND);
EditTextSetSerialBoudRate = (EditText) mContext.findViewById(R.id.editTextSerialBoudRate);
EditTextMinThrottle = (EditText) mContext.findViewById(R.id.editTextMinThrottle);
EditTextMaxThrottle = (EditText) mContext.findViewById(R.id.editTextMaxThrottle);
EditTextMinCommand = (EditText) mContext.findViewById(R.id.editTextMinCommand);
EditTextFailsafeThrottle = (EditText) mContext.findViewById(R.id.editTextFailsafeThrottle);
EditTextVBatsScale = (EditText) mContext.findViewById(R.id.EditTextVBatScale);
EditTextBatWarning1 = (EditText) mContext.findViewById(R.id.EditTextBatWarning1);
EditTextBatWarning2 = (EditText) mContext.findViewById(R.id.EditTextBatWarning2);
EditTextBatCritical = (EditText) mContext.findViewById(R.id.EditTextBatCritical);
TextViewVolt = (TextView) mContext.findViewById(R.id.textViewVolt);
EditTextDeclination = (EditText) mContext.findViewById(R.id.editTextDeclination);
textViewArmedCount = (TextView) mContext.findViewById(R.id.textViewArmedCount);
if(!app.AdvancedFunctions){
((LinearLayout)mContext.findViewById(R.id.otherExtended)).setVisibility(View.GONE);
}
}
protected void onPause() {
mHandler.removeCallbacks(null);
killme = true;
}
protected void onResume() {
killme = false;
//mHandler.postDelayed(update, app.RefreshRate);
Read();
}
private void Read() {
app.mw.SendRequestMSP_MISC();
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
app.mw.ProcessSerialData(false);
EditTextPowerMeterAlarm.setText(String.valueOf(app.mw.intPowerTrigger));
EditTextSelectSettings.setText(String.valueOf(app.mw.confSetting));
EditTextMinThrottle.setText(String.valueOf(app.mw.minthrottle));
EditTextMaxThrottle.setText(String.valueOf(app.mw.maxthrottle));
EditTextMinCommand.setText(String.valueOf(app.mw.mincommand));
EditTextFailsafeThrottle.setText(String.valueOf(app.mw.failsafe_throttle));
EditTextVBatsScale.setText(String.valueOf(app.mw.vbatscale));
EditTextBatWarning1.setText(String.valueOf(app.mw.vbatlevel_warn1));
EditTextBatWarning2.setText(String.valueOf(app.mw.vbatlevel_warn2));
EditTextBatCritical.setText(String.valueOf(app.mw.vbatlevel_crit));
EditTextDeclination.setText(String.valueOf(app.mw.mag_decliniation));
textViewArmedCount.setText(String.valueOf(app.mw.armedNum));
}
public void BatteryVoltageRefreshOnClick(View v) {
TextViewVolt.setText(String.valueOf(app.mw.bytevbat / 10f) + "V");
}
public void DeclinationTakeFromPhoneOnClick(View v) {
EditTextDeclination.setText(String.valueOf(app.sensors.Declination));
}
public void MSP_MISC_CONFreadOnClick(View v) {
Read();
}
public void MagCalibrationOnClick(View v) {
app.mw.SendRequestMSP_MAG_CALIBRATION();
}
public void AccCalibrationOnClick(View v) {
app.mw.SendRequestMSP_ACC_CALIBRATION();
}
public void MSP_SET_MISC_CONF_WriteOnClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setMessage(mContext.getString(R.string.Continue)).setCancelable(false).setPositiveButton(mContext.getString(R.string.Yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
app.mw.SendRequestMSP_SET_MISC(Integer.parseInt(EditTextPowerMeterAlarm.getText().toString()), Integer.parseInt(EditTextMinThrottle.getText().toString()), Integer.parseInt(EditTextMaxThrottle.getText().toString()), Integer.parseInt(EditTextMinCommand.getText().toString()), Integer.parseInt(EditTextFailsafeThrottle.getText().toString()), Float.parseFloat(EditTextDeclination.getText().toString()), (byte) Integer.parseInt(EditTextVBatsScale.getText().toString()), (Float.parseFloat(EditTextBatWarning1.getText().toString())), (Float.parseFloat(EditTextBatWarning2.getText().toString())), (Float.parseFloat(EditTextBatCritical.getText().toString())));
app.mw.SendRequestMSP_EEPROM_WRITE();
Toast.makeText(mContext.getApplicationContext(), mContext.getString(R.string.Done), Toast.LENGTH_SHORT).show();
}
}).setNegativeButton(mContext.getString(R.string.No), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
public void WriteSelectSettingOnClick(View v) {
app.mw.SendRequestMSP_SELECT_SETTING(Integer.parseInt(EditTextSelectSettings.getText().toString()));
}
public void RXBINDOnClick(View v) {
app.mw.SendRequestMSP_BIND();
}
public void SetSerialBoudRateOnClick(View v) {
app.mw.SendRequestMSP_ENABLE_FRSKY();
// app.mw.SendRequestMSP_SET_SERIAL_BAUDRATE(Integer.parseInt(EditTextSetSerialBoudRate.getText().toString()));
app.mw.SendRequestMSP_SET_SERIAL_BAUDRATE(9600);
app.commMW.Close();
}
public void show() {
onCreate(null);
onResume();
}
}