diff --git a/2021_Arduino_Demo.ino b/2021_Arduino_Demo.ino index af87b30..442386e 100644 --- a/2021_Arduino_Demo.ino +++ b/2021_Arduino_Demo.ino @@ -1,14 +1,7 @@ -#include "AlarmTowerCommand.h" -#include "VoiceRepotCommand.h" -#include "GarageCommand.h" -#include "LEDDisplayCommand.h" -#include "CommandDecoder.h" #include "ZigBeeOperator.h" -#include "BarrierCommand.h" #include "CommandEncoder.h" -#include "ZigBeeOperator.h" -#include "AccurateMotor.h" #include "CommandDecoder.h" +#include "AccurateMotor.h" #include #include #include "GlobalDatas.h" diff --git a/2021_Arduino_Demo.vcxproj b/2021_Arduino_Demo.vcxproj index 5848cce..257bfe2 100644 --- a/2021_Arduino_Demo.vcxproj +++ b/2021_Arduino_Demo.vcxproj @@ -76,7 +76,7 @@ __AVR_atmega2560__;__AVR_ATmega2560__;F_CPU=16000000L;ARDUINO=108010;ARDUINO_AVR_MEGA2560;ARDUINO_ARCH_AVR;__cplusplus=201103L;_VMICRO_INTELLISENSE;%(PreprocessorDefinitions) stdcpp17 stdc11 - $(ProjectDir)..\Arduino;G:\Users\15819\Documents\Arduino\libraries\ExtSRAMInterface;G:\Users\15819\Documents\Arduino\libraries\DCMotor;G:\Users\15819\Documents\Arduino\libraries\MsTimer2;G:\Users\15819\Documents\Arduino\libraries\Ultrasonic;G:\Users\15819\Documents\Arduino\libraries\BKRC_Voice;G:\Users\15819\Documents\Arduino\libraries\CoreBeep;G:\Users\15819\Documents\Arduino\libraries\CoreKEY;G:\Users\15819\Documents\Arduino\libraries\CoreLED;G:\Users\15819\Documents\Arduino\libraries\Command;G:\Users\15819\Documents\Arduino\libraries\Infrares;G:\Users\15819\Documents\Arduino\libraries\BEEP;G:\Users\15819\Documents\Arduino\libraries\LED;G:\Users\15819\Documents\Arduino\libraries\BH1750;C:\Users\15819\AppData\Local\arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src;G:\Users\15819\Documents\Arduino\libraries\Metro;C:\Users\15819\AppData\Local\arduino15\packages\arduino\hardware\avr\1.8.6\variants\mega;C:\Users\15819\AppData\Local\arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\\lib\gcc\avr\7.3.0\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\\lib\gcc\avr\7.3.0\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include-fixed;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\lib\gcc\avr\4.9.2\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\lib\gcc\avr\4.9.2\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\lib\gcc\avr\4.9.3\include;%(AdditionalIncludeDirectories) + $(ProjectDir)..\Arduino;G:\Users\15819\Documents\Arduino\libraries\ExtSRAMInterface;G:\Users\15819\Documents\Arduino\libraries\DCMotor;G:\Users\15819\Documents\Arduino\libraries\MsTimer2;G:\Users\15819\Documents\Arduino\libraries\Ultrasonic;G:\Users\15819\Documents\Arduino\libraries\BKRC_Voice;G:\Users\15819\Documents\Arduino\libraries\CoreBeep;G:\Users\15819\Documents\Arduino\libraries\CoreKEY;G:\Users\15819\Documents\Arduino\libraries\CoreLED;G:\Users\15819\Documents\Arduino\libraries\BH1750;C:\Users\15819\AppData\Local\arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src;G:\Users\15819\Documents\Arduino\libraries\Infrares;G:\Users\15819\Documents\Arduino\libraries\Command;G:\Users\15819\Documents\Arduino\libraries\BEEP;G:\Users\15819\Documents\Arduino\libraries\LED;G:\Users\15819\Documents\Arduino\libraries\Metro;C:\Users\15819\AppData\Local\arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src\utility;C:\Users\15819\AppData\Local\arduino15\packages\arduino\hardware\avr\1.8.6\variants\mega;C:\Users\15819\AppData\Local\arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino;$(ProjectDir)..\..\..\RACECA~1\SUBCAR~1\Arduino;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\\lib\gcc\avr\7.3.0\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\\lib\gcc\avr\7.3.0\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include-fixed;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\lib\gcc\avr\4.9.2\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\lib\gcc\avr\4.9.2\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\lib\gcc\avr\4.9.3\include;%(AdditionalIncludeDirectories) true @@ -106,33 +106,51 @@ + + + + + + + + + + + + + + + + + + VisualMicroDebugger diff --git a/2021_Arduino_Demo.vcxproj.filters b/2021_Arduino_Demo.vcxproj.filters index d5953a4..cd75dc1 100644 --- a/2021_Arduino_Demo.vcxproj.filters +++ b/2021_Arduino_Demo.vcxproj.filters @@ -60,6 +60,33 @@ Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + @@ -98,5 +125,32 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + \ No newline at end of file diff --git a/3DDisplayCommand.cpp b/3DDisplayCommand.cpp new file mode 100644 index 0000000..c2cf96d --- /dev/null +++ b/3DDisplayCommand.cpp @@ -0,0 +1,91 @@ +// +// 标志物通信 - 立体显示 - ZigBee/IR +// + +#include "3DDisplayCommand.h" + +_3DDisplayCommand::_3DDisplayCommand() +{ + SetDevice(CommandData::Devices::_3D_Display); +} + +byte* _3DDisplayCommand::CMD_IR_CarLicenseMode_1to4(byte d1, byte d2, byte d3, byte d4) +{ + SetCommand(0xFF, 0x20, d1, d2, d3, d4); + return GetIRCommandArray(); +} + +byte* _3DDisplayCommand::CMD_IR_CarLicenseMode_5to6_XY(byte d5, byte d6, byte x, byte y) +{ + SetCommand(0xFF, 0x10, d5, d6, x, y); + return GetIRCommandArray(); +} + +byte* _3DDisplayCommand::CMD_IR_DisplayDestence(byte dis) +{ + if (dis >= 99) + SetCommand(0xFF, 0x11, 0x09, 0x09, 0x00, 0x00); + else + SetCommand(0xFF, 0x11, (dis / 10), (dis % 10), 0x00, 0x00); + return GetIRCommandArray(); +} + +byte* _3DDisplayCommand::CMD_IR_DisplayShape(Shape shape) +{ + SetCommand(0xFF, 0x12, (byte)shape, 0x00, 0x00, 0x00); + return GetIRCommandArray(); +} + +byte* _3DDisplayCommand::CMD_IR_DisplayColor(Color color) +{ + SetCommand(0xFF, 0x13, (byte)color, 0x00, 0x00, 0x00); + return GetIRCommandArray(); +} + +byte* _3DDisplayCommand::CMD_IR_DisplayAlarmSign(AlarmSign sign) +{ + SetCommand(0xFF, 0x14, (byte)sign, 0x00, 0x00, 0x00); + return GetIRCommandArray(); +} + +byte* _3DDisplayCommand::CMD_IR_DisplayTrafficSign(TrafficSign sign) +{ + SetCommand(0xFF, 0x15, (byte)sign, 0x00, 0x00, 0x00); + return GetIRCommandArray(); +} + +byte* _3DDisplayCommand::CMD_IR_DisplayDefaultInfo() +{ + SetCommand(0xFF, 0x16, 0x01, 0x00, 0x00, 0x00); + return GetIRCommandArray(); +} + +byte* _3DDisplayCommand::CMD_IR_SetTextColor(byte r, byte g, byte b) +{ + SetCommand(0xFF, 0x17, 0x01, r, g, b); + return GetIRCommandArray(); +} + +byte* _3DDisplayCommand::CMD_IR_CustomTextAdd(byte text1, byte text2, bool last_char) +{ + SetCommand(0xFF, 0x31, text1, text2, (last_char ? 0x55 : 0x00), 0x00); + return GetIRCommandArray(); +} + +byte* _3DDisplayCommand::CMD_IR_CustomTextStop(bool clear_display) +{ + SetCommand(0xFF, 0x32, (clear_display ? 0x02 : 0x01), 0x00, 0x00, 0x00); + return GetIRCommandArray(); +} + +byte* _3DDisplayCommand::CMD_ZIGBEE_CustomTextAdd(byte text1, byte text2, bool last_char) +{ + SetCommand(0x31, text1, text2, (last_char ? 0x55 : 0x00)); + return GetCommandArray(); +} + +byte* _3DDisplayCommand::CMD_ZIGBEE_CustomTextStop(bool clear_display) +{ + SetCommand(0x32, (clear_display ? 0x02 : 0x01)); + return GetCommandArray(); +} diff --git a/3DDisplayCommand.h b/3DDisplayCommand.h new file mode 100644 index 0000000..62a8de1 --- /dev/null +++ b/3DDisplayCommand.h @@ -0,0 +1,73 @@ +// 3DDisplayCommand.h + +#ifndef _3DDISPLAYCOMMAND_h +#define _3DDISPLAYCOMMAND_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "arduino.h" +#else + #include "WProgram.h" +#endif + +#include "CommandEncoder.h" + +class _3DDisplayCommand : private CommandEncoder +{ +public: + enum class Shape + { + Rectangle = 0x01, + Round = 0x02, + Triangle = 0x03, + Rhombus = 0x04, + Star = 0x05 + }; + enum class Color + { + Red = 0x01, + Green = 0x02, + Blue = 0x03, + Yellow = 0x04, + Pink = 0x05, + Cyan = 0x06, + Black = 0x07, + White = 0x08 + }; + enum class AlarmSign + { + School = 0x01, + UnderConstruction = 0x02, + RodeFallsDown = 0x03, + KeepDistence = 0x04, + NoDrinkDrive = 0x05, + NoThrowRubbish = 0x06 + }; + enum class TrafficSign + { + GoStraight = 0x01, + TurnLeft = 0x02, + TurnRight = 0x03, + TurnAround = 0x04, + NoStraight = 0x05, + DoNotEnter = 0x06 + }; +public: + _3DDisplayCommand(); +public: + byte* CMD_IR_CarLicenseMode_1to4(byte d1, byte d2, byte d3, byte d4); + byte* CMD_IR_CarLicenseMode_5to6_XY(byte d5, byte d6, byte x, byte y); + byte* CMD_IR_DisplayDestence(byte dis); + byte* CMD_IR_DisplayShape(Shape shape); + byte* CMD_IR_DisplayColor(Color color); + byte* CMD_IR_DisplayAlarmSign(AlarmSign sign); + byte* CMD_IR_DisplayTrafficSign(TrafficSign sign); + byte* CMD_IR_DisplayDefaultInfo(); + byte* CMD_IR_SetTextColor(byte r, byte g, byte b); + byte* CMD_IR_CustomTextAdd(byte text1, byte text2, bool last_char = false); + byte* CMD_IR_CustomTextStop(bool clear_display); + byte* CMD_ZIGBEE_CustomTextAdd(byte text1, byte text2, bool last_char = false); + byte* CMD_ZIGBEE_CustomTextStop(bool clear_display); +}; + +#endif + diff --git a/DebugOpt.h b/DebugOpt.h index eedf8f7..a99aa8a 100644 --- a/DebugOpt.h +++ b/DebugOpt.h @@ -1,14 +1,22 @@ #ifndef __DEBUG_OPT__ #define __DEBUG_OPT_ +#include "WirelessChargerCommand.h" +#include "TrafficLightCommand.h" +#include "SpecTerrainCommand.h" #include "VoiceRepotCommand.h" #include "LEDDisplayCommand.h" #include "AlarmTowerCommand.h" +#include "3DDisplayCommand.h" +#include "RodeLightCommand.h" #include "BarrierCommand.h" #include "ZigBeeOperator.h" #include "GarageCommand.h" #include "AccurateMotor.h" +#include "TextEncoder.h" #include "GlobalDatas.h" +#include "ETCCommand.h" +#include "TFTCommand.h" #include #include "OpenMVOpt.h" #include diff --git a/ETCCommand.cpp b/ETCCommand.cpp new file mode 100644 index 0000000..dbd12c3 --- /dev/null +++ b/ETCCommand.cpp @@ -0,0 +1,34 @@ +// +// 标志物通信 - ETC - ZigBee +// + +#include "ETCCommand.h" + +ETCCommand::ETCCommand() +{ + SetDevice(CommandData::Devices::ETC); +} + +byte* ETCCommand::CMD_GateUp() +{ + SetCommand(0x08, 0x01, 0x01); + return GetCommandArray(); +} + +byte* ETCCommand::CMD_GateDown() +{ + SetCommand(0x08, 0x02, 0x02); + return GetCommandArray(); +} + +byte* ETCCommand::CMD_LeftUpRightDown() +{ + SetCommand(0x08, 0x01, 0x02); + return GetCommandArray(); +} + +byte* ETCCommand::CMD_LeftDownRightUp() +{ + SetCommand(0x08, 0x02, 0x01); + return GetCommandArray(); +} diff --git a/ETCCommand.h b/ETCCommand.h new file mode 100644 index 0000000..75fa7ca --- /dev/null +++ b/ETCCommand.h @@ -0,0 +1,26 @@ +// ETCCommand.h + +#ifndef _ETCCOMMAND_h +#define _ETCCOMMAND_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "arduino.h" +#else + #include "WProgram.h" +#endif + +#include "CommandEncoder.h" + +class ETCCommand : private CommandEncoder +{ +public: + ETCCommand(); +public: + byte* CMD_GateUp(); + byte* CMD_GateDown(); + byte* CMD_LeftUpRightDown(); + byte* CMD_LeftDownRightUp(); +}; + +#endif + diff --git a/GlobalDatas.cpp b/GlobalDatas.cpp index 40bd89c..acb4f1a 100644 --- a/GlobalDatas.cpp +++ b/GlobalDatas.cpp @@ -19,17 +19,4 @@ unsigned long Tcount; uint8_t Data_Type; uint8_t Data_Flag; uint8_t Data_Length; -uint8_t Data_OTABuf[40]; - -void DataTool::PrintDataArray(uint8_t* arr, uint8_t len) -{ - Serial.println("------Data Array------"); - for (uint8_t i = 0; i < len; i++) - { - Serial.print("arr["); - Serial.print(i); - Serial.print("] = 0x"); - Serial.println(arr[i], HEX); - } - Serial.println("------Array End------"); -} +uint8_t Data_OTABuf[40]; \ No newline at end of file diff --git a/GlobalDatas.h b/GlobalDatas.h index 493371f..de7163e 100644 --- a/GlobalDatas.h +++ b/GlobalDatas.h @@ -40,7 +40,18 @@ namespace CommandData namespace DataTool { - void PrintDataArray(uint8_t* arr, uint8_t len); + template void PrintDataArray(T* arr, uint8_t len) + { + Serial.println("------Data Array------"); + for (uint8_t i = 0; i < len; i++) + { + Serial.print("arr["); + Serial.print(i); + Serial.print("] = 0x"); + Serial.println(arr[i], HEX); + } + Serial.println("------Array End------"); + } }; extern uint8_t ZigBee_back[16]; diff --git a/Handler.cpp b/Handler.cpp index 2da5eaa..b7051ae 100644 --- a/Handler.cpp +++ b/Handler.cpp @@ -78,9 +78,38 @@ void Handler::ZigBeeRx_Handler(uint8_t* mar) case CommandData::Devices::Garage_A: //立体车库标志物A break; case CommandData::Devices::TrafficLight_A: //交通灯标注物A + { + TrafficLightCommand cmd; + if (cmd.ModeChangeSuccess(mar)) + Serial.println("Enter Identify Mode"); + else + Serial.println("Mode Change Failure"); break; + } case CommandData::Devices::TrafficLight_B: //交通灯标志物B break; + case CommandData::Devices::SpecTerrain: + { + SpecTerrainCommand cmd; + if(cmd.IsSpecTerrainCommand(mar)) + { + switch (cmd.ReadStatus(mar)) + { + case SpecTerrainCommand::Status::Passed_AtoB: + case SpecTerrainCommand::Status::Passed_BtoA: + Serial.println("Passed"); + break; + case SpecTerrainCommand::Status::NotPass: + Serial.println("Not Pass"); + break; + default: + Serial.println("Data Invalidate"); + } + } + else + Serial.println("Command Invalidate"); + break; + } default: break; } @@ -207,28 +236,35 @@ void Handler::MainCarRx_Handler(uint8_t* com) void Handler::Key_0() { - AlarmTowerCommand cmd; - ZigBeeOperator.SendCommand(cmd.CMD_QueryRescuePosition()); + OpenMVOpt::Servo_Control(-60); + OpenMVOpt::OpenMV_Track(1); } void Handler::Key_1() { - AlarmTowerCommand cmd; - Infrare.Transmition(cmd.CMD_DefaultIRAlarm(), 6); + _3DDisplayCommand cmd; + Infrare.Transmition(cmd.CMD_IR_DisplayAlarmSign(_3DDisplayCommand::AlarmSign::NoDrinkDrive), 6); } void Handler::Key_2() { - LEDDisplayCommand cmd; - ZigBeeOperator.SendCommand(cmd.CMD_FirstLineDisplay(0x123456)); - delay(1000); - ZigBeeOperator.SendCommand(cmd.CMD_SecondLineDisplay(0x7890AB)); + _3DDisplayCommand cmd; + Infrare.Transmition(cmd.CMD_IR_SetTextColor(0x00, 0xFF, 0x00), 6); } void Handler::Key_3() { + _3DDisplayCommand cmd; + TextEncoder encoder("主车不动安如山,从车乱飞墙撞翻。"); + while(encoder.HasNextChar()) + { + byte b1, b2; + encoder.GetNextChar(b1, b2); + ZigBeeOperator.SendCommand(cmd.CMD_ZIGBEE_CustomTextAdd(b1, b2, encoder.IsLastChar())); + delay(200); + } /*OpenMVOpt::Servo_Control(-60); - OpenMVOpt::OpenMV_Track(10);*/ + OpenMVOpt::OpenMV_Track(1);*/ } void Handler::KEY_Handler(uint8_t k_value) diff --git a/OpenMVOpt.cpp b/OpenMVOpt.cpp index 1abb4d8..1c7ddf8 100644 --- a/OpenMVOpt.cpp +++ b/OpenMVOpt.cpp @@ -105,7 +105,7 @@ void OpenMVOpt::OpenMVTrack_Disc_CloseUp() void OpenMVOpt::OpenMV_Track(uint8_t Car_Speed) { uint32_t num = 0; - Car_Speed = 50; + //Car_Speed = 50; // 清空串口缓存 while (ExtSRAMInterface.ExMem_Read(0x6038) != 0x00) ExtSRAMInterface.ExMem_Read_Bytes(0x6038, Data_OpenMVBuf, 1); diff --git a/RodeLightCommand.cpp b/RodeLightCommand.cpp new file mode 100644 index 0000000..19bc20d --- /dev/null +++ b/RodeLightCommand.cpp @@ -0,0 +1,105 @@ +// +// 标志物通信 - 路灯 - IR +// + +#include "RodeLightCommand.h" + +void RodeLightCommand::Swap(uint16_t& a, uint16_t& b) +{ + uint16_t c = a; + a = b; + b = c; +} + +byte RodeLightCommand::CalcLevel(uint16_t* sorted_arr, uint16_t curr) +{ + if (curr >= sorted_arr[3]) + return 4; + else if (curr >= sorted_arr[2]) + return 3; + else if (curr >= sorted_arr[1]) + return 2; + else + return 1; +} + +RodeLightCommand::RodeLightCommand() +{ + ir_cmd[0] = 0x00; + ir_cmd[1] = 0xFF; + ir_cmd[2] = 0x00; + ir_cmd[3] = 0x00; +} + +byte* RodeLightCommand::CMD_LightPlusOne() +{ + ir_cmd[2] = 0x0C; + ir_cmd[3] = 0xF3; + return ir_cmd; +} + +byte* RodeLightCommand::CMD_LightPlusTwo() +{ + ir_cmd[2] = 0x18; + ir_cmd[3] = 0xE7; + return ir_cmd; +} + +byte* RodeLightCommand::CMD_LightPlusThree() +{ + ir_cmd[2] = 0x5E; + ir_cmd[3] = 0xA1; + return ir_cmd; +} + +byte RodeLightCommand::GetCurrentLevel() +{ + RodeLightCommand cmd; + uint16_t light_arr[4] = { 0 }; + uint16_t current = BH1750.ReadLightLevel(), last = 0; + for (int i = 0; i < 4; i++) + { + Infrare.Transmition(cmd.CMD_LightPlusOne(), 4); + light_arr[i] = BH1750.ReadLightLevel(true); + while(abs(last - light_arr[i]) <= 200) + { + Infrare.Transmition(cmd.CMD_LightPlusOne(), 4); + light_arr[i] = BH1750.ReadLightLevel(true); + delay(1500); + } + last = light_arr[i]; + delay(1500); + } + for (int i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) + if (light_arr[i] < light_arr[j]) + Swap(light_arr[i], light_arr[j]); + /*DataTool::PrintDataArray(light_arr, 4); + Serial.print("Current: "); + Serial.println(current, HEX);*/ + return CalcLevel(light_arr, current); +} + +void RodeLightCommand::SetToSpeclevel(byte target_lv, byte current_lv) +{ + uint8_t times = 0; + RodeLightCommand cmd; + if (target_lv > current_lv) + times = target_lv - current_lv; + else + times = 4 - (current_lv - target_lv); + switch (times) + { + case 1: + Infrare.Transmition(cmd.CMD_LightPlusOne(), 4); + break; + case 2: + Infrare.Transmition(cmd.CMD_LightPlusTwo(), 4); + break; + case 3: + Infrare.Transmition(cmd.CMD_LightPlusThree(), 4); + break; + default: + return; + } +} \ No newline at end of file diff --git a/RodeLightCommand.h b/RodeLightCommand.h new file mode 100644 index 0000000..1b3afc8 --- /dev/null +++ b/RodeLightCommand.h @@ -0,0 +1,35 @@ +// RodeLightCommand.h + +#ifndef _RODELIGHTCOMMAND_h +#define _RODELIGHTCOMMAND_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "arduino.h" +#else + #include "WProgram.h" +#endif + +#include +#include +#include "GlobalDatas.h" + +class RodeLightCommand +{ +private: + byte ir_cmd[4]; +private: + static void Swap(uint16_t& a, uint16_t& b); + static byte CalcLevel(uint16_t* sorted_arr, uint16_t curr); +public: + RodeLightCommand(); +public: + byte* CMD_LightPlusOne(); + byte* CMD_LightPlusTwo(); + byte* CMD_LightPlusThree(); +public: + static byte GetCurrentLevel(); + static void SetToSpeclevel(byte target_lv, byte current_lv); +}; + +#endif + diff --git a/SpecTerrainCommand.cpp b/SpecTerrainCommand.cpp new file mode 100644 index 0000000..d6c6d4c --- /dev/null +++ b/SpecTerrainCommand.cpp @@ -0,0 +1,28 @@ +// +// 标志物通信 - 特殊地形 - ZigBee +// + +#include "SpecTerrainCommand.h" + +SpecTerrainCommand::SpecTerrainCommand() +{ + SetDevice(CommandData::Devices::SpecTerrain); +} + +byte* SpecTerrainCommand::CMD_QueryStatus() +{ + SetCommand(0x10, 0x01); + return GetCommandArray(); +} + +bool SpecTerrainCommand::IsSpecTerrainCommand(byte* cmd) +{ + return ((cmd[1] == CommandData::Devices::SpecTerrain) && (cmd[2] == 0x10) && (cmd[3] == 0x01)); +} + +SpecTerrainCommand::Status SpecTerrainCommand::ReadStatus(byte* cmd) +{ + if (!IsSpecTerrainCommand(cmd)) + return Status::Unknown; + return ((Status)cmd[4]); +} diff --git a/SpecTerrainCommand.h b/SpecTerrainCommand.h new file mode 100644 index 0000000..0521e0b --- /dev/null +++ b/SpecTerrainCommand.h @@ -0,0 +1,34 @@ +// SpecTerrainCommand.h + +#ifndef _SPECTERRAINCOMMAND_h +#define _SPECTERRAINCOMMAND_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "arduino.h" +#else + #include "WProgram.h" +#endif + +#include "CommandEncoder.h" + +class SpecTerrainCommand : private CommandEncoder +{ +public: + enum class Status + { + Passed_AtoB = 0x31, + Passed_BtoA = 0x32, + NotPass = 0x33, + Unknown = 0xFF + }; +public: + SpecTerrainCommand(); +public: + byte* CMD_QueryStatus(); +public: + bool IsSpecTerrainCommand(byte* cmd); + Status ReadStatus(byte* cmd); +}; + +#endif + diff --git a/TFTCommand.cpp b/TFTCommand.cpp index 73b16bb..f47adde 100644 --- a/TFTCommand.cpp +++ b/TFTCommand.cpp @@ -4,4 +4,106 @@ #include "TFTCommand.h" +TFTCommand::TFTCommand() +{ + SetDevice(CommandData::Devices::TFT_A); +} +void TFTCommand::UsingA() +{ + SetDevice(CommandData::Devices::TFT_A); +} + +void TFTCommand::UsingB() +{ + SetDevice(CommandData::Devices::TFT_B); +} + +byte* TFTCommand::CMD_DisplaySpecPicture(byte no) +{ + SetCommand(0x10, 0x00, no); + return GetCommandArray(); +} + +byte* TFTCommand::CMD_PageUp() +{ + SetCommand(0x10, 0x01); + return GetCommandArray(); +} + +byte* TFTCommand::CMD_PageDown() +{ + SetCommand(0x10, 0x02); + return GetCommandArray(); +} + +byte* TFTCommand::CMD_AutoPaging() +{ + SetCommand(0x10, 0x03); + return GetCommandArray(); +} + +byte* TFTCommand::CMD_CarLicenseMode_1to3(byte d1, byte d2, byte d3) +{ + SetCommand(0x20, d1, d2, d3); + return GetCommandArray(); +} + +byte* TFTCommand::CMD_CarLicenseMode_4to6(byte d4, byte d5, byte d6) +{ + SetCommand(0x21, d4, d5, d6); + return GetCommandArray(); +} + +byte* TFTCommand::CMD_TimerOn() +{ + SetCommand(0x30, 0x01); + return GetCommandArray(); +} + +byte* TFTCommand::CMD_TimerOff() +{ + SetCommand(0x30); + return GetCommandArray(); +} + +byte* TFTCommand::CMD_TimerClear() +{ + SetCommand(0x30, 0x02); + return GetCommandArray(); +} + +byte* TFTCommand::CMD_DisplayHex(uint32_t hex) +{ + if (hex >= 0xFFFFFF) + SetCommand(0x40, 0xFF, 0xFF, 0xFF); + else + { + byte d1 = ((hex > 0xFFFF) ? (hex / 0x10000) : 0x00); + hex -= (d1 * 0x10000); + byte d2 = ((hex > 0xFF) ? (hex / 0x100) : 0x00); + byte d3 = hex % 0x100; + SetCommand(0x40, d1, d2, d3); + } + return GetCommandArray(); +} + +byte* TFTCommand::CMD_DisplayDistence(uint16_t dis) +{ + if (dis >= 0x999) + SetCommand(0x50, 0x00, 0x09, 0x99); + else + { + byte d1 = ((dis > 0x99) ? (dis / 0x100) : 0); + dis -= (d1 * 0x100); + byte d2 = dis % 0x100; + SetCommand(0x50, 0x00, d1, d2); + } + return GetCommandArray(); +} + +byte* TFTCommand::CMD_DisplayTrafficSign(TrafficSign sign) +{ + SetCommand(0x60, (byte)sign); + return GetCommandArray(); +} diff --git a/TFTCommand.h b/TFTCommand.h index 6420a55..dc9aaaf 100644 --- a/TFTCommand.h +++ b/TFTCommand.h @@ -13,13 +13,40 @@ class TFTCommand : private CommandEncoder { +public: + enum class TrafficSign + { + GoStraight = 0x01, + TurnLeft = 0x02, + TurnRight = 0x03, + TurnAround = 0x04, + NoStraight = 0x05, + DoNotEnter = 0x06 + }; public: TFTCommand(); public: void UsingA(); void UsingB(); public: - + //Picture Mode + byte* CMD_DisplaySpecPicture(byte no); //Range: 0x01~0x20 + byte* CMD_PageUp(); + byte* CMD_PageDown(); + byte* CMD_AutoPaging(); + //Car License Mode + byte* CMD_CarLicenseMode_1to3(byte d1, byte d2, byte d3); + byte* CMD_CarLicenseMode_4to6(byte d4, byte d5, byte d6); + //Timer Mode + byte* CMD_TimerOn(); + byte* CMD_TimerOff(); + byte* CMD_TimerClear(); + //HEX Mode + byte* CMD_DisplayHex(uint32_t hex); + //Distence Mode + byte* CMD_DisplayDistence(uint16_t dis); + //Traffic Sign Mode + byte* CMD_DisplayTrafficSign(TrafficSign sign); }; #endif diff --git a/TextEncoder.cpp b/TextEncoder.cpp new file mode 100644 index 0000000..439ec1d --- /dev/null +++ b/TextEncoder.cpp @@ -0,0 +1,70 @@ +// +// GBK文本编码器 +// + +#include "TextEncoder.h" + +TextEncoder::TextEncoder() +{ + size = 0; + data = nullptr; + current_index = 0; +} + +TextEncoder::TextEncoder(String text) +{ + current_index = 0; + size = text.length(); + data = new byte[size]; + for (int i = 0; i < size; i++) + data[i] = text[i]; +} + +TextEncoder::~TextEncoder() +{ + if (data != nullptr) + { + delete[] data; + data = nullptr; + } +} + +void TextEncoder::EncodeText(String text) +{ + if (data != nullptr) + { + delete[] data; + data = nullptr; + } + current_index = 0; + size = text.length(); + data = new byte[size]; + for (int i = 0; i < size; i++) + data[i] = text[i]; +} + +bool TextEncoder::HasNextChar() +{ + return (current_index < size); +} + +bool TextEncoder::IsLastChar() +{ + return ((current_index + 1) >= size); +} + +void TextEncoder::GetNextChar(byte& bit1, byte& bit2) +{ + if (data[current_index] >= 0x7F) //中文 + { + bit1 = data[current_index]; + bit2 = data[current_index + 1]; + current_index += 2; + } + else + { + bit1 = data[current_index]; + bit2 = 0x00; + current_index++; + } +} diff --git a/TextEncoder.h b/TextEncoder.h new file mode 100644 index 0000000..fc61a9b --- /dev/null +++ b/TextEncoder.h @@ -0,0 +1,31 @@ +// TextEncoder.h + +#ifndef _TEXTENCODER_h +#define _TEXTENCODER_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "arduino.h" +#else + #include "WProgram.h" +#endif + +class TextEncoder +{ +private: + uint16_t size; + uint16_t current_index; + byte* data = nullptr; +public: + TextEncoder(); + TextEncoder(String text); + ~TextEncoder(); +public: + void EncodeText(String text); +public: + bool HasNextChar(); + bool IsLastChar(); + void GetNextChar(byte& bit1, byte& bit2); +}; + +#endif + diff --git a/TrafficLightCommand.cpp b/TrafficLightCommand.cpp new file mode 100644 index 0000000..ea697b1 --- /dev/null +++ b/TrafficLightCommand.cpp @@ -0,0 +1,46 @@ +// +// 标志物通信 - 交通灯(A/B) - ZigBee +// + +#include "TrafficLightCommand.h" + +TrafficLightCommand::TrafficLightCommand() +{ + SetDevice(CommandData::Devices::TrafficLight_A); +} + +void TrafficLightCommand::UsingA() +{ + SetDevice(CommandData::Devices::TrafficLight_A); +} + +void TrafficLightCommand::UsingB() +{ + SetDevice(CommandData::Devices::TrafficLight_B); +} + +byte* TrafficLightCommand::CMD_EnterIdentifyMode() +{ + SetCommand(0x01); + return GetCommandArray(); +} + +byte* TrafficLightCommand::CMD_CheckResult(Color color) +{ + SetCommand(0x02, (byte)color); + return GetCommandArray(); +} + +bool TrafficLightCommand::IsTrafficLightCommand(byte* cmd) +{ + if ((cmd[1] == CommandData::Devices::TrafficLight_A) || (cmd[1] == CommandData::Devices::TrafficLight_B)) + return (cmd[2] == 0x01); + return false; +} + +bool TrafficLightCommand::ModeChangeSuccess(byte* cmd) +{ + if (!IsTrafficLightCommand(cmd)) + return false; + return ((cmd[3] == 0x01) && (cmd[4] == 0x07)); +} diff --git a/TrafficLightCommand.h b/TrafficLightCommand.h new file mode 100644 index 0000000..e75d237 --- /dev/null +++ b/TrafficLightCommand.h @@ -0,0 +1,37 @@ +// TrafficLightCommand.h + +#ifndef _TRAFFICLIGHTCOMMAND_h +#define _TRAFFICLIGHTCOMMAND_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "arduino.h" +#else + #include "WProgram.h" +#endif + +#include "CommandEncoder.h" + +class TrafficLightCommand : private CommandEncoder +{ +public: + enum class Color + { + Red = 0x01, + Green = 0x02, + Yellow = 0x03 + }; +public: + TrafficLightCommand(); +public: + void UsingA(); + void UsingB(); +public: + byte* CMD_EnterIdentifyMode(); + byte* CMD_CheckResult(Color color); +public: + bool IsTrafficLightCommand(byte* cmd); + bool ModeChangeSuccess(byte* cmd); +}; + +#endif + diff --git a/WirelessChargerCommand.cpp b/WirelessChargerCommand.cpp new file mode 100644 index 0000000..04981d1 --- /dev/null +++ b/WirelessChargerCommand.cpp @@ -0,0 +1,22 @@ +// +// 标志物通信 - 无线充电 - ZigBee +// + +#include "WirelessChargerCommand.h" + +WirelessChargerCommand::WirelessChargerCommand() +{ + SetDevice(CommandData::Devices::WirelessCharger); +} + +byte* WirelessChargerCommand::CMD_TurnOn() +{ + SetCommand(0x01, 0x01); + return GetCommandArray(); +} + +byte* WirelessChargerCommand::CMD_TurnOff() +{ + SetCommand(0x01, 0x02); + return GetCommandArray(); +} diff --git a/WirelessChargerCommand.h b/WirelessChargerCommand.h new file mode 100644 index 0000000..7306666 --- /dev/null +++ b/WirelessChargerCommand.h @@ -0,0 +1,24 @@ +// WirelessChargerCommand.h + +#ifndef _WIRELESSCHARGERCOMMAND_h +#define _WIRELESSCHARGERCOMMAND_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "arduino.h" +#else + #include "WProgram.h" +#endif + +#include "CommandEncoder.h" + +class WirelessChargerCommand : private CommandEncoder +{ +public: + WirelessChargerCommand(); +public: + byte* CMD_TurnOn(); + byte* CMD_TurnOff(); +}; + +#endif + diff --git a/__vm/Compile.vmps.xml b/__vm/Compile.vmps.xml index 270a588..6676c93 100644 --- a/__vm/Compile.vmps.xml +++ b/__vm/Compile.vmps.xml @@ -2,7 +2,7 @@ - + diff --git a/__vm/Upload.vmps.xml b/__vm/Upload.vmps.xml index 270a588..6676c93 100644 --- a/__vm/Upload.vmps.xml +++ b/__vm/Upload.vmps.xml @@ -2,7 +2,7 @@ - +