Skip to content

Commit

Permalink
Added GPIO buzzer & LED emulation
Browse files Browse the repository at this point in the history
  • Loading branch information
Witherflare committed Dec 25, 2023
1 parent be0d178 commit 7f77782
Show file tree
Hide file tree
Showing 67 changed files with 793 additions and 47 deletions.
2 changes: 1 addition & 1 deletion flight_data.txt

Large diffs are not rendered by default.

Binary file modified graphs/Altitude.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphs/Pitch.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphs/Roll.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphs/Temperature.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphs/X Acceleration.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphs/Y Acceleration.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphs/Z Acceleration.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<SubComponents>
<Component class="javax.swing.JTextArea" name="jTextArea1">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="columns" type="int" value="20"/>
<Property name="rows" type="int" value="5"/>
<Property name="text" type="java.lang.String" value="Welcome to C.W. Mission Control! This is your home base&#xa;and programming central for any Circuit Wizardry flight computers.&#xa;If you don&apos;t know where to start, check out the &quot;Docs&quot; button. If you&#xa;recently purchased a C.W. flight computer and want to tune it, check&#xa;out the &quot;Program&quot; button. If you just flew your flight computer and&#xa;are ready to gather flight data, check out &quot;Debrief&quot;."/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});

jTextArea1.setEditable(false);
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jTextArea1.setText("Welcome to C.W. Mission Control! This is your home base\nand programming central for any Circuit Wizardry flight computers.\nIf you don't know where to start, check out the \"Docs\" button. If you\nrecently purchased a C.W. flight computer and want to tune it, check\nout the \"Program\" button. If you just flew your flight computer and\nare ready to gather flight data, check out \"Debrief\".");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
package com.circuitwizardry.missioncontrol;

import com.fazecast.jSerialComm.SerialPort;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import static javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE;
import org.json.JSONObject;

/**
Expand All @@ -25,6 +28,15 @@ public ProgramConfirm(String c, SerialPort port) {
invalidJSON.setVisible(false);
codeFrame.setText(text);
this.port = port;

// DONT CLOSE ALL
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent event) {
dispose();
}
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,13 @@ private void connectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN

PyroCharge ejection = new PyroCharge(dataPanel, 0, "EJECTION", prev_data);
PyroCharge igniter = new PyroCharge(dataPanel, 1, "IGNITER", prev_data);
GPIO gp0 = new GPIO(dataPanel, 2, "GP0");
GPIO gp1 = new GPIO(dataPanel, 3, "GP1");
GPIO gp16 = new GPIO(dataPanel, 4, "GP16");
GPIO gp17 = new GPIO(dataPanel, 5, "GP17");
GPIO gp18 = new GPIO(dataPanel, 6, "GP18");
GPIO gp19 = new GPIO(dataPanel, 7, "GP19");
ThrustVectoring tvc = new ThrustVectoring(dataPanel, 8);
GPIO gp0 = new GPIO(dataPanel, 2, 0, "GP0", prev_data);
GPIO gp1 = new GPIO(dataPanel, 3, 1, "GP1", prev_data);
GPIO gp16 = new GPIO(dataPanel, 4, 16, "GP16", prev_data);
GPIO gp17 = new GPIO(dataPanel, 5, 17, "GP17", prev_data);
GPIO gp18 = new GPIO(dataPanel, 6, 18, "GP18", prev_data);
GPIO gp19 = new GPIO(dataPanel, 7, 19, "GP19", prev_data);
// ThrustVectoring tvc = new ThrustVectoring(dataPanel, 8);

features.add(ejection);
features.add(igniter);
Expand All @@ -324,7 +324,7 @@ private void connectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN
features.add(gp17);
features.add(gp18);
features.add(gp19);
features.add(tvc);
// features.add(tvc);

dataPanel.setPreferredSize(new Dimension(850, features.size() * 100));
dataPanel.revalidate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@
<Component class="javax.swing.JComboBox" name="actionSelector">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="2">
<StringArray count="3">
<StringItem index="0" value="&lt;none&gt;"/>
<StringItem index="1" value="Emulate Pyro Charge"/>
<StringItem index="2" value="Output"/>
</StringArray>
</Property>
</Properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.circuitwizardry.missioncontrol.features.pyro.*;
import com.circuitwizardry.missioncontrol.features.gpio.*;
import javax.swing.*;
import org.json.JSONArray;
import org.json.JSONObject;

/**
Expand All @@ -15,24 +16,75 @@
*/
public class GPIO extends Feature {

GPIOFeature selectedOption;
GPIOFeature selectedOption = new GPIOFeature();
int id;
boolean isLoading = true;
int pin = 0;
JSONObject data = new JSONObject();

/**
* Creates new form PyroCharge
* @param parent
* @param num
* @param identifier
*/
public GPIO(JPanel parent, int num, String identifier) {
public GPIO(JPanel parent, int num, int pin, String identifier, String prev_data) {
this.setSize(696, 100);
this.setLocation(0, num*100);
initComponents();
this.id = num;
this.pin = pin;
infoLabel.setText(identifier);

parent.add(this);
super.setVisible(true);

// figure out prev_data
JSONArray pyroData = new JSONObject(prev_data).getJSONArray("features");

JSONObject desiredObject = null;

for (int i = 0; i < pyroData.length(); i++) {
JSONObject obj = pyroData.getJSONObject(i);
if (obj.getInt("id") == id) {
desiredObject = obj;
break; // Exit the loop once the object is found
}
}

// Now you can use the desiredObject for further processing
try {
this.data = desiredObject.getJSONObject("data");
String type = this.data.getString("action");

switch (type) {
case "custom":
// Handle the case where type is "main"
System.out.println("Pyro Emulate found");
// Perform actions specific to the main pyro device
actionSelector.setSelectedIndex(1);
break;
case "output":
// Handle the case where type is "drogue"
System.out.println("Output found");
// Perform actions specific to the drogue pyro device
actionSelector.setSelectedIndex(2);
break;
case "input":
// Handle the case where type is "drogue"
System.out.println("Input found");
// Perform actions specific to the drogue pyro device
actionSelector.setSelectedIndex(3);
break;
default:
// Handle all other cases
System.out.println("Not detected");
// Perform actions appropriate for other types
actionSelector.setSelectedIndex(0);
}
} catch (org.json.JSONException e) {
actionSelector.setSelectedIndex(0);
}
}

@Override
Expand All @@ -41,6 +93,8 @@ public JSONObject generateJson() {
output.put("id", id);
output.put("type", "GPIO");

output.put("data", selectedOption.generateJson());

return output;
}

Expand All @@ -65,7 +119,7 @@ private void initComponents() {
jLabel2.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N
jLabel2.setText("Action:");

actionSelector.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "<none>", "Emulate Pyro Charge" }));
actionSelector.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "<none>", "Emulate Pyro Charge", "Output" }));
actionSelector.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
actionSelectorItemStateChanged(evt);
Expand Down Expand Up @@ -145,12 +199,13 @@ private void actionSelectorItemStateChanged(java.awt.event.ItemEvent evt) {//GEN
// Code to open pyro feature windows
if (selectedOption != null) {
selectedOption.setVisible(false);
selectedOption = new GPIOFeature();
}
if (actionSelector.getSelectedIndex() == 1) {
selectedOption = new EmulatePyro(this);
}
if (actionSelector.getSelectedIndex() == 2) {
selectedOption = new Output(this);
selectedOption = new Output(this, data, isLoading, pin);
}
if (actionSelector.getSelectedIndex() == 3) {
selectedOption = new Input(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
public class PyroCharge extends Feature {

PyroFeature selectedOption;
PyroFeature selectedOption = new PyroFeature();
JSONObject data = new JSONObject();
int id;
boolean isLoading = true;
Expand Down Expand Up @@ -50,10 +50,9 @@ public PyroCharge(JPanel parent, int num, String identifier, String prev_data) {
}
}

this.data = desiredObject.getJSONObject("data");

// Now you can use the desiredObject for further processing
if (desiredObject != null) {
try {
this.data = desiredObject.getJSONObject("data");
String type = this.data.getString("action");

switch (type) {
Expand Down Expand Up @@ -81,9 +80,8 @@ public PyroCharge(JPanel parent, int num, String identifier, String prev_data) {
// Perform actions appropriate for other types
actionSelector.setSelectedIndex(0);
}
} else {
// Handle the case where the object with the specified ID was not found
System.out.println("Object with ID " + id + " not found");
} catch (org.json.JSONException e) {
actionSelector.setSelectedIndex(0);
}

isLoading = false;
Expand Down Expand Up @@ -203,6 +201,7 @@ private void actionSelectorItemStateChanged(java.awt.event.ItemEvent evt) {//GEN

if (selectedOption != null) {
selectedOption.setVisible(false);
selectedOption = new PyroFeature();
}
if (actionSelector.getSelectedIndex() == 1) {
selectedOption = new MainChute(this, data, isLoading);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public boolean isInteger(String s) {
@Override
public JSONObject generateJson() {
JSONObject output = new JSONObject();
output.put("action", "other");
output.put("action", "custom");
output.put("trigger", jComboBox1.getSelectedIndex()+1);
output.put("value", custom.getText());
output.put("time", fireTime.getText());
output.put("value", Integer.parseInt(custom.getText()));
output.put("time", Integer.parseInt(fireTime.getText()));
// String output = "'trigger': " + (jComboBox1.getSelectedIndex()+1) + ", 'value': " + custom.getText() + ", 'time': " + fireTime.getText() + " }";
return output;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
*/
public class GPIOFeature extends JPanel {
public JSONObject generateJson() {
return new JSONObject("{}");
return new JSONObject("{\"action\": \"none\"}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<Component id="jComboBox1" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="298" max="32767" attributes="0"/>
<EmptySpace pref="318" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
Expand All @@ -47,10 +47,9 @@
<Component class="javax.swing.JComboBox" name="jComboBox1">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="3">
<StringArray count="2">
<StringItem index="0" value="&lt;none&gt;"/>
<StringItem index="1" value="Active Low"/>
<StringItem index="2" value="Active High"/>
<StringItem index="1" value="Button"/>
</StringArray>
</Property>
</Properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private void initComponents() {

jLabel1.setText("Input");

jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "<none>", "Active Low", "Active High" }));
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "<none>", "Button" }));

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
Expand All @@ -50,7 +50,7 @@ private void initComponents() {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(298, Short.MAX_VALUE))
.addContainerGap(318, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<Component id="jComboBox1" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="actionSelector" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="278" max="32767" attributes="0"/>
<EmptySpace pref="318" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
Expand All @@ -32,7 +32,7 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jComboBox1" min="-2" max="-2" attributes="0"/>
<Component id="actionSelector" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="40" max="32767" attributes="0"/>
</Group>
</Group>
Expand All @@ -44,17 +44,20 @@
<Property name="text" type="java.lang.String" value="Output"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="jComboBox1">
<Component class="javax.swing.JComboBox" name="actionSelector">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4">
<StringArray count="3">
<StringItem index="0" value="&lt;none&gt;"/>
<StringItem index="1" value="PREFAB: Buzzer"/>
<StringItem index="2" value="PREFAB: LED"/>
<StringItem index="3" value="PWM"/>
<StringItem index="1" value="Buzzer"/>
<StringItem index="2" value="LED"/>
</StringArray>
</Property>
</Properties>
<Events>
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="actionSelectorItemStateChanged"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="actionSelectorActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
Expand Down

0 comments on commit 7f77782

Please sign in to comment.