mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 08:06:13 +01:00
Send onoff packets from setAccessory
This commit is contained in:
parent
17fb921678
commit
d3b72dc4fc
20
DCC.cpp
20
DCC.cpp
|
@ -8,7 +8,7 @@
|
||||||
* © 2020-2021 Chris Harlow
|
* © 2020-2021 Chris Harlow
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This file is part of Asbelos DCC API
|
* This file is part of DCC-EX
|
||||||
*
|
*
|
||||||
* This is free software: you can redistribute it and/or modify
|
* This is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -229,7 +229,12 @@ uint32_t DCC::getFunctionMap(int cab) {
|
||||||
return (reg<0)?0:speedTable[reg].functions;
|
return (reg<0)?0:speedTable[reg].functions;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DCC::setAccessory(int address, byte port, bool gate) {
|
void DCC::setAccessory(int address, byte port, bool gate, byte onoff /*= 2*/) {
|
||||||
|
// onoff is tristate:
|
||||||
|
// 0 => send off packet
|
||||||
|
// 1 => send on packet
|
||||||
|
// >1 => send both on and off packets.
|
||||||
|
|
||||||
// An accessory has an address, 4 ports and 2 gates (coils) each. That's how
|
// An accessory has an address, 4 ports and 2 gates (coils) each. That's how
|
||||||
// the initial decoders were orgnized and that influenced how the DCC
|
// the initial decoders were orgnized and that influenced how the DCC
|
||||||
// standard was made.
|
// standard was made.
|
||||||
|
@ -244,15 +249,20 @@ void DCC::setAccessory(int address, byte port, bool gate) {
|
||||||
byte b[2];
|
byte b[2];
|
||||||
|
|
||||||
// first byte is of the form 10AAAAAA, where AAAAAA represent 6 least signifcant bits of accessory address
|
// first byte is of the form 10AAAAAA, where AAAAAA represent 6 least signifcant bits of accessory address
|
||||||
// second byte is of the form 1AAACPPG, where C should be 1, PP the ports and G the gate
|
// second byte is of the form 1AAACPPG, where C is 1 for on, PP the ports 0 to 3 and G the gate (coil).
|
||||||
b[0] = address % 64 + 128;
|
b[0] = address % 64 + 128;
|
||||||
b[1] = ((((address / 64) % 8) << 4) + (port % 4 << 1) + gate % 2) ^ 0xF8;
|
b[1] = ((((address / 64) % 8) << 4) + (port % 4 << 1) + gate % 2) ^ 0xF8;
|
||||||
|
if (onoff != 0) {
|
||||||
DCCWaveform::mainTrack.schedulePacket(b, 2, 3); // Repeat the packet three times
|
DCCWaveform::mainTrack.schedulePacket(b, 2, 3); // Repeat on packet three times
|
||||||
#if defined(EXRAIL_ACTIVE)
|
#if defined(EXRAIL_ACTIVE)
|
||||||
RMFT2::activateEvent(address<<2|port,gate);
|
RMFT2::activateEvent(address<<2|port,gate);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
if (onoff != 1) {
|
||||||
|
b[1] &= ~0x08; // set C to 0
|
||||||
|
DCCWaveform::mainTrack.schedulePacket(b, 2, 3); // Repeat off packet three times
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// writeCVByteMain: Write a byte with PoM on main. This writes
|
// writeCVByteMain: Write a byte with PoM on main. This writes
|
||||||
|
|
2
DCC.h
2
DCC.h
|
@ -66,7 +66,7 @@ public:
|
||||||
static int getFn(int cab, int16_t functionNumber);
|
static int getFn(int cab, int16_t functionNumber);
|
||||||
static uint32_t getFunctionMap(int cab);
|
static uint32_t getFunctionMap(int cab);
|
||||||
static void updateGroupflags(byte &flags, int16_t functionNumber);
|
static void updateGroupflags(byte &flags, int16_t functionNumber);
|
||||||
static void setAccessory(int aAdd, byte aNum, bool activate);
|
static void setAccessory(int address, byte port, bool gate, byte onoff = 2);
|
||||||
static bool writeTextPacket(byte *b, int nBytes);
|
static bool writeTextPacket(byte *b, int nBytes);
|
||||||
|
|
||||||
// ACKable progtrack calls bitresults callback 0,0 or -1, cv returns value or -1
|
// ACKable progtrack calls bitresults callback 0,0 or -1, cv returns value or -1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user