...
 
Commits (2)
......@@ -4,3 +4,5 @@ VStudio/.vs
VStudio/*.user
VStudio/*.opensdf
VStudio/*opendb
*.db
@../MakeTests.bat
......@@ -22,105 +22,167 @@ int _tmain(int argc, _TCHAR* argv[])
//-----------------------------------------
// ino PART
//-----------------------------------------
/*************************************************************
project: <DCC Accessory Decoder>
author: <Thierry PARIS>
description: <Test for UAD library, with one light, controled by Dcc.>
*************************************************************/
#include "UniversalAccessoryDecoder.h"
#include "binary.h"
//------------------------------------------------------------------------------
// SignalArduino declaration
class SignalArduino : public AccessoryLightMulti
{
public:
SignalArduino(DriverArduino *inpDriver, byte inNbLeds, int *inpPins, int inFirstPort = 0);
void SetupSignal(int inStartingDcc);
};
//------------------------------------------------------------------------------
// SignalArduino definition
SignalArduino::SignalArduino(DriverArduino *inpDriver, byte inNbLeds, int *inpPins, int inFirstPort) : AccessoryLightMulti(0, 0, inNbLeds, 0)
{
for (int led = 0; led < inNbLeds; led++)
{
inpDriver->SetupPortMotor(inFirstPort + led, inpPins[led], DIGITAL_INVERTED);
}
for (int led = 0; led < inNbLeds; led++)
{
// Led number is also port number...
this->SetupLight(led, inpDriver, inFirstPort + led, 255);
}
}
void SignalArduino::SetupSignal(int inStartingDcc)
{
this->Setup();
// Used dcc codes are
// Led 0 1 2
// inStartingDcc / 0 on off off
// inStartingDcc / 1 off on off
// inStartingDcc+1 / 0 off off on
// inStartingDcc+1 / 1 off off off
this->AdjustDccPositionsSize(this->GetSize() + 1);
int dcc = inStartingDcc;
bool etat = false;
for (int i = 0; i < this->GetSize(); i++)
{
if (!etat)
{
this->AddDccPosition(dcc, 0, 1 << i, 0);
etat = true;
}
else
{
this->AddDccPosition(dcc, 1, 1 << i, 0);
dcc++;
etat = false;
}
}
this->AddDccPosition(dcc, etat == true ? 1 : 0, 0, 0);
}
//------------------------------------------------------------------------------
// Classic INO area
/* kDCC_INTERRUPT values :
Board int.0 int.1 int.2 int.3 int.4 int.5
Uno, Ethernet 2 3
Mega2560 2 3 21 20 19 18
Leonardo 3 2 0 1 7
*/
#define kDCC_INTERRUPT 5
#define kDCC_INTERRUPT 0
#define NB_LEDS 3
#define NB_ETATS 3
#define NB_FEUX 1
SignalArduino* signaux[NB_FEUX];
int pins[][NB_ETATS] = {
{ 5, 6, 7 },
{ 8, 9, 10 },
{ 11, 12, 13 },
/*{ 14, 15, 16 },
{ 17, 18, 19 },
{ 20, 21, 22 },
{ 22, 23, 24 },
{ 25, 26, 27 },
{ 28, 29, 30 },
{ 31, 32, 33 },
{ 34, 35, 36 },
{ 37, 38, 39 },
{ 40, 41, 42 },
{ 43, 44, 45 },
{ 46, 47, 48 },
{ 49, 50, 51 }*/
};
// Accessories
Accessories accessories;
DccCommander dccCommander;
ButtonsCommander buttonsCommander;
// Drivers
DriverArduino *arduino;
//////////////////////////////////
//
// Setup
//
int dcc_codes[] = { 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 33, 34, 35, 36};
void setup()
{
UAD_StartSetup();
// Setup of the Dcc commander.
dccCommander.Setup(0x00, 0x00, kDCC_INTERRUPT);
dccCommander.SetStatusLedPin(13);
// Drivers setups
buttonsCommander.Setup(1, new ButtonsCommanderPush(NB_FEUX * NB_ETATS));
// Ce petit bouton va permettre de passer en revue tous les codes dcc des feux en squence...
int dcc = 0;
for (int feu = 0; feu < NB_FEUX; feu++)
{
PUSH(buttonsCommander, 0)->AddDccId(dcc_codes[dcc], 0);
PUSH(buttonsCommander, 0)->AddDccId(dcc_codes[dcc], 1);
PUSH(buttonsCommander, 0)->AddDccId(dcc_codes[dcc+1], 0);
}
PUSH(buttonsCommander, 0)->Setup(56); // port A2
// one light is connected to the arduino.
arduino = new DriverArduino(5, 0); // 1 motor/led, 0 servos
arduino = new DriverArduino(NB_LEDS * NB_FEUX, 0);
arduino->Setup();
arduino->SetupPortMotor(0, 4); // first port (0), pin 4
arduino->SetupPortMotor(1, 5); // first port (1), pin 5
arduino->SetupPortMotor(2, 6); // first port (2), pin 6
arduino->SetupPortMotor(3, 7); // first port (3), pin 7
arduino->SetupPortMotor(4, 8); // first port (4), pin 8
// Accessories setups
AccessoryLightMulti *pSignal = new AccessoryLightMulti(0, 0, 5, 1000); // dcc not significant here
// Assign Dcc code for each accessory.
accessories.Setup(1);
accessories.Add(pSignal);
// Attach each light to its driver/port.
pSignal->Setup();
pSignal->SetupLight(0, arduino, 0); // use port 0 of arduino driver
pSignal->SetupLight(1, arduino, 1); // use port 0 of arduino driver
pSignal->SetupLight(2, arduino, 2); // use port 0 of arduino driver
pSignal->SetupLight(3, arduino, 3); // use port 0 of arduino driver
pSignal->SetupLight(4, arduino, 4); // use port 0 of arduino driver
pSignal->AdjustDccPositionsSize(10);
pSignal->AddDccPosition(20, 0, B10000, B10000);
pSignal->AddDccPosition(21, 0, B01000, B01000);
pSignal->AddDccPosition(22, 0, B00100, B00100);
pSignal->AddDccPosition(23, 0, B00010, B00010);
pSignal->AddDccPosition(24, 0, B00001, B00001);
pSignal->AddDccPosition(25, 0, B10001, B10000);
pSignal->AddDccPosition(26, 0, B01001, B01000);
pSignal->AddDccPosition(27, 0, B00101, B00100);
pSignal->AddDccPosition(28, 0, B00011, B00010);
pSignal->AddDccPosition(29, 0, B00101, B00001);
UAD_EndSetup();
accessories.Setup(NB_FEUX);
for (int i = 0; i < pSignal->GetDccPositionSize(); i++)
for (int feu = 0; feu < NB_FEUX; feu++)
{
pSignal->Move(20 + i, 0);
signaux[feu] = new SignalArduino(arduino, NB_LEDS, pins[feu], feu * 3);
signaux[feu]->SetupSignal(dcc_codes[feu]);
accessories.Add(signaux[feu]);
}
unsigned long start = millis();
UAD_EndSetup();
while (millis() - start < 5000)
{
loop();
}
for (int i = 0; i < 10; i++)
{
accessories.DCCToggle(10, 0);
accessories.Loop();
delay(1000);
accessories.DCCToggle(10, 1);
accessories.Loop();
delay(1000);
accessories.DCCToggle(11, 0);
accessories.Loop();
delay(1000);
}
}
void loop()
{
// Dcc is run first, and if necessary, lets the accessories work.
if (dccCommander.Loop())
{
accessories.Loop();
buttonsCommander.Loop();
}
}
//-----------------------------------------
......
name=UniversalAccessoryDecoder
version=4.30
version=4.30.0
author=Thierry Paris - Locoduino
maintainer=https://git.framasoft.org/locoduino.org/UniversalAccessoryDecoder
sentence=This is a library for Arduino to handle accessories like lights, motors.
......
......@@ -20,12 +20,13 @@ AccessoryBaseLight::AccessoryBaseLight(Accessory *inpOwner)
void AccessoryBaseLight::SetState(ACC_STATE inState)
{
if (inState == LIGHTBLINK && this->blinkingDelay == 0)
inState = LIGHTON;
#ifdef DEBUG_MODE
Serial.print(F("AccessoryBaseLight SetState "));
Serial.println(inState == LIGHTON ? "ON" : inState == LIGHTOFF ? "OFF" : "BLINK");
#endif
if (inState == LIGHTBLINK && this->blinkingDelay == 0)
inState = LIGHTON;
this->state = inState;
}
......
......@@ -54,6 +54,16 @@ void AccessoryLightMulti::Setup()
unsigned char AccessoryLightMulti::AddDccPosition(int inDccIdMin, byte inDccIdAccessoryMin, int inOnMask, int inBlinkMask)
{
#ifdef DEBUG_MODE
Serial.print(F("AccessoryBaseLight: AddDccPosition "));
Serial.print(inDccIdMin);
Serial.print("/");
Serial.print(inDccIdAccessoryMin);
Serial.print(": ");
Serial.print(inOnMask, BIN);
Serial.print(" / ");
Serial.println(inBlinkMask, BIN);
#endif
unsigned char pos = Accessory::AddDccPosition(inDccIdMin, inDccIdAccessoryMin, inOnMask);
if (this->pDccPositionBlinks == 0)
......
////////////////////////////////////////////////////////
// Add a '//' at the beginning of the line to be in
// release mode.
//#define DEBUG_MODE
#define DEBUG_MODE
///////////////////////////////////////////////////////
// Verbose mode lets you see all actions done by the
......