|
It happens. Actually this module what I'm doing is fairly complex, if the folks around me come to know I had stuck over this trivia, for sure they'd be puzzled, how I'm going to do the rest of the stuff. They wouldn't understand this phenomena!
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.
|
|
|
|
|
I can keep a secret if you can!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
If you divide these by 10, you map the range 0-9 to 0, 10-19 to 1, etc.
Then just check if that's even.
if ((x / 10 & 1) == 0)
else
|
|
|
|
|
Yup I've done the same way thanks
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.
|
|
|
|
|
for natural numbers just use: bool OK=number%20<10;
|
|
|
|
|
Wow another good thought! Feels great I wasn't a fool to think about a way through mod fn.
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.
|
|
|
|
|
Why is it that in this code which is in a button, when I click in the button to fill a row that is empty, instead of sending the message "Fill the empty cells", it selects the previous row and add it as a new line (it copies the row with the previous Id)? Thank you.
if (grid_lic.CurrentRow.Cells[1].Value.ToString() == "" || grid_lic.CurrentRow.Cells[2].Value.ToString() == "" || grid_lic.CurrentRow.Cells[6].Value.ToString() == "")
MessageBox.Show("Fill the empty cells");
else
{
dbcCommand Command = new OdbcCommand("insert into lojas (NIF, Loja, bloqueado, DataFim, lastupdate, Nome) values (?, ?, ?, ?, ?, ?)", connection);
Command.CommandType = CommandType.Text;
Command.Parameters.AddWithValue("@NIF", grid_lic.CurrentRow.Cells[1].Value);
Command.Parameters.AddWithValue("@Loja", grid_lic.CurrentRow.Cells[2].Value);
Command.Parameters.AddWithValue("@Bloqueado", checkBox_bloq.Checked);
Command.Parameters.AddWithValue("@DataFim", grid_lic.CurrentRow.Cells[4].Value);
Command.Parameters.AddWithValue("@lastupdate", grid_lic.CurrentRow.Cells[5].Value);
Command.Parameters.AddWithValue("@Nome", grid_lic.CurrentRow.Cells[6].Value);
connection.Open();
Command.ExecuteNonQuery();
modified 10-Dec-15 7:47am.
|
|
|
|
|
That would suggest that the empty row is not the current row.
Debug your code and check the CurrentRow property. Then work out why it's not pointing to the empty row.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That´s exactly the problem I described with other words. It is selecting the previous row, not the one where the mouse is clicked. But this only happens if the cell selected is empty, because if I write in the cell and click the button, that same row is the current row, not the previous one. That´s what the following code is telling:
MessageBox.Show(grid_lic.CurrentCell.ColumnIndex.ToString()); MessageBox.Show(grid_lic.CurrentCell.RowIndex.ToString());
I don't know where is the source of the problem. Any clue?
|
|
|
|
|
Sounds like the empty row doesn't become "current" until you start editing it.
Try checking the Selected property of the CurrentRow , which will probably be false . Also, check the SelectedRows collection to see if it contains the empty row.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The empty row belongs to the collection of SelectedRows, as this code which I ran selecting an empty row with index #4, confirms:
DataGridViewRow emptyrow = grid_lic.Rows[4];
if (grid_lic.SelectedRows.Contains(emptyrow))
MessageBox.Show("The row is empty!");
The Selected property of the CurrentRow is false:
if (grid_lic.Rows[4].Selected == false)
MessageBox.Show("False");
else
MessageBox.Show("True");
The problem was identified, I just don't know why it happens nor how to solve it. Any ideas?
Thank you.
|
|
|
|
|
Try something like this:
var row = grid_lic.CurrentRow;
if (row == null || !row.Selected)
{
if (grid_lic.SelectedRows.Count == 0)
{
MessageBox.Show("Select a row.");
return;
}
row = grid_lic.SelectedRows[0];
}
if (string.IsNullOrEmpty(Convert.ToString(row.Cells[1].Value))
|| string.IsNullOrEmpty(Convert.ToString(row.Cells[2].Value))
|| string.IsNullOrEmpty(Convert.ToString(row.Cells[6].Value)))
{
MessageBox.Show("Fill the empty cells");
return;
}
using (OdbcConnection connection = CreateConnection())
using (OdbcCommand command = new OdbcCommand("insert into lojas (NIF, Loja, bloqueado, DataFim, lastupdate, Nome) values (?, ?, ?, ?, ?, ?)", connection))
{
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("@NIF", row.Cells[1].Value);
command.Parameters.AddWithValue("@Loja", row.Cells[2].Value);
command.Parameters.AddWithValue("@Bloqueado", checkBox_bloq.Checked);
command.Parameters.AddWithValue("@DataFim", row.Cells[4].Value);
command.Parameters.AddWithValue("@lastupdate", row.Cells[5].Value);
command.Parameters.AddWithValue("@Nome", row.Cells[6].Value);
connection.Open();
command.ExecuteNonQuery();
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That code allows me to fill an empty row which is what I don't want, it just doesn't allow to add data when the row is not selected, even if the cells are filled.
|
|
|
|
|
I solved it this way:
if(!row.Selected)
{
if (grid_lic.SelectedRows.Count == 0)
{
MessageBox.Show("Select the row.");
return;
}
row = grid_lic.SelectedRows[0];
}
int i = grid_lic.SelectedRows[0].Index;
if (string.IsNullOrEmpty(Convert.ToString(grid_lic.Rows[i].Cells[1].Value)) || string.IsNullOrEmpty(Convert.ToString(grid_lic.CurrentRow.Cells[2].Value))
|| string.IsNullOrEmpty(Convert.ToString(grid_lic.CurrentRow.Cells[6].Value)))
{
MessageBox.Show("Preencha os campos vazios");
return;
}
using (OdbcConnection connection = CreateConnection())
{
OdbcCommand Command = new OdbcCommand("insert into lojas (NIF, Loja, bloqueado, DataFim, lastupdate, Nome) values (?, ?, ?, ?, ?, ?)", connection);
Command.CommandType = CommandType.Text;
Command.Parameters.AddWithValue("@NIF", grid_lic.CurrentRow.Cells[1].Value);
Command.Parameters.AddWithValue("@Loja", grid_lic.CurrentRow.Cells[2].Value);
Command.Parameters.AddWithValue("@Bloqueado", checkBox_bloq.Checked);
Command.Parameters.AddWithValue("@DataFim", grid_lic.CurrentRow.Cells[4].Value);
Command.Parameters.AddWithValue("@lastupdate", grid_lic.CurrentRow.Cells[5].Value);
Command.Parameters.AddWithValue("@Nome", grid_lic.CurrentRow.Cells[6].Value);
connection.Open();
Command.ExecuteNonQuery();
}
|
|
|
|
|
Richard is right; it is not the currently selected row, but the one you are editing.
Also would like to point out that X.ToString() will fail if X is null . I'd recommend "Convert.ToString(X)".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I have used Thread Thr = new Thread();
I do not SetFocus gridview1.FocusedRowHandle = i; it will warning: "Cross-thread operation not valid: Control 'gridControl1' accessed from a thread other than the thread it was created on."
you do not know how to fix this ?
|
|
|
|
|
because the grid is active on another thread so you will need to use a delegate to access the grid.
have a read of this Fill datagridview Column from different thread[^]
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
, 1, 1, 0, 0, 0, 0,
0, 1, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static INT sIsLastArrValid = 0;
#define RRINTERVAL_NUM 12
static INT16 sHeartRate;
static INT16 sRrIntervals[RRINTERVAL_NUM];
static INT sHrOfOneSecond;
static INT sInnerHeartRate, sInnerLastHeartRate;
static INT sPreviousMatched;
static INT sOutHR;
typedef struct{ UCHAR type; INT position; INT isSaved;} ARRSELECTED;
static ARRSELECTED sLastArrSelected;
static UINT32 sBlankLength = 0;
static INT sNotUpdatedTime = 0;
void ArrhythmiaAnalysis( void )
{
PaceStatistic();
arr_anal( );
if( 0 < gArrAnalysisInfo.ignoreResult )
{
gArrAnalysisInfo.arrCode = NML;
gStates.current = MAX_STATE;
gRGlobals.counter = 0;
}
}
void arr_anal( void )
{
INT i, ptr;
Frame pack;
if ( gEcgStatus.ecg1Exist
&& gEcgStatus.ecg2Exist )
{
i = ChannelAutoSelect(mod( gEcgBuffer.pos - ARR_SAMPLE_RATE , ECG_BUF_LENGTH));
}
else
{
if ( gEcgStatus.ecg1Exist )
i = ECG_CHANNEL_1;
else
i = ECG_CHANNEL_2;
}
if ( i != gArrConfig.arrChannel )
{
gArrConfig.arrChannel = i;
pack.id = ECGCHANNEL;
pack.data[0] = gArrConfig.arrChannel;
gProtocol.SendPack( pack );
}
gRDetEcgBuf = gEcgBuffer.channel[gArrConfig.arrChannel];
if( IsRelearnNeeded() == TRUE )
{
gArrAnalysisInfo.ignoreResult = 4;
EcgVarInit();
gQrsAnaInfo.inLearning = TRUE;
ResetSTAnalysis( );
sBlankLength = 0;
}
if(TRUE == gArrConfig.arrSelfLearn)
{
gQrsAnaInfo.inLearning = TRUE;
gArrConfig.arrSelfLearn = FALSE;
}
gTemplateSet.maxTemplate = MAX_TEMPLATE;
gRDetEcgBufPtr = gEcgBuffer.pos;
ECGProcess( ARR_SAMPLE_RATE );
#ifdef ENABLE_EXTRA_VFIB_DETECTION
CopyDiffData( ARR_SAMPLE_RATE );
#endif
gRGlobals.qrsDetected = 0;
if( IsNoise( ARR_SAMPLE_RATE ) )
{
gArrAnalysisInfo.arrCode = NOS;
gArrStatus.ecgAnalysisStatus = ECG_ANA_STATUS_NOISE;
gQrsAnaInfo.delay = 2;
gRGlobals.validRRi = 0;
gRGlobals.resetPeakDetect = 1;
gRGlobals.timePast = 0;
gStates.current = MAX_STATE;
gRGlobals.counter = 0;
if( gRGlobals.initialized == 0 )
EcgVarInit();
}
else
if( gQrsAnaInfo.delay > 0 )
{
gQrsAnaInfo.delay --;
gArrAnalysisInfo.arrCode = NML;
}
else
{
if( IsECGLost( ARR_SAMPLE_RATE ) )
{
gArrAnalysisInfo.arrCode = ASY;
gRGlobals.timePast = 0;
gQrsAnaInfo.isEcgLost = TRUE;
gRGlobals.validRRi = 0;
gRGlobals.resetPeakDetect = 1;
gStates.current = MAX_STATE;
gRGlobals.counter = 0;
if( gRGlobals.initialized == 0 )
EcgVarInit();
}
else
{
gQrsAnaInfo.isEcgLost = FALSE;
}
if( gRGlobals.initialized == 0 )
{
if( TRUE == gQrsAnaInfo.isEcgLost )
{
gRGlobals.initLength = 0;
gRGlobals.initialized = 0;
gRGlobals.qrsPtr = 0;
}
else
{
InitDetect( );
if( gRGlobals.initialized == 1 )
{
gArrStatus.ecgAnalysisStatus = ECG_ANA_STATUS_ARR_LRN;
}
else
gArrStatus.ecgAnalysisStatus = ECG_ANA_STATUS_QRS_LEARN;
}
}
else
{
if( gQrsAnaInfo.inLearning == TRUE && gTemplateSet.ready == 1 )
{
TemplateVarInit();
gArrStatus.ecgAnalysisStatus = ECG_ANA_STATUS_ARR_LRN;
}
if( FALSE == gQrsAnaInfo.isEcgLost)
QRSDetector( ARR_SAMPLE_RATE );
else
gRGlobals.qrsDetected = 0;
i = gRGlobals.qrsDetected - 1;
while( i >= 0 )
{
ptr = mod( gRGlobals.qrsPtr - i, MAX_QRS_NUM);
if( gQrsComplex[ptr].coef != INVALID_CORRCOEF )
{
break;
}
i --;
}
ArrhythmiaProcess( i+1 );
if( gQrsAnaInfo.inLearning == TRUE && gArrAnalysisInfo.arrCode != ASY )
{
gArrAnalysisInfo.arrCode = ARRLRN;
gArrStatus.ecgAnalysisStatus = ECG_ANA_STATUS_ARR_LRN;
}
}
if ( ( gQrsAnaInfo.isEcgLost
||( gRGlobals.timePast > _4SECONDS + _200MS) )
&& ASY != gArrAnalysisInfo.arrCode )
gArrStatus.ecgAnalysisStatus = ECG_ANA_STATUS_SIGNAL_TOO_SMALL;
}
gQrsAnaInfo.heartRate = InnerGetHeartRate();
gQrsAnaInfo.hrOfCurrSec = sHrOfOneSecond;
}
UCHAR ChannelAutoSelect( INT16 beginPos )
{
INT i;
for( i = 0; i < ECG_CHANNEL_MAX; i++ )
{
__Ddf1(gEcgBuffer.channel[i], gChannelAutoSelInfo.lpDifEcg[i], beginPos,
ARR_SAMPLE_RATE, ECG_BUF_LENGTH, ECG_BUF_LENGTH);
PulNum( gChannelAutoSelInfo.lpDifEcg[i], i );
}
ChSelectNum( ECG_CHANNEL_MAX );
return gChannelAutoSelInfo.byCurChNum;
}
void ChSelectNum( INT16 iChNum )
{
INT16 i;
INT16 pulseNum = 0;
if( iChNum == 1 )
return;
if( gChannelAutoSelInfo.byTimeDelay > 1 )
gChannelAutoSelInfo.byTimeDelay--;
else
gChannelAutoSelInfo.byTimeDelay = 0;
for( i = 0; i < iChNum; i++ )
{
if( i != gChannelAutoSelInfo.byCurChNum )
{
if( gChannelAutoSelInfo.byPulNum[gChannelAutoSelInfo.byCurChNum] != 0 )
{
if( gChannelAutoSelInfo.byPulNum[i] != 0 )
pulseNum = 1;
else
pulseNum = 0;
}
if( ( ( gChannelAutoSelInfo.byPulNum[i] < gChannelAutoSelInfo.byPulNum[gChannelAutoSelInfo.byCurChNum] ) && ( pulseNum == 1 ) )
|| ( ( gChannelAutoSelInfo.byPulNum[i] <= gChannelAutoSelInfo.byPulNum[gChannelAutoSelInfo.byCurChNum] )
&&( gChannelAutoSelInfo.iMaxDiff[i] > gChannelAutoSelInfo.iMaxDiff[gChannelAutoSelInfo.byCurChNum] ) )
|| ( gChannelAutoSelInfo.iMaxDiff[gChannelAutoSelInfo.byCurChNum] == 10 ) )
{
gChannelAutoSelInfo.byChgCount[i]++;
if( ( gChannelAutoSelInfo.byChgCount[i] > 10 ) && ( gChannelAutoSelInfo.byTimeDelay == 0 ) )
{
gChannelAutoSelInfo.byCurChNum = i;
gChannelAutoSelInfo.byChgCount[i] = 0;
}
}
else
gChannelAutoSelInfo.byChgCount[i] = 0;
}
}
return;
}
void PulNum( INT16 *lpDifEcg, INT16 iChNo)
{
INT16 i;
INT16 iCutLine;
gChannelAutoSelInfo.iMaxDiff[iChNo] = *lpDifEcg;
gChannelAutoSelInfo.byPulNum[iChNo] = 0;
for( i = 1; i < ARR_SAMPLE_RATE; i++)
{
if( *( lpDifEcg + i ) > gChannelAutoSelInfo.iMaxDiff[iChNo] )
gChannelAutoSelInfo.iMaxDiff[iChNo] = *( lpDifEcg + i );
}
iCutLine = gChannelAutoSelInfo.iMaxDiff[iChNo] / 3;
if( iCutLine < 10 )
iCutLine = 10;
for( i = 0; i < ARR_SAMPLE_RATE; i++ )
{
if( ( *( lpDifEcg + i ) > iCutLine ) && ( gChannelAutoSelInfo.byPassThdFlag[iChNo]== 0 ) )
{
gChannelAutoSelInfo.byPulNum[iChNo] ++;
gChannelAutoSelInfo.byPassThdFlag[iChNo] = 1;
}
else
{
if( *( lpDifEcg + i ) <= iCutLine )
gChannelAutoSelInfo.byPassThdFlag[iChNo] = 0;
}
}
if( gChannelAutoSelInfo.iMaxDiff[iChNo] < 10 )
gChannelAutoSelInfo.iMaxDiff[iChNo] = 10;
return;
}
INT IsRelearnNeeded( void )
{
return FALSE;
}
void ArrhythmiaProcess( INT qrsProcessed )
{
UCHAR arrCode;
INT i, ptr, position, isArrSelectedValid;
INT tmp, firstSaved;
ARRSELECTED arrSelected;
gRGlobals.qrsClassified = 0;
for( i = qrsProcessed - 1; i >= 0; i -- )
{
ptr = mod( gRGlobals.qrsPtr - i, MAX_QRS_NUM);
tmp = MorphClassify(
ptr,
gSysSetting.pace || (0 < gArrAnalysisInfo.ignoreResult)
);
if( tmp > 0 )
{
gRGlobals.qrsClassified += tmp;
gRGlobals.classifiedQrsPtr = ptr;
}
}
if( gSysSetting.pace || (0 < gArrAnalysisInfo.ignoreResult) )
{
for( i = gRGlobals.qrsClassified - 1; i >= 0; i -- )
{
ptr = mod( gRGlobals.classifiedQrsPtr - i, MAX_QRS_NUM);
gQrsComplex[ptr].type = QT_DOMINANT;
}
}
arrSelected.type = gArrAnalysisInfo.lastArrCode;
arrSelected.isSaved = 1;
isArrSelectedValid = 0;
firstSaved = 0;
for( i = gRGlobals.qrsClassified - 1; i >= 0; i -- )
{
ptr = mod( gRGlobals.classifiedQrsPtr - i, MAX_QRS_NUM);
if( gQrsComplex[ptr].type == QT_ABNORMAL )
gArrAnalysisInfo.pvcOfCurrentSecond ++;
arrCode = ArrhythmiaClassify( &gStates, ptr, &position );
if( arrCode != NON && position >= 0 )
{
if( gArrAnalysisInfo.lastArrCode == arrCode && sContinueAllowed[arrCode] )
{
if( sIsLastArrValid )
{
arrSelected.type = sLastArrSelected.type ;
arrSelected.position = sLastArrSelected.position ;
arrSelected.isSaved = 0;
firstSaved = 1;
sIsLastArrValid = 0;
isArrSelectedValid = 1;
}
else
if( !firstSaved )
{
arrSelected.type = arrCode ;
arrSelected.position = gQrsComplex[position].peakPos;
isArrSelectedValid = 1;
}
continue;
}
else
gArrAnalysisInfo.lastArrCode = arrCode;
if( sArrInfo[arrCode].warningLevel >= sArrInfo[arrSelected.type].warningLevel )
{
arrSelected.type = arrCode;
arrSelected.position = gQrsComplex[position].peakPos;
arrSelected.isSaved = 0;
firstSaved = 1;
isArrSelectedValid = 1;
}
else
if( arrCode != NML )
{
sLastArrSelected.type = arrCode;
sLastArrSelected.position = gQrsComplex[position].peakPos;
sIsLastArrValid = 1;
}
}
}
arrCode = NON;
if( ASYSTOLEDetect() == 1 )
{
arrCode = ASY;
}
else
if( (gArrAnalysisInfo.arrCode == ASY) && (arrSelected.type != ASY) )
{
arrSelected.type = NML;
isArrSelectedValid = 1;
}
#ifdef ENABLE_EXTRA_VFIB_DETECTION
if( VFIBDetect( ) == 1 )
{
arrCode = FIB;
}
#endif
#ifdef ENABLE_EXTRA_VFIB_DETECTION
if( arrCode == ASY || arrCode == FIB )
#else
if( arrCode == ASY )
#endif
{
arrSelected.type = arrCode;
arrSelected.position = mod( gEcgBuffer.pos - 4 * ARR_SAMPLE_RATE, ECG_BUF_LENGTH);
isArrSelectedValid = 1;
if( gArrAnalysisInfo.arrCode != arrCode )
{
arrSelected.isSaved = 0;
}
}
if( isArrSelectedValid )
{
gArrAnalysisInfo.arrCode = arrSelected.type;
gArrAnalysisInfo.position = arrSelected.position;
if( arrSelected.isSaved == 0 )
gArrAnalysisInfo.isSaved = 0;
}
if( gArrAnalysisInfo.arrCode <= 19 && gArrAnalysisInfo.isSaved == 0 )
{
i = mod( gArrAnalysisInfo.position - ARR_RECORD_SECONDS * ARR_SAMPLE_RATE, ECG_BUF_LENGTH);
i = mod( gEcgBuffer.pos - i , ECG_BUF_LENGTH );
if( i < ARR_RECORD_SECONDS * ARR_SAMPLE_RATE )
{
gArrAnalysisInfo.arrCode = NML;
}
}
}
CHAR IsECGLost( INT sample )
{
INT i, ptr;
ptr = mod(gRDetEcgBufPtr - sample, ECG_BUF_LENGTH);
for( i = 0; i < sample; i ++)
{
if( MWI_THRESHOLD >= *(gMWIBuf + ptr) )
{
sBlankLength ++;
}
else
{
sBlankLength = 0;
}
ptr = mod(ptr + 1, ECG_BUF_LENGTH);
}
if( ECGLOST_THRESHOLD < sBlankLength )
return TRUE;
else
return FALSE;
}
UCHAR ArrhythmiaClassify( STATES* states, INT qrsPtr, INT* eventQrsIndex )
{
INT arrCode, qrsIndex;
INT i, tmp, qrsNumber, ptr0, ptr1;
UCHAR type;
states->last = states->current;
if( gQrsComplex[qrsPtr].type == QT_ABNORMAL )
type = 1;
else
type = 0;
if( states->current <= MAX_STATE && states->current >= 0 )
{
states->current = sStateTransfer[states->current][type];
}
else
{
states->current = MAX_STATE;
}
states->ptr = mod( states->ptr + 1, QRS_SAVED );
states->rri[states->ptr] = gQrsComplex[qrsPtr].rri;
states->matched[states->ptr] = gQrsComplex[qrsPtr].matched;
states->qrsPtrs[states->ptr] = qrsPtr;
arrCode = sStateToArrType[states->current][0];
qrsIndex = sStateToArrType[states->current][1];
switch( arrCode )
{
case VPB:
if( states->averageRRi > _600MS )
{
i = mod( states->ptr - qrsIndex , QRS_SAVED );
if( ( (states->rri[i] * 10) <= (states->averageRRi * 5 ) )
&&(states->rri[mod(i+1,QRS_SAVED)] >= states->averageRRi* 5 / 4 ) )
{
arrCode = ROT;
}
}
break;
case NML:
if( states->current == 24 )
{
arrCode = TachBradyDetect( states );
}
break;
default:
break;
}
if( states->current >= 22 )
{
if( states->last == 8 )
qrsNumber = 2;
else
qrsNumber = 1;
ptr0 = mod( states->ptr - qrsNumber , QRS_SAVED );
ptr1 = mod( ptr0 + 1, QRS_SAVED );
for( i = 0; i < qrsNumber ; i ++ )
{
if( (states->rri[ptr0] < _4SECONDS )
&&(states->rri[ptr1] < states->averageRRi * 3 / 2 )
&&( (states->averageRRi > _600MS && states->rri[ptr0] > states->averageRRi * 7 / 4 )
|| (states->averageRRi < _600MS && states->rri[ptr0] > ( _1000MS - 4 ) )) )
{
arrCode = MIS;
ptr0 = mod( ptr0 - 1, QRS_SAVED );
*eventQrsIndex = states->qrsPtrs[ptr0];
if( TRUE == gSysSetting.pace )
{
tmp = mod( gEcgBuffer.pos - gQrsComplex[*eventQrsIndex].peakPos, ECG_BUF_LENGTH);
arrCode = PaceAnalysis( tmp, states->averageRRi );
}
break;
}
ptr0 = mod( ptr0 + 1, QRS_SAVED );
}
}
qrsNumber = sStateToArrType[states->current][2];
tmp = mod( states->ptr - qrsIndex, QRS_SAVED );
if( arrCode != MIS && arrCode != PNC && arrCode != PNP )
{
if( qrsNumber > 0 )
{
if( arrCode == TAC || arrCode == BRD )
*eventQrsIndex = states->qrsPtrs[mod(tmp - 5, QRS_SAVED)];
else
*eventQrsIndex = states->qrsPtrs[tmp];
}
else
*eventQrsIndex = -1;
}
for( i = 0; i < qrsNumber; i++)
{
if( states->matched[tmp] && states->matched[mod( tmp - 1, QRS_SAVED)] )
states->averageRRi = UpdateAveRRi( states->rri[tmp], states->averageRRi );
tmp = mod( tmp + 1, QRS_SAVED);
}
return arrCode;
}
UCHAR TachBradyDetect( STATES* states )
{
INT i, tmp, tmp1, ptr;
UCHAR arrCode;
static INT TACHY_LIMIT[3] = { ARR_SAMPLE_RATE/2+2, ARR_SAMPLE_RATE*3/8+2, ARR_SAMPLE_RATE*3/8+2 };
tmp = tmp1 = 0;
for(i = 0 ; i < 5; i ++)
{
ptr = mod( states->ptr - i , QRS_SAVED );
if( states->rri[ ptr ] <= TACHY_LIMIT[gSysSetting.patientType] )
{
tmp ++;
}
else
if( states->rri[ ptr ] >= (_1500MS - 2) )
{
tmp1 ++;
}
}
arrCode = NML;
if( tmp >= 5 )
arrCode = TAC;
else
if( tmp1 >= 5 )
arrCode = BRD;
return arrCode;
}
INT UpdateAveRRi( INT currentRRi, INT averageRRi )
{
if( ( (abs( currentRRi - averageRRi ) < averageRRi / 5)
&&(currentRRi > ARR_SAMPLE_RATE/2)
&&(currentRRi < ARR_SAMPLE_RATE*3/2) )
||( sNotUpdatedTime >= 3 ) )
{
averageRRi = (averageRRi * 7 + currentRRi) / 8;
sNotUpdatedTime = 0;
}
else
{
sNotUpdatedTime ++;
}
return averageRRi;
}
UCHAR ASYSTOLEDetect( void )
{
return gQrsAnaInfo.isEcgLost || (gRGlobals.timePast > _4SECONDS + _200MS) ;
}
INT16 __Ddf1( UCHAR *Ecg_buf, INT16* dif_buf, UINT Proc_begin,
UINT Proc_len, UINT Ecgbuf_len, UINT Ddfbuf_len )
{
INT16 i, n0;
INT16 ecgPos;
INT16 x0, x1, x2, x3;
INT16 fib;
if( (Proc_len > Ecgbuf_len) || (Proc_len > Ddfbuf_len) )
{
return(-1);
}
n0 = 0;
ecgPos = (Proc_begin - 4 + Ecgbuf_len)%Ecgbuf_len;
for( i = n0; i < (int)Proc_len; i++ )
{
x0 = ecgPos;
x1 = ( ecgPos + 1 ) ;
if( x1 >= (int)Ecgbuf_len ) x1 = x1 - Ecgbuf_len;
x2 = ( ecgPos + 3 );
if( x2 >= (int)Ecgbuf_len ) x2 = x2 - Ecgbuf_len;
x3 = ( ecgPos + 4 );
if( x3 >= (int)Ecgbuf_len ) x3 = x3 - Ecgbuf_len;
fib = ( *(Ecg_buf+x2) - *(Ecg_buf+x1)
+ 2 * (*(Ecg_buf+x3) - *(Ecg_buf+x0) ) ) >> 1;
if( Proc_len <= ARR_SAMPLE_RATE )
{
*( dif_buf + i ) = fib;
}
ecgPos = ( ecgPos + 1 );
if(ecgPos>=(int)Ecgbuf_len) ecgPos = 0 ;
}
return 1;
}
INT16 PVCStatistic( UCHAR* list, INT listSize, INT pvcNumber )
{
INT16 i, total;
total = pvcNumber;
for( i = listSize - 1; i > 0 ; i -- )
{
*( list + i ) = *( list + i - 1);
total += *( list + i );
}
*( list ) = pvcNumber;
return total;
}
#define _1200MS (ARR_SAMPLE_RATE+ARR_SAMPLE_RATE/5)
INT16 CalculateHeartRate( INT16 rrInterval )
{
INT i, max, min, total, rri, validRRI;
for( i = RRINTERVAL_NUM - 1; i > 0; i --)
{
sRrIntervals[i] = sRrIntervals[i-1];
}
sRrIntervals[0] = rrInterval;
if( (_1200MS <= sRrIntervals[0])
&& (_1200MS <= sRrIntervals[1])
&& (_1200MS <= sRrIntervals[2]) )
{
rri = 4;
}
else
rri = RRINTERVAL_NUM;
validRRI = 0;
for( i = 0; i < RRINTERVAL_NUM; i ++)
{
if ( 0 < sRrIntervals[i] )
validRRI ++;
}
if ( 5 > validRRI )
return sHeartRate;
total = 0;
max = 0;
min = 5120;
if (RRINTERVAL_NUM == rri)
rri = validRRI;
for( i = 0; i < rri; i ++)
{
if( sRrIntervals[i] > max )
max = sRrIntervals[i];
if( sRrIntervals[i] < min )
min = sRrIntervals[i];
total += sRrIntervals[i];
}
if( rri > 4 )
{
total -= min + max;
rri -= 2;
}
if( total != 0 )
{
sHeartRate = 600 * (INT32)rri * ARR_SAMPLE_RATE / total;
sHeartRate = ( sHeartRate + 4 ) / 10;
} else {
sHeartRate = -100;
}
return sHeartRate;
}
INT16 InnerGetHeartRate( void )
{
INT i, ptr;
INT sum_for_b2b_hr;
BOOL tmpCondition = FALSE;
tmpCondition = ( gRGlobals.timePast > _4SECONDS + _200MS );
if( TRUE == gQrsAnaInfo.isEcgLost
|| tmpCondition
|| gRGlobals.initialized == 0
|| gQrsAnaInfo.delay > 0 )
{
sInnerHeartRate = -100;
sHrOfOneSecond = -100;
}
else
{
sum_for_b2b_hr = 0;
for( i = gRGlobals.qrsDetected - 1 ; i >= 0; i -- )
{
ptr = mod(gRGlobals.qrsPtr - i, MAX_QRS_NUM);
if( sPreviousMatched && gQrsComplex[ptr].matched && gRGlobals.validRRi )
{
sInnerHeartRate = CalculateHeartRate( gQrsComplex[ptr].rri);
sum_for_b2b_hr += gQrsComplex[ptr].rri;
}
else
gRGlobals.validRRi = 1;
sPreviousMatched = gQrsComplex[ptr].matched;
}
if (0 < sum_for_b2b_hr)
{
sHrOfOneSecond = 600 * (INT32)gRGlobals.qrsDetected * ARR_SAMPLE_RATE / sum_for_b2b_hr;
sHrOfOneSecond = ( sHrOfOneSecond + 4 ) / 10;
}
}
if( sOutHR == 1 || sInnerLastHeartRate == -100 )
{
sInnerLastHeartRate = sInnerHeartRate;
sOutHR = 0;
}
else
{
sOutHR = 1;
}
return sInnerLastHeartRate;
}
#ifdef ENABLE_EXTRA_VFIB_DETECTION
void CopyDiffData( INT sample )
{
INT i, ptr, tmp;
ptr = mod( gRDetEcgBufPtr - sample , ECG_BUF_LENGTH );
for( i = 0; i < sample && i < ARR_SAMPLE_RATE; i ++)
{
tmp = *(gDiffBuf + ptr);
*( gVFibInfo.data + i ) = tmp;
if( tmp > 0 )
*( gVFibInfo.noiseDetBuf + i ) = tmp;
else
*( gVFibInfo.noiseDetBuf + i ) = 0;
ptr = mod( ptr + 1, ECG_BUF_LENGTH);
}
}
#endif
void ResetFlag( void )
{
gQrsAnaInfo.inLearning = FALSE;
gArrStatus.ecgAnalysisStatus = ECG_ANA_STATUS_NORMAL;
gArrAnalysisInfo.arrCode = NML;
gArrAnalysisInfo.lastArrCode = NML;
}
#define MINIMAL_CROSSPOINT 20
INT IsNoise( INT sample )
{
INT isNoise,crossPoint, slope;
isNoise = IsSaturation( sample );
isNoise |= ( PacePulseOfTheSecond() > PACE_NUM_ALLOWED );
if( !isNoise )
{
slope = gRGlobals.maxSlope / 4;
if( slope < MIN_NOISESLOPE )
slope = MIN_NOISESLOPE;
crossPoint = CrossPointNum(gLpDiffBuf, mod( gRDetEcgBufPtr - sample, ECG_BUF_LENGTH),
sample/2, slope );
if( crossPoint < MINIMAL_CROSSPOINT )
crossPoint = CrossPointNum(gLpDiffBuf, mod( gRDetEcgBufPtr - sample/2, ECG_BUF_LENGTH),
sample/2, slope );
isNoise = ( crossPoint >= MINIMAL_CROSSPOINT );
}
return isNoise;
}
#define SATURATION_HI 0xfd
#define SATURATION_LO 0x2
#define FASTCHANGE_TIME 5
#define FASTCHANGING 5
INT IsSaturation( INT sample )
{
INT i, ptr, delay, result;
INT numberFF, number00, fastChange;
UCHAR data;
numberFF = number00 = fastChange = 0;
delay = ARR_SAMPLE_RATE;
ptr = mod( gRDetEcgBufPtr - sample, ECG_BUF_LENGTH);
for( i = 0; i < sample; i++ )
{
data = *( gRDetEcgBuf + ptr );
ptr += 1;
if( ptr >= ECG_BUF_LENGTH )
ptr = 0;
if( data > SATURATION_HI )
{
numberFF ++;
if( delay < FASTCHANGING )
{
fastChange ++;
}
}
else
if( data < SATURATION_LO )
{
number00 ++;
delay = 0;
}
delay ++;
}
if( number00 > _200MS
|| numberFF > _200MS
|| fastChange > FASTCHANGE_TIME )
{
result = 1;
}
else
{
result = 0;
}
return result;
}
void InitStatics( void )
{
INT i;
sIsLastArrValid = 0;
sHeartRate = -100;
for (i = 0; i < RRINTERVAL_NUM; i ++)
sRrIntervals[i] = 0;
sHrOfOneSecond = -100;
sInnerHeartRate = -100;
sInnerLastHeartRate = -100;
sPreviousMatched = 1;
sOutHR = 0;
sLastArrSelected.type = NML;
sLastArrSelected.position = 0;
sLastArrSelected.isSaved = 1;
sBlankLength = 0;
sNotUpdatedTime = 0;
InitTompkinsStatic( );
}
INT PacePulseOfTheSecond( void )
{
INT pace_count, i;
pace_count = 0;
for( i = 0; i < MAX_PACE_NUM; i ++ )
{
if( gPaceEcg1Cnt[i] <= ARR_SAMPLE_RATE - 1 )
pace_count ++;
}
return pace_count;
}
|
|
|
|
|
And what precisely is your expectation here. You have just dumped a bunch of code in the forum.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I've GPL'd your code.
What was the question again?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Is this in any way related to the detection of obstructive sleep apnea through ECG signal features?
|
|
|
|
|
How I Can Make My Program With Multiple Language For Forms In C# ?
|
|
|
|
|
Do some research, this is the first entry[^] when I typed your question into Google.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Simply put, what would be more efficient?
If I make a program with lets say 20 images that are just solid colors, but put together to make custom controls, then those custom controls are used several times each, would that be as efficient as just creating panels with a solid BackColor?
Would they yield the same results in terms of RAM/CPU consumption? Would one be better then the other?
|
|
|
|
|