Skip to content

Commit

Permalink
Merge pull request #84 from gcmcnutt/AlertPulse
Browse files Browse the repository at this point in the history
AlertPulse -- checkpoint
  • Loading branch information
dlktdr authored Mar 30, 2022
2 parents 06e6d76 + 58750b2 commit 127b323
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ Release/

# Compiled Output Folders, But include Zips
/gui/bin/*
/gui/build*
!/gui/bin/*.zip
48 changes: 35 additions & 13 deletions firmware/src/src/sense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,13 @@ void calculate_Thread()
* 5) Reset Center on PPM channel
* 6) Set auxiliary functions
* 7) Set analog channels
* 8) Override desired channels with pan/tilt/roll
* 9) Output to PPMout
* 10) Output to Bluetooth
* 11) Output to SBUS
* 12) Output PWM channels
* 13) Output to USB Joystick
* 8) Set Reset Center pulse channel
* 9) Override desired channels with pan/tilt/roll
* 10) Output to PPMout
* 11) Output to Bluetooth
* 12) Output to SBUS
* 13) Output PWM channels
* 14) Output to USB Joystick
*
* Channels should all be set to zero if they don't have valid data
* Only on the output should a channel be set to center if it's still zero
Expand Down Expand Up @@ -425,8 +426,29 @@ void calculate_Thread()
channel_data[trkset.analog7Ch()-1] = an7;
}

// 8) Set Tilt/Roll/Pan Channel Values
// Only set these outputs if button press mode is set to off
// 8) First decide if 'reset center' pulse should be sent

static float pulsetimer=0;
static bool sendingresetpulse = false;
int alertch = trkset.alertCh();
if (alertch > 0) {
// Synthesize a pulse indicating reset center started
channel_data[alertch - 1] = TrackerSettings::MIN_PWM;
if (butdnw) {
sendingresetpulse = true;
pulsetimer=0;
}
if (sendingresetpulse) {
channel_data[alertch - 1] = TrackerSettings::MAX_PWM;
pulsetimer += (float)CALCULATE_PERIOD / 1000000.0;
if(pulsetimer > TrackerSettings::RECENTER_PULSE_DURATION) {
sendingresetpulse = false;
}
}
}

// 9) Then, set Tilt/Roll/Pan Channel Values (after reset center in case of channel overlap)
// Only set these outputs if button press mode is set to off
if(trkset.buttonPressMode() == false)
trpOutputEnabled = true;

Expand All @@ -440,22 +462,22 @@ void calculate_Thread()
if(panch > 0)
channel_data[panch - 1] = trpOutputEnabled == true ? panout_ui : trkset.Pan_cnt();

// 9) Set the PPM Outputs
// 10) Set the PPM Outputs
for(int i=0;i<PpmOut_getChnCount();i++) {
uint16_t ppmout = channel_data[i];
if(ppmout == 0)
ppmout = TrackerSettings::PPM_CENTER;
PpmOut_setChannel(i,ppmout);
}

// 10) Set all the BT Channels, send the zeros don't center
// 11) Set all the BT Channels, send the zeros don't center
bool bleconnected=BTGetConnected();
trkset.setBLEAddress(BTGetAddress());
for(int i=0;i < BT_CHANNELS;i++) {
BTSetChannel(i,channel_data[i]);
}

// 11) Set all SBUS output channels, if disabled set to center
// 12) Set all SBUS output channels, if disabled set to center
uint16_t sbus_data[16];
for(int i=0;i<16;i++) {
uint16_t sbusout = channel_data[i];
Expand All @@ -465,7 +487,7 @@ void calculate_Thread()
}
SBUS_TX_BuildData(sbus_data);

// 12) Set PWM Channels
// 13) Set PWM Channels
for(int i=0;i<4;i++) {
int pwmch = trkset.PWMCh(i)-1;
if(pwmch >= 0 && pwmch < 16) {
Expand All @@ -476,7 +498,7 @@ void calculate_Thread()
}
}

// 13 Set USB Joystick Channels, Only 8 channels
// 14 Set USB Joystick Channels, Only 8 channels
static int joycnt=0;
if(joycnt++ == 1) {
set_JoystickChannels(channel_data);
Expand Down
14 changes: 14 additions & 0 deletions firmware/src/src/trackersettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ TrackerSettings::TrackerSettings()
tltch = DEF_TILT_CH;
rllch = DEF_ROLL_CH;
panch = DEF_PAN_CH;
alertch = DEF_ALERT_CH;

// Servo Reversed bits
servoreverse = 0x00;
Expand Down Expand Up @@ -415,6 +416,17 @@ void TrackerSettings::setRollCh(int value)
rllch = (int)value;
}

int TrackerSettings::alertCh() const
{
return alertch;
}

void TrackerSettings::setAlertCh(int value)
{
if((value > 0 && value < 17) || value == -1)
alertch = (int)value;
}

//----------------------------------------------------------------------------------------
// Remappable Buttons + PPM Output Pin + Bluetooth

Expand Down Expand Up @@ -770,6 +782,7 @@ void TrackerSettings::loadJSONSettings(DynamicJsonDocument &json)
v = json["rllch"]; if(!v.isNull()) setRollCh(v);
v = json["tltch"]; if(!v.isNull()) setTiltCh(v);
v = json["panch"]; if(!v.isNull()) setPanCh(v);
v = json["alertch"]; if(!v.isNull()) setAlertCh(v);

// Servo Reversed
v = json["servoreverse"]; if(!v.isNull()) setServoreverse(v);
Expand Down Expand Up @@ -954,6 +967,7 @@ void TrackerSettings::setJSONSettings(DynamicJsonDocument &json)
json["rllch"] = rllch;
json["panch"] = panch;
json["tltch"] = tltch;
json["alertch"] = alertch;

// Servo Reverse Channels
json["servoreverse"] = servoreverse;
Expand Down
7 changes: 6 additions & 1 deletion firmware/src/src/trackersettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class TrackerSettings
static constexpr bool DEF_RESET_ON_TILT = false;
static constexpr float RESET_ON_TILT_TIME = 1.5; // Seconds to complete a head tilt
static constexpr float RESET_ON_TILT_AFTER = 1.0; // How long after the tilt to reset
static constexpr float RECENTER_PULSE_DURATION = 0.5; // (sec) pulse width of recenter signal to tx
static constexpr int DEF_PPM_OUT = 10; // Random choice
static constexpr int DEF_PPM_IN = -1;
static constexpr int PPM_CENTER = 1500;
Expand All @@ -118,6 +119,7 @@ class TrackerSettings
static constexpr int DEF_TILT_CH = -1;
static constexpr int DEF_ROLL_CH = -1;
static constexpr int DEF_PAN_CH = -1;
static constexpr int DEF_ALERT_CH = -1;
static constexpr int DEF_LP_PAN = 75;
static constexpr int DEF_LP_TLTRLL = 75;
static constexpr int DEF_PWM_A0_CH = -1;
Expand Down Expand Up @@ -201,6 +203,9 @@ class TrackerSettings
int rollCh() const;
void setRollCh(int value);

int alertCh() const;
void setAlertCh(int value);

int ppmOutPin() const;
void setPpmOutPin(int value);

Expand Down Expand Up @@ -348,7 +353,7 @@ class TrackerSettings
int tlt_min,tlt_max,tlt_cnt;
int pan_min,pan_max,pan_cnt;
float rll_gain,tlt_gain,pan_gain;
int tltch,rllch,panch;
int tltch,rllch,panch,alertch;

// Calibration
float magxoff, magyoff, magzoff;
Expand Down
5 changes: 5 additions & 0 deletions gui/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->cmbpanchn,SIGNAL(currentIndexChanged(int)),this,SLOT(updateFromUI()));
connect(ui->cmbtiltchn,SIGNAL(currentIndexChanged(int)),this,SLOT(updateFromUI()));
connect(ui->cmbrllchn,SIGNAL(currentIndexChanged(int)),this,SLOT(updateFromUI()));
connect(ui->cmbalertchn,SIGNAL(currentIndexChanged(int)),this,SLOT(updateFromUI()));
connect(ui->cmbRemap,SIGNAL(currentIndexChanged(int)),this,SLOT(updateFromUI()));
connect(ui->cmbSigns,SIGNAL(currentIndexChanged(int)),this,SLOT(updateFromUI()));
connect(ui->cmbButtonPin,SIGNAL(currentIndexChanged(int)),this,SLOT(updateFromUI()));
Expand Down Expand Up @@ -573,6 +574,7 @@ void MainWindow::updateToUI()
int panCh = trkset.panCh();
int rllCh = trkset.rollCh();
int tltCh = trkset.tiltCh();
int alertCh = trkset.alertCh();
int a4Ch = trkset.analog4Ch();
int a5Ch = trkset.analog5Ch();
int a6Ch = trkset.analog6Ch();
Expand All @@ -589,6 +591,7 @@ void MainWindow::updateToUI()
ui->cmbpanchn->setCurrentIndex(panCh==-1?0:panCh);
ui->cmbrllchn->setCurrentIndex(rllCh==-1?0:rllCh);
ui->cmbtiltchn->setCurrentIndex(tltCh==-1?0:tltCh);
ui->cmbalertchn->setCurrentIndex(alertCh==-1?0:alertCh);
// Analog CH
ui->cmbA4Ch->setCurrentIndex(a5Ch==-1?0:a4Ch);
ui->cmbA5Ch->setCurrentIndex(a5Ch==-1?0:a5Ch);
Expand Down Expand Up @@ -684,9 +687,11 @@ void MainWindow::updateFromUI()
int panCh = ui->cmbpanchn->currentIndex();
int rllCh = ui->cmbrllchn->currentIndex();
int tltCh = ui->cmbtiltchn->currentIndex();
int alertCh = ui->cmbalertchn->currentIndex();
trkset.setPanCh(panCh==0?-1:panCh);
trkset.setRollCh(rllCh==0?-1:rllCh);
trkset.setTiltCh(tltCh==0?-1:tltCh);
trkset.setAlertCh(alertCh==0?-1:alertCh);
trkset.setRollReversed(ui->chkrllrev->isChecked());
trkset.setPanReversed(ui->chkpanrev->isChecked());
trkset.setTiltReversed(ui->chktltrev->isChecked());
Expand Down
120 changes: 111 additions & 9 deletions gui/src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@
<string>General</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_12">
<item row="6" column="0">
<item row="7" column="0">
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -575,7 +575,7 @@
</property>
</spacer>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QSpinBox" name="spnLPTiltRoll">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
Expand Down Expand Up @@ -606,7 +606,7 @@
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<item row="3" column="1" colspan="2">
<layout class="QGridLayout" name="gridLayout_7">
<item row="1" column="0">
<widget class="QLabel" name="label_45">
Expand Down Expand Up @@ -677,14 +677,14 @@
</item>
</layout>
</item>
<item row="5" column="0" colspan="2">
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="chkResetCenterWave">
<property name="text">
<string>Center on Proximity Detect (BLE Sense Only)</string>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
Expand All @@ -697,7 +697,7 @@
</property>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
Expand Down Expand Up @@ -774,7 +774,7 @@
</item>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_15">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
Expand All @@ -787,7 +787,7 @@
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="QSpinBox" name="spnLPPan">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
Expand Down Expand Up @@ -831,7 +831,109 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="1" column="0">
<widget class="QLabel" name="alertSignal">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Send Recenter on Chan</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="cmbalertchn">
<item>
<property name="text">
<string>Off</string>
</property>
</item>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>3</string>
</property>
</item>
<item>
<property name="text">
<string>4</string>
</property>
</item>
<item>
<property name="text">
<string>5</string>
</property>
</item>
<item>
<property name="text">
<string>6</string>
</property>
</item>
<item>
<property name="text">
<string>7</string>
</property>
</item>
<item>
<property name="text">
<string>8</string>
</property>
</item>
<item>
<property name="text">
<string>9</string>
</property>
</item>
<item>
<property name="text">
<string>10</string>
</property>
</item>
<item>
<property name="text">
<string>11</string>
</property>
</item>
<item>
<property name="text">
<string>12</string>
</property>
</item>
<item>
<property name="text">
<string>13</string>
</property>
</item>
<item>
<property name="text">
<string>14</string>
</property>
</item>
<item>
<property name="text">
<string>15</string>
</property>
</item>
<item>
<property name="text">
<string>16</string>
</property>
</item>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="chkLngBttnPress">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This function allows you to enable the tilt/roll/pan outputs after a long press of the reset button. Another long press will disable the output&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
Expand Down
Loading

0 comments on commit 127b323

Please sign in to comment.