Skip to content

Commit

Permalink
Merge branch 'PPM-Turnigy9x'
Browse files Browse the repository at this point in the history
  • Loading branch information
shauleiz committed Mar 8, 2016
2 parents 0761880 + 0b36b2c commit cd2237f
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 12 deletions.
154 changes: 148 additions & 6 deletions SPP4/trunk/Spp/SppProcess/SppProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,12 @@ void CSppProcess::StorePulse(UINT PulseLength, bool Negative)

#pragma endregion

// Walkera PPM or normal PPM?
// Walkera PPM, Turnigy 9X PPM or normal PPM?
if (avrage_separator > 90)
Type = MOD_TYPE_PPMW;
else
Type = MOD_TYPE_PPMW; // Walkera
else if (avrage_separator < 66)
Type = MOD_TYPE_PPMT; // Turnigy 9X
else
Type = MOD_TYPE_PPM;

return S_OK;// PPM OK
Expand Down Expand Up @@ -1094,13 +1096,21 @@ int CSppProcess::InitModulationMap(void)
m_ModulationMap.emplace(tmp.Type, tmp);

// PPM (Walkera)
tmp.func = [=] (int width, BOOL input) {this->ProcessPulseWK2401Ppm(width, input);};
tmp.func = [=](int width, BOOL input) {this->ProcessPulseWK2401Ppm(width, input); };
tmp.Name = MOD_NAME_PPMW;
tmp.Subtype = _T("PPM");
tmp.Subtype = _T("PPM");
tmp.Type = MOD_TYPE_PPMW;
tmp.Qreset = 25;
m_ModulationMap.emplace(tmp.Type, tmp);

// PPM (Turnigy 9X)
tmp.func = [=](int width, BOOL input) {this->ProcessPulseTurnigy9XPpm(width, input); };
tmp.Name = MOD_NAME_PPMT;
tmp.Subtype = _T("PPM");
tmp.Type = MOD_TYPE_PPMT;
tmp.Qreset = 25;
m_ModulationMap.emplace(tmp.Type, tmp);

// JR (PCM)
tmp.func = [=] (int width, BOOL input) {this->ProcessPulseJrPcm(width, input);};
tmp.Name = MOD_NAME_JR;
Expand Down Expand Up @@ -1540,6 +1550,138 @@ inline UINT CSppProcess::NormalizePulse(UINT Length)
}
//#endif
/*
Process Pulse for Turnigy 9X PPM
This is how it works:
Cycle: 22.46mS
Separator: 0.30mS-0.34mS - In Normalized values: 57.6-65.3
Data Pulse: 0.68mS , 1.18mS, 1.68mS (Min, Mid, Max) 130.56, 226.56, 322.56
*/
void CSppProcess::ProcessPulseTurnigy9XPpm(int width, BOOL input)
{

static int sync = 0;

int newdata; /* Current width in joystick values */
static int data[14]; /* Array of pulse widthes in joystick values */
static int datacount = 0; /* pulse index (corresponds to channel index) */
static int former_sync = 0;
static bool prev_sep = false;
char tbuffer[9];
static int i = 0;
static int PrevWidth[14]; /* array of previous width values */
static int last_separator_width = 0; /* Added to sypport PPM for Turngy 9x */

if (width < PPM_GLITCH)
return;

if (gDebugLevel >= 2 && gCtrlLogFile && !(_strtime_s(tbuffer, 10))/*&& !(i++%50)*/)
fprintf(gCtrlLogFile, "\n%s - ProcessPulseTurnigy9XPpm(width=%d, input=%d)", tbuffer, width, input);

/* If pulse is a separator then go to the next one */
if (width < PPMT_SEP || former_sync)
{
prev_sep = true;
former_sync = 0;
return;
last_separator_width = width; /* Added to sypport PPM for Turngy 9x */
};

// Two separators in a row is an error - resseting
if ((width < PPMT_SEP) && prev_sep)
{
prev_sep = true;
m_nChannels = 0;
datacount = 0;
return;
};


/* sync is detected at the end of a very long pulse (over 200 samples = 4.5mSec) */
if (/*sync == 0 && */width > PPMT_TRIG) {
sync = 1;
if (datacount)
m_PosUpdateCounter++;
m_nChannels = datacount;
datacount = 0;
former_sync = 1;
prev_sep = false;
return;
}

if (!sync)
return; /* still waiting for sync */

// Two long pulse in a row is an error - resseting
if (width > PPM_SEP)
{
if (!prev_sep)
{
m_nChannels = 0;
datacount = 0;
prev_sep = false;
return;
}
else
prev_sep = false;
};

// Cancel jitter
if (abs(PrevWidth[datacount] - width) < PPM_JITTER)
width = PrevWidth[datacount];
PrevWidth[datacount] = width;


/* convert pulse width in samples to joystick position values (newdata) */
if (input || m_JsChPostProc_selected != -1)
newdata = (int)(1024 - (width - PPMT_MIN) / (PPMT_MAX - PPMT_MIN) * 1024); /* JR */
else
newdata = (int)((width - PPMT_MIN) / (PPMT_MAX - PPMT_MIN) * 1024); /* Futaba */


/* Trim values into 0-1023 boundries */
if (newdata < 0) newdata = 0;
else if (newdata > 1023) newdata = 1023;

/* Update data - do not allow abrupt change */
if (data[datacount] - newdata > 100) data[datacount] -= 100;
else if (newdata - data[datacount] > 100) data[datacount] += 100;
else data[datacount] = (data[datacount] + newdata) / 2;


//if (input|| m_JsChPostProc_selected!=-1)
m_Position[datacount] = data[datacount]; /* JR - Assign data to joystick channels */
//else
// switch (datacount)
//{ // Futaba
//case 0: m_Position[1] = data[datacount]; break;/* Assign data to joystick channels */
//case 1: m_Position[2] = data[datacount]; break;/* Assign data to joystick channels */
//case 2: m_Position[0] = data[datacount]; break;/* Assign data to joystick channels */
//case 3: m_Position[3] = data[datacount]; break;/* Assign data to joystick channels */
//case 4: m_Position[4] = data[datacount]; break;/* Assign data to joystick channels */
//case 5: m_Position[5] = data[datacount]; break;/* Assign data to joystick channels */
//case 6: m_Position[6] = data[datacount]; break;/* Assign data to joystick channels */
//case 7: m_Position[7] = data[datacount]; break;/* Assign data to joystick channels */
//case 8: m_Position[8] = data[datacount]; break;/* Assign data to joystick channels */
//case 9: m_Position[9] = data[datacount]; break;/* Assign data to joystick channels */
//case 10: m_Position[10] = data[datacount]; break;/* Assign data to joystick channels */
//case 11: m_Position[11] = data[datacount]; break;/* Assign data to joystick channels */
//};

// Send Position and number of channels to the virtual joystick
Send2vJoy(m_nChannels, m_Position);

if (gDebugLevel >= 3 && gCtrlLogFile /*&& !(i++%50)*/)
fprintf(gCtrlLogFile, " data[%d]=%d", datacount, data[datacount]);

if (datacount == 11)
sync = 0; /* Reset sync after channel 12 */

datacount++;
return;

}

/*
Process Pulse for Walkera WK-2401 PPM
This is just a permiscuous PPM that does not follow the PPM standard
Expand All @@ -1557,7 +1699,7 @@ void CSppProcess::ProcessPulseWK2401Ppm(int width, BOOL input)
static int data[14]; /* Array of pulse widthes in joystick values */
static int datacount = 0; /* pulse index (corresponds to channel index) */
static int former_sync = 0;
char tbuffer [9];
char tbuffer[9];
static int i = 0;
static int PrevWidth[14]; /* array of previous width values */

Expand Down
15 changes: 14 additions & 1 deletion SPP4/trunk/Spp/SppProcess/SppProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,27 @@ typedef struct _DECODER_DETECT
// All values are in number of samples normalized to 192K samples per second
#define PW_FUTABA 27.5
#define PW_JR 31.95

// PPM Values (General)
#define PPM_MIN 96.0 // PPM minimal pulse width (0.5 mSec)
#define PPM_MAX 288.0 // PPM maximal pulse width (1.5 mSec)
#define PPM_TRIG 870.0 // PPM inter packet separator pulse ( = 4.5mSec)
#define PPM_SEP 95.0 // PPM inter-channel separator pulse - this is a maximum value that can never occur
#define PPM_GLITCH 21.0 // Pulses of this size or less are just a glitch
#define PPM_JITTER 5.0

// PPM Values (Walkera)
#define PPMW_MIN 78.4
#define PPMW_MAX 304.8
#define PPMW_TRIG 870.0 // PPM inter packet separator pulse ( = 4.5mSec)
#define PPMW_SEP 65.3
#define PPM_JITTER 5.0

// PPM Values (Turnigy 9x)
#define PPMT_MIN 130.56
#define PPMT_MAX 322.56
#define PPMT_TRIG 870.0 // PPM inter packet separator pulse ( = 4.5mSec)
#define PPMT_SEP 61.44

#define SANWA1_MIN 30
#define SANWA2_MIN 52.24
#define PCMW_SYNC 243.809
Expand Down Expand Up @@ -141,6 +152,8 @@ class /*SPPMAIN_API*/ CSppProcess {
void ProcessPulseWK2401Ppm(int width, BOOL input);
void ProcessPulseFutabaPpm(int width, BOOL input);
void ProcessPulseJrPpm(int width, BOOL input);
void ProcessPulseTurnigy9XPpm(int width, BOOL input);


void Send2vJoy(int nChannels, int *Channel);
int RunJsFilter(int * ch, int nChannels);
Expand Down
12 changes: 7 additions & 5 deletions SPP4/trunk/Spp/SppUI/SppDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ int SppDlg::InitTabs(HWND hDlg)
if (!m_hrsrc.hwndTab)
{
MessageBox(hDlg, CN_NO_TABCONTROL, CN_NO_TABCONTROL_HDR, MB_OK | MB_ICONERROR | MB_TOPMOST);
return 0;
return 0;
}

// Fix white background around tab icon
Expand All @@ -407,7 +407,7 @@ int SppDlg::InitTabs(HWND hDlg)
if (!GotRect)
{
MessageBox(hDlg, CN_NO_TABRECT, CN_NO_TABRECT_HDR, MB_OK | MB_ICONERROR | MB_TOPMOST);
return 0;
return 0;
}

// Create child dialogs and tabs
Expand Down Expand Up @@ -797,13 +797,13 @@ void SppDlg::SetStreamingState(BOOL isProcessingAudio)

// Show/Hide Tab control
int ShowState;
if (isProcessingAudio)
if (isProcessingAudio)
ShowState = SW_SHOW;
else
ShowState = SW_HIDE;

ShowWindow(GetDlgItem(m_hDlg, IDC_TABS), ShowState);

ShowWindow(GetDlgItem(m_hDlg, IDC_TABS), ShowState);


// Enable/Disable Info frame
EnableWindow(GetDlgItem(m_hDlg, IDS_AUDIO_SRC), isProcessingAudio);
Expand Down Expand Up @@ -911,6 +911,8 @@ LPCTSTR SppDlg::GetDecoderFullName(LPCTSTR Type)
return MOD_FNAME_PPMN;
if (!_tcscmp(Type, MOD_TYPE_PPMW))
return MOD_FNAME_PPMW;
if (!_tcscmp(Type, MOD_TYPE_PPMT))
return MOD_FNAME_PPMT;
if (!_tcscmp(Type,MOD_TYPE_JR))
return MOD_FNAME_JR;
if (!_tcscmp(Type,MOD_TYPE_FUT))
Expand Down
4 changes: 4 additions & 0 deletions SPP4/trunk/Spp/include/SmartPropoPlus.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extern "C"
#define MOD_TYPE_PPMP _T("PPMPOS")
#define MOD_TYPE_PPMN _T("PPMNEG")
#define MOD_TYPE_PPMW _T("PPMW")
#define MOD_TYPE_PPMT _T("PPMT9X")
#define MOD_TYPE_JR _T("JR")
#define MOD_TYPE_FUT _T("FUT")
#define MOD_TYPE_AIR1 _T("AIR1")
Expand All @@ -30,6 +31,7 @@ extern "C"
#define MOD_NAME_PPMP _T("Positive")
#define MOD_NAME_PPMN _T("Negative")
#define MOD_NAME_PPMW _T("Walkera")
#define MOD_NAME_PPMT _T("Turnigy 9X")
#define MOD_NAME_JR _T("JR/Graupner")
#define MOD_NAME_FUT _T("Futaba")
#define MOD_NAME_AIR1 _T("Sanwa/Airtronics [1]")
Expand All @@ -40,6 +42,7 @@ extern "C"
#define MOD_FNAME_PPMP _T("PPM (Positive)")
#define MOD_FNAME_PPMN _T("PPM (Negative)")
#define MOD_FNAME_PPMW _T("PPM (Walkera)")
#define MOD_FNAME_PPMT _T("PPM (Turnigy 9X)")
#define MOD_FNAME_JR _T("PCM - JR/Graupner")
#define MOD_FNAME_FUT _T("PCM - Futaba")
#define MOD_FNAME_AIR1 _T("PCM - Sanwa/Airtronics [1]")
Expand All @@ -52,6 +55,7 @@ extern "C"
MOD_TYPE_PPMP, MOD_NAME_PPMP,\
MOD_TYPE_PPMN, MOD_NAME_PPMN,\
MOD_TYPE_PPMW, MOD_NAME_PPMW,\
MOD_TYPE_PPMT, MOD_NAME_PPMT,\
MOD_TYPE_JR, MOD_NAME_JR,\
MOD_TYPE_FUT, MOD_NAME_FUT,\
MOD_TYPE_AIR1,MOD_NAME_AIR1,\
Expand Down

0 comments on commit cd2237f

Please sign in to comment.