mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
PoKeys: dodanie wsparcia dla rozszerzeń PoExt
This commit is contained in:
30
Console.cpp
30
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
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user