diff --git a/Console.cpp b/Console.cpp index 80ccbe0a..c14caf45 100644 --- a/Console.cpp +++ b/Console.cpp @@ -288,17 +288,27 @@ void Console::ValueSet(int x, double y) if (iMode == 4) if (PoKeys55[0]) { - if (Global::fCalibrateOutMax[x] > 0) - { - y = y / Global::fCalibrateOutMax[x]; // sprowadzenie do <0,1> jeśli podana maksymalna wartość - y = Global::CutValueToRange(0, y, Global::fCalibrateOutMax[x]); - } - - PoKeys55[0]->PWM( - x, (((((Global::fCalibrateOut[x][5] * y) + Global::fCalibrateOut[x][4]) * y + + if (x == 7) + { + PoKeys55[0]->PoExtUpdate(8, y); + } // nbmx: wal kulakowy + else + { + if (Global::fCalibrateOutMax[x] > 0) + { + y = Global::CutValueToRange(0, y, Global::fCalibrateOutMax[x]); + y = y / Global::fCalibrateOutMax[x]; // sprowadzenie do <0,1> jeśli podana maksymalna wartość + } + double temp = (((((Global::fCalibrateOut[x][5] * y) + Global::fCalibrateOut[x][4]) * y + Global::fCalibrateOut[x][3]) * y + Global::fCalibrateOut[x][2]) * y + - Global::fCalibrateOut[x][1]) * y + - Global::fCalibrateOut[x][0]); // zakres <0;1> + Global::fCalibrateOut[x][1]) * y + + Global::fCalibrateOut[x][0] // zakres <0;1> + PoKeys55[0]->PWM(x, temp); + if (x == 6) + { + PoKeys55[0]->PoExtUpdate(9, temp); //dodatkowo hasler na PoExt + } + } } }; diff --git a/Console/PoKeys55.cpp b/Console/PoKeys55.cpp index d816a7ee..99e61136 100644 --- a/Console/PoKeys55.cpp +++ b/Console/PoKeys55.cpp @@ -34,7 +34,8 @@ TPoKeys55::TPoKeys55() fAnalog[0] = fAnalog[1] = fAnalog[2] = fAnalog[3] = fAnalog[4] = fAnalog[5] = fAnalog[6] = -1.0; iPWM[0] = iPWM[1] = iPWM[2] = iPWM[3] = iPWM[4] = iPWM[5] = iPWM[6] = 0; iPWM[7] = 4096; - iInputs[0] = 0; // czy normalnie są w stanie wysokim? + PoExt[0] = PoExt[1] = PoExt[2] = PoExt[3] = PoExt[4] = PoExt[5] = PoExt[6] = PoExt[7] = PoExt[8] = PoExt[9] = PoExt[10] = 0; + iInputs[0] = 0; // czy normalnie są w stanie wysokim? iRepeats = 0; bNoError = true; }; @@ -229,6 +230,30 @@ bool TPoKeys55::Write(unsigned char c, unsigned char b3, unsigned char b4, unsig return (BytesWritten == 65); // Read(); //odczyt trzeba zrobić inaczej - w tym miejscu będzie za szybko i nic się nie odczyta } + +bool TPoKeys55::PoExtWrite(unsigned char *c) +{ + DWORD BytesWritten = 0; + OutputBuffer[0] = 0; //The first byte is the "Report ID" and does not get transmitted over the USB bus. Always set=0. + OutputBuffer[1] = 0xBB; //0xBB - bajt rozpoznawczy dla PoKeys55 + OutputBuffer[2] = iLastCommand = 0xDA; //operacja: 0xDA PoExt + OutputBuffer[3] = 1; //1 = enable PoExt + OutputBuffer[4] = 0; // Connector selection 0: dedicated , 1: normal pins + OutputBuffer[5] = 0; + OutputBuffer[6] = 0; + OutputBuffer[7] = ++cRequest; //numer żądania + OutputBuffer[8] = 0; + for (int i = 0; i<10; ++i) + OutputBuffer[9 + i] = c[i]; + for (int i = 0; i<8; ++i) + OutputBuffer[8] += OutputBuffer[i]; //czy sumować też od 9 do 64? + //The basic Windows I/O functions WriteFile() and ReadFile() can be used to read and write to HID class USB devices + //(once we have the read and write handles to the device, which are obtained with CreateFile()). + //The following call to WriteFile() sends 64 bytes of data to the USB device. + WriteFile(WriteHandle, &OutputBuffer, 65, &BytesWritten, 0); //Blocking function, unless an "overlapped" structure is used + return (BytesWritten == 65); + //Read(); //odczyt trzeba zrobić inaczej - w tym miejscu będzie za szybko i nic się nie odczyta +} //--------------------------------------------------------------------------- bool TPoKeys55::Read() @@ -297,6 +322,13 @@ bool TPoKeys55::PWM(int x, float y) return true; } +bool TPoKeys55::PoExtUpdate(int x, char y) +{//ustawienie wskazanego PWM (@12Mhz: 12000=1ms=1000Hz) + //iPWM[7]=1024; //1024==85333.3333333333ns=11718.75Hz + PoExt[x] = y & 0x0FF; //0x0FF=256 + return true; +} + bool TPoKeys55::Update(bool pause) { // funkcja powinna być wywoływana regularnie, np. raz w każdej ramce ekranowej if (pause) @@ -353,10 +385,15 @@ bool TPoKeys55::Update(bool pause) case 3: // ustawienie wyjść analogowych, 0..4095 mapować na 0..65520 (<<4) if (Write(0x41, 43 - 1, (iPWM[6] >> 4), (iPWM[6] << 4))) // wysłanie ustawień iRepeats = 0; // informacja, że poszło dobrze - iFaza = 0; //++iFaza; //ta faza została zakończona + iFaza = 4; //++iFaza; //ta faza została zakończona // powinno jeszcze przyjść potwierdzenie o kodzie 0x41 break; - default: + case 4: //ustawienie + if (PoExtWrite(PoExt)) + iRepeats = 0; //informacja, że poszło dobrze + iFaza = 0; //++iFaza; //ta faza została zakończona + break; + default: iFaza = 0; // na wypadek, gdyby zbłądziło po jakichś zmianach w kodzie // iRepeats=0; } diff --git a/Console/PoKeys55.h b/Console/PoKeys55.h index 9815dead..7b08ac05 100644 --- a/Console/PoKeys55.h +++ b/Console/PoKeys55.h @@ -16,7 +16,8 @@ class TPoKeys55 unsigned char OutputBuffer[65]; // Allocate a memory buffer equal to our endpoint size + 1 unsigned char InputBuffer[65]; // Allocate a memory buffer equal to our endpoint size + 1 int iPWM[8]; // 0-5:wyjścia PWM,6:analogowe,7:częstotliwośc PWM - int iPWMbits; + char PoExt[10];// Wyjscia PoExt + int iPWMbits; int iLastCommand; int iFaza; int iRepeats; // liczba powtórzeń @@ -29,11 +30,13 @@ class TPoKeys55 bool Connect(); bool Close(); bool Write(unsigned char c, unsigned char b3, unsigned char b4 = 0, unsigned char b5 = 0); - bool Read(); + bool PoExtWrite(unsigned char *c); + bool Read(); bool ReadLoop(int i); AnsiString Version(); bool PWM(int x, float y); - bool Update(bool pause); + bool PoExtUpdate(int x, char y); + bool Update(bool pause); }; //--------------------------------------------------------------------------- #endif diff --git a/Train.cpp b/Train.cpp index 67c981fe..d10a4a2f 100644 --- a/Train.cpp +++ b/Train.cpp @@ -2789,16 +2789,15 @@ bool TTrain::Update() mvOccupied->Compressor); // Ra: sterowanie miernikiem: zbiornik główny Console::ValueSet(1, mvOccupied->PipePress); // Ra: sterowanie miernikiem: przewód główny - Console::ValueSet( - 2, mvOccupied->BrakePress); // Ra: sterowanie miernikiem: cylinder hamulcowy + Console::ValueSet(2, mvOccupied->BrakePress); // Ra: sterowanie miernikiem: cylinder hamulcowy Console::ValueSet(3, fHVoltage); // woltomierz wysokiego napięcia Console::ValueSet(4, fHCurrent[2]); // Ra: sterowanie miernikiem: drugi amperomierz - Console::ValueSet( - 5, + Console::ValueSet(5, fHCurrent[(mvControlled->TrainType & dt_EZT) ? 0 : 1]); // pierwszy amperomierz; dla // EZT prąd całkowity Console::ValueSet(6, fTachoVelocity); ////Ra: prędkość na pin 43 - wyjście - /// analogowe (to nie jest PWM); + Console::ValueSet(7, mvControlled->MainCtrlActualPos + mvControlled->ScndCtrlActualPos); //nbmx: Wal kulakowy + /// analogowe (to nie jest PWM); /// skakanie zapewnia mechanika /// napędu }