counterform.cpp

来自「16 relay output channels and 16 isolated」· C++ 代码 · 共 187 行

CPP
187
字号
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "CounterForm.h"
#include "math.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmCounter *frmCounter;

extern USHORT  usCEnable, usCMatchEnable, usTrigEdge, usCOverflow;
extern USHORT usCPreset[8],usCMatchValue[8];
//---------------------------------------------------------------------------
__fastcall TfrmCounter::TfrmCounter(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TfrmCounter::chkBitEnable7Click(TObject *Sender)
{
    TCheckBox* chkBEbox[8] = {chkBitEnable0,chkBitEnable1,chkBitEnable2,chkBitEnable3,
                           chkBitEnable4,chkBitEnable5,chkBitEnable6,chkBitEnable7};
    TCheckBox* chkMEbox[8] = {chkMatchEnable0,chkMatchEnable1,chkMatchEnable2,chkMatchEnable3,
                           chkMatchEnable4,chkMatchEnable5,chkMatchEnable6,chkMatchEnable7};
    TCheckBox* chkOFbox[8] = {chkOverflow0,chkOverflow1,chkOverflow2,chkOverflow3,chkOverflow4,
                           chkOverflow5,chkOverflow6,chkOverflow7};
    TEdit* txtPvalue[8] = {txtPresetValue0,txtPresetValue1,txtPresetValue2,txtPresetValue3,
                           txtPresetValue4,txtPresetValue5,txtPresetValue6,txtPresetValue7};
    TRadioButton* rbtRise[8] = {optRising0,optRising1,optRising2,optRising3,optRising4,
                                optRising5,optRising6,optRising7};
    TRadioButton* rbtFall[8] = {optFalling0,optFalling1,optFalling2,optFalling3,
                                optFalling4,optFalling5,optFalling6,optFalling7};

    TCheckBox* chk = (TCheckBox*)(Sender);
    if(chk->Checked){
        for(int i=0; i<8; i++){
            if(chk == chkBEbox[i]){
                txtPvalue[i]->Enabled = True;
                chkMEbox[i]->Enabled = True;
                chkOFbox[i]->Enabled = True;
                rbtRise[i]->Enabled = True;
                rbtFall[i]->Enabled = True;
            }
        }
    }else{
        for(int i=0; i<8; i++){
            if(chk == chkBEbox[i]){
                txtPvalue[i]->Enabled = False;
                chkMEbox[i]->Enabled = False;
                chkOFbox[i]->Enabled = False;
                rbtRise[i]->Enabled = False;
                rbtFall[i]->Enabled = False;
            }
        }
    }


    //add code here
}
//---------------------------------------------------------------------------


void __fastcall TfrmCounter::chkMatchEnable7Click(TObject *Sender)
{
    TCheckBox* chkMEbox[8] = {chkMatchEnable0,chkMatchEnable1,chkMatchEnable2,chkMatchEnable3,
                           chkMatchEnable4,chkMatchEnable5,chkMatchEnable6,chkMatchEnable7};
    TEdit* txtMvalue[8] = {txtMatchValue0,txtMatchValue1,txtMatchValue2,txtMatchValue3,txtMatchValue4,
                           txtMatchValue5,txtMatchValue6,txtMatchValue7};

    TCheckBox* chk = (TCheckBox*)(Sender);
    if(chk->Checked){
        for(int i=0; i<8; i++){
            if(chk == chkMEbox[i]){
                txtMvalue[i]->Enabled = True;
            }
        }
    }else{
        for(int i=0; i<8; i++){
            if(chk == chkMEbox[i]){
                txtMvalue[i]->Enabled = False;
            }
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmCounter::cmdOkClick(TObject *Sender)
{
    TCheckBox* chkBEbox[8] = {chkBitEnable0,chkBitEnable1,chkBitEnable2,chkBitEnable3,
                           chkBitEnable4,chkBitEnable5,chkBitEnable6,chkBitEnable7};
    TCheckBox* chkMEbox[8] = {chkMatchEnable0,chkMatchEnable1,chkMatchEnable2,chkMatchEnable3,
                           chkMatchEnable4,chkMatchEnable5,chkMatchEnable6,chkMatchEnable7};
    TCheckBox* chkOFbox[8] = {chkOverflow0,chkOverflow1,chkOverflow2,chkOverflow3,chkOverflow4,
                           chkOverflow5,chkOverflow6,chkOverflow7};
    TEdit* txtPvalue[8] = {txtPresetValue0,txtPresetValue1,txtPresetValue2,txtPresetValue3,
                           txtPresetValue4,txtPresetValue5,txtPresetValue6,txtPresetValue7};
    TEdit* txtMvalue[8] = {txtMatchValue0,txtMatchValue1,txtMatchValue2,txtMatchValue3,txtMatchValue4,
                           txtMatchValue5,txtMatchValue6,txtMatchValue7};
    TRadioButton* rbtRise[8] = {optRising0,optRising1,optRising2,optRising3,optRising4,
                                optRising5,optRising6,optRising7};
    TRadioButton* rbtFall[8] = {optFalling0,optFalling1,optFalling2,optFalling3,
                                optFalling4,optFalling5,optFalling6,optFalling7};
    usCEnable = 0;
    usCMatchEnable = 0;
    usTrigEdge = 0;
    usCOverflow = 0;
    
    for(int i=0; i<8; i++){
        if(chkBEbox[i]->Checked){
            usCEnable |= (0x01<<i);
            usCPreset[i] = txtPvalue[i]->Text.ToDouble();
            if(chkMEbox[i]->Checked && chkMEbox[i]->Enabled){
                usCMatchEnable |= (0x01<<i);
                usCMatchValue[i] = txtMvalue[i]->Text.ToDouble();
            }
            if(chkOFbox[i]->Checked){
                usCOverflow |= (0x01<<i);
            }
            if(rbtRise[i]->Checked){
                usTrigEdge |= (0x01<<8);
            }else if(rbtFall[i]->Checked){
                usTrigEdge &= ~(0x01<<8);
            }
        }else{
            usCPreset[i] = 0;
            usCMatchValue[i] = 0;
        }
    }
    this->Close();
}
//---------------------------------------------------------------------------

void __fastcall TfrmCounter::cmdCancelClick(TObject *Sender)
{
    this->Close();        
}
//---------------------------------------------------------------------------

void __fastcall TfrmCounter::FormShow(TObject *Sender)
{
    TCheckBox* chkBEbox[8] = {chkBitEnable0,chkBitEnable1,chkBitEnable2,chkBitEnable3,
                           chkBitEnable4,chkBitEnable5,chkBitEnable6,chkBitEnable7};
    TCheckBox* chkMEbox[8] = {chkMatchEnable0,chkMatchEnable1,chkMatchEnable2,chkMatchEnable3,
                           chkMatchEnable4,chkMatchEnable5,chkMatchEnable6,chkMatchEnable7};
    TCheckBox* chkOFbox[8] = {chkOverflow0,chkOverflow1,chkOverflow2,chkOverflow3,chkOverflow4,
                           chkOverflow5,chkOverflow6,chkOverflow7};
    TEdit* txtPvalue[8] = {txtPresetValue0,txtPresetValue1,txtPresetValue2,txtPresetValue3,
                           txtPresetValue4,txtPresetValue5,txtPresetValue6,txtPresetValue7};
    TEdit* txtMvalue[8] = {txtMatchValue0,txtMatchValue1,txtMatchValue2,txtMatchValue3,txtMatchValue4,
                           txtMatchValue5,txtMatchValue6,txtMatchValue7};
    TRadioButton* rbtRise[8] = {optRising0,optRising1,optRising2,optRising3,optRising4,
                                optRising5,optRising6,optRising7};
    TRadioButton* rbtFall[8] = {optFalling0,optFalling1,optFalling2,optFalling3,
                                optFalling4,optFalling5,optFalling6,optFalling7};

    for(int i=0; i<8; i++){
        if(usCEnable & (USHORT)pow(2,i)){
            chkBEbox[i]->Checked = True;
            txtPvalue[i]->Enabled = True;
            txtPvalue[i]->Text = AnsiString(usCPreset[i]);
            chkMEbox[i]->Enabled = True;
            chkOFbox[i]->Enabled = True;
            rbtRise[i]->Enabled = True;
            rbtFall[i]->Enabled = True;
            if(usCMatchEnable &(USHORT)pow(2,i)){
                chkMEbox[i]->Checked = True;
                txtMvalue[i]->Enabled = True;
                txtMvalue[i]->Text = AnsiString(usCMatchValue[i]);
            }
            if(usCOverflow & (USHORT)pow(2,i)){
                chkOFbox[i]->Checked = True;
            }
            if(usTrigEdge & (USHORT)pow(2,i)){
                rbtRise[i]->Checked = True;
            }else{
                rbtFall[i]->Checked = True;
            }
        }
    }
        
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?