Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/stl 1 fraction medic box #1

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
27 changes: 24 additions & 3 deletions MBSmartMedic.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class TempMedicBox : public MedicBox
TempMedicBox(Device* aDevice, int aliveTime, int stunTime)
: MedicBox(aDevice) {
this->aliveTime = aliveTime;
this->stunTime = stunTime < 10*60 ? stunTime : 10*60-1;
//reason for it ? TODO very strange bug with changing stun time value
this->stunTime = stunTime < 30*60 ? stunTime : 30*60;
}

virtual void reset() {
Expand All @@ -101,8 +102,21 @@ class TempMedicBox : public MedicBox
}
updateTime();
}


/**
* Send specific mlt protocol command.
* Required for execute specific command via medic button.
* Main target - extended S.L.K.E.R.T.A.G. support.
*
* @author Anton Karasev
* @param cmd mlt command
*/
virtual void processCommand(mlt_command* cmd) {
if(alive) {
sendCommand(*cmd);
delay(300);
}
updateTime();
}

virtual void updateTime() {
Expand All @@ -125,7 +139,14 @@ class TempMedicBox : public MedicBox
device->showStatusText(" Ready! ");
}
} else {
device->showTimeInterval(((long)timeLeft*100/60)*10, " Waiting... ");
// minutes left (current minute included)
if(timeLeft > 60) {
device->showTimerNumber(timeLeft/60 + 1, " Waiting(min) ");
}
// seconds left (in last minute)
else {
device->showTimerNumber(timeLeft, " Waiting(sec) ");
}
}
device->preventSleep(2000);
}
Expand Down
26 changes: 25 additions & 1 deletion MedicBox.ino
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,31 @@ void loop() {
} else if ( IsValidCmd(cmd) ) {
medic->processCommand(&cmd);
} else if (btnPressed) {
medic->processButton();
mlt_command respawnCmd; // how about memory
if ((ModeType)config->getMenuMode() == ModeTempMedicGreen1_30 /* Freedom base e.g. */ ) {
respawnCmd.command_type = MLT_CT_RESPAWN;
respawnCmd.cmd_data = MLT_CLR_GREEN;
respawnCmd.package_end = MLT_END_GREEN;
medic->processCommand(&respawnCmd);
} else if ((ModeType)config->getMenuMode() == ModeTempMedicRed1_30 /* Dept base e.g. */ ) {
respawnCmd.command_type = MLT_CT_RESPAWN;
respawnCmd.cmd_data = MLT_CLR_RED;
respawnCmd.package_end = MLT_END_RED;
medic->processCommand(&respawnCmd);
} else if ((ModeType)config->getMenuMode() == ModeTempMedicBlue1_30 /* Merc base e.g. */ ) {
respawnCmd.command_type = MLT_CT_RESPAWN;
respawnCmd.cmd_data = MLT_CLR_BLUE;
respawnCmd.package_end = MLT_END_BLUE;
medic->processCommand(&respawnCmd);
} else if ((ModeType)config->getMenuMode() == ModeTempMedicRedTest1_01 /* Quick test */ ) {
respawnCmd.command_type = MLT_CT_RESPAWN;
respawnCmd.cmd_data = MLT_CLR_RED;
respawnCmd.package_end = MLT_END_RED;
medic->processCommand(&respawnCmd);
}
else {
medic->processButton();
}
} else {
medic->updateTime();
}
Expand Down
31 changes: 31 additions & 0 deletions ModeMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ enum ModeType : char {
ModeTempMedic05_5,
ModeTempMedic1_5,
ModeTempMedic1_10,
ModeTempMedic1_20,
ModeTempMedic1_30,
ModeTempMedicGreen1_30,
ModeTempMedicRed1_30,
ModeTempMedicBlue1_30,
ModeTempMedicRedTest1_01,
#endif

#if MODE_TEMP_ALIVE_MEDIC
Expand Down Expand Up @@ -173,6 +179,19 @@ class ModeMenu
return new TempMedicBox(device, 1*60, 5*60);
case ModeTempMedic1_10:
return new TempMedicBox(device, 1*60, 10*60);
case ModeTempMedic1_20:
return new TempMedicBox(device, 1*60, 20*60);
case ModeTempMedic1_30:
return new TempMedicBox(device, 1*60, 30*60);
case ModeTempMedicGreen1_30:
return new TempMedicBox(device, 1*60, 30*60);
case ModeTempMedicRed1_30:
return new TempMedicBox(device, 1*60, 30*60);
case ModeTempMedicBlue1_30:
return new TempMedicBox(device, 1*60, 30*60);
//Test mode for quick test compatibility with colored respawn
case ModeTempMedicRedTest1_01:
return new TempMedicBox(device, 1*60, 1);
#endif

#if MODE_TEMP_ALIVE_MEDIC
Expand Down Expand Up @@ -240,6 +259,18 @@ class ModeMenu
return "Temp Medic 1/5";
case ModeTempMedic1_10:
return "Temp Medic 1/10";
case ModeTempMedic1_20:
return "Temp Medic 1/20";
case ModeTempMedic1_30:
return "Temp Medic 1/30";
case ModeTempMedicGreen1_30:
return "Temp Medic Green 1/30";
case ModeTempMedicRed1_30:
return "Temp Medic Red 1/30";
case ModeTempMedicBlue1_30:
return "Temp Medic Blue 1/30";
case ModeTempMedicRedTest1_01:
return "Temp Medic Red 1/01";
#endif

#if MODE_TEMP_ALIVE_MEDIC
Expand Down
4 changes: 2 additions & 2 deletions mlt_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// half cycle period: T/2 = 8.93 µs

// assuming carrier_interval_delay + instructions_delay = T/2
#define CARRIER_INTERVAL 4 // adjusted experimentally
#define CARRIER_INTERVAL 5 // adjusted experimentally


// MilesTag definitions
Expand Down Expand Up @@ -199,7 +199,7 @@ void sendCommand(mlt_command cmd) {
sendHeader();
sendByte(cmd.command_type, 8);
sendByte(cmd.cmd_data, 8);
sendByte(0xE8, 8);
sendByte(cmd.package_end, 8);
}
}

Expand Down
24 changes: 23 additions & 1 deletion mlt_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum mlt_command_type : uint8_t {
MLT_CT_INVALID = 0,
MLT_CT_SHOT = 1,
MLT_CT_SYSTEM = 0x83,
MLT_CT_RESPAWN = 0xB4,//0xA9,
};

enum mlt_team_color : uint8_t {
Expand Down Expand Up @@ -86,17 +87,38 @@ enum mlt_system_command : uint8_t {
MLT_SC_DOUBLE_HEALTH = 0x22, // LW extension
};

/**
* LASERWAR protocol supports different package ends.
* Current values received from LW tech director https://vk.com/sempertenebris
*/
enum mlt_package_end : uint8_t {
MLT_END_COMMON = 0xE8,
MLT_END_RED = 0xB4,
MLT_END_BLUE = 0xB5,
MLT_END_YELLOW = 0xB6,
MLT_END_GREEN = 0xB7,
};

struct mlt_command {

/**
* First byte
*/
mlt_command_type command_type;

union {
mlt_shot_data shot_data;
union {
mlt_system_command sys_cmd;
uint8_t cmd_data;
};
};
};

/**
* Last byte, MLT_END_COMMON (0xE8) by default, c++ 11 feature
*/
mlt_package_end package_end = mlt_package_end::MLT_END_COMMON;
};

void mltSetup(uint8_t emitter_pin, uint8_t sensor_pin);

Expand Down