Skip to content

Commit

Permalink
Categories for protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjak committed Apr 24, 2022
1 parent 5d52a0e commit c1db5dc
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 24 deletions.
56 changes: 32 additions & 24 deletions Applications/Connectatron/Connectatron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ static string CurrentProjectName = "my_project.con";

static vector<ConnectorCategoryInfo> ConnectorCategories;
static vector<PinType> UncategorizedConnectors;
static vector<ProtocolCategoryInfo> ProtocolCategories;
static vector<WireProtocol> UncategorizedProtocols;

constexpr double HSV_HueFromStringOffset = 90;
constexpr double HSV_ValFromStringOffset = 0;
Expand Down Expand Up @@ -547,6 +549,8 @@ struct Connectatron:
{
ConnectorCategories = GetConnectorCategories();
UncategorizedConnectors = GetUncategorizedConnectors();
ProtocolCategories = GetProtocolCategories();
UncategorizedProtocols = GetUncategorizedProtocols();

ed::Config config;

Expand Down Expand Up @@ -2071,7 +2075,7 @@ struct Connectatron:

if (ImGui::BeginMenu(editing_title.c_str()))
{
for (const auto& possible_proto : magic_enum::enum_values<WireProtocol>())
for (const auto& possible_proto : UncategorizedProtocols)
{
auto proto_string = NameFromProtocol(possible_proto);
EnumName_Underscore2Symbol(proto_string);
Expand All @@ -2092,29 +2096,33 @@ struct Connectatron:
}
}

//TODO protocol categories
//for (const auto& category : ConnectorCategories)
//{
// if (ImGui::BeginMenu(category.name.c_str()))
// {
// for (const auto& possible_connect : category.connectors)
// {
// auto connect_string = NameFromPinType(possible_connect);
// EnumName_Underscore2Symbol(connect_string);

// DrawPinTypeIcon(possible_connect, false, 255);
// ImGui::SameLine();

// bool is_selected = possible_connect == pin->Type;
// //TODO also try Selectable?
// if (ImGui::MenuItem(connect_string.c_str(), "", is_selected))
// pin->Type = possible_connect;
// if (is_selected)
// ImGui::SetItemDefaultFocus();
// }
// ImGui::EndMenu();
// }
//}
for (const auto& category : ProtocolCategories)
{
if (ImGui::BeginMenu(category.name.c_str()))
{
for (const auto& possible_proto : category.protocols)
{
auto proto_string = NameFromProtocol(possible_proto);
EnumName_Underscore2Symbol(proto_string);

//TODO might use icons for protocols later?
/*DrawPinTypeIcon(possible_proto, false, 255);
ImGui::SameLine();*/

bool val = pin->Protocols.find(possible_proto) != pin->Protocols.end();
auto pastval = val;
ImGui::Checkbox(proto_string.c_str(), &val);
if (val != pastval)
{
if (val)
pin->Protocols.insert(possible_proto);
else
pin->Protocols.erase(possible_proto);
}
}
ImGui::EndMenu();
}
}
ImGui::EndMenu();
}
}
Expand Down
106 changes: 106 additions & 0 deletions Applications/Connectatron/Protocols.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,23 @@ enum class WireProtocol : unsigned int
AnalogAudio, //Placeholder until I get a proper name for this

// Single-Wire
START_CATEGORY_Single___Wire,
//https://en.wikipedia.org/wiki/System_Management_Bus
UART,
SPI,
//https://en.wikipedia.org/wiki/I%C2%B2C
I2C,
END_CATEGORY_Single___Wire,

// Audio
START_CATEGORY_Audio,
S____PIDF, //https://en.wikipedia.org/wiki/S/PDIF
ADAT__Lightpipe, //https://en.wikipedia.org/wiki/ADAT_Lightpipe
AES3, //https://en.wikipedia.org/wiki/AES3
END_CATEGORY_Audio,

// USB
START_CATEGORY_USB,
MIN_VERSION_USB,
USB__1_0, //Low-Speed: 1.5 Mbps
USB__1_1, //Full-Speed: 12 Mbps
Expand All @@ -85,8 +90,10 @@ enum class WireProtocol : unsigned int
USB4__20g, //USB4 20 Gbps
USB4__40g, //USB4 40 Gbps
MAX_VERSION_USB,
END_CATEGORY_USB,

// FireWire
START_CATEGORY_FireWire,
//https://en.wikipedia.org/wiki/IEEE_1394
MIN_VERSION_FireWire,
FireWire__400__1394, //IEEE 1394-1995
Expand All @@ -96,8 +103,10 @@ enum class WireProtocol : unsigned int
FireWire__S1600, //IEEE 1394-2008
FireWire__S3200, //IEEE 1394-2008
MAX_VERSION_FireWire,
END_CATEGORY_FireWire,

// Display
START_CATEGORY_Display,
// https://en.wikipedia.org/wiki/DisplayPort
MIN_VERSION_DisplayPort,
DisplayPort__1_0,
Expand Down Expand Up @@ -135,16 +144,20 @@ enum class WireProtocol : unsigned int
RGB__Video, //https://en.wikipedia.org/wiki/RGB_color_model#Video_electronics
S___Video, //https://en.wikipedia.org/wiki/S-Video
Component__Video, //https://en.wikipedia.org/wiki/Component_video
END_CATEGORY_Display,

// Display Metadata (may be a part of another display cable protocol)
START_CATEGORY_Display__Metadata,
//https://en.wikipedia.org/wiki/Display_Data_Channel
DDC1,
DDC2B,
E___DDC,
//https://en.wikipedia.org/wiki/Extended_Display_Identification_Data
EDID,
END_CATEGORY_Display__Metadata,

// Expansion Slot
START_CATEGORY_Expansion__Slot,
//https://en.wikipedia.org/wiki/Industry_Standard_Architecture
ISA,
ISA__DMA, // Direct Memory Access
Expand Down Expand Up @@ -194,8 +207,10 @@ enum class WireProtocol : unsigned int
//TODO
// https://en.wikipedia.org/wiki/ExpressCard
//TODO
END_CATEGORY_Expansion__Slot,

// Storage Interface
START_CATEGORY_Storage__Interface,
//https://en.wikipedia.org/wiki/Parallel_ATA
//https://en.wikipedia.org/wiki/Advanced_Host_Controller_Interface
//https://en.wikipedia.org/wiki/Serial_ATA
Expand Down Expand Up @@ -223,8 +238,10 @@ enum class WireProtocol : unsigned int
SD__UHS___II,
SD__UHS___III,
SD__Express,
END_CATEGORY_Storage__Interface,

// Ethernet
START_CATEGORY_Ethernet,
//https://en.wikipedia.org/wiki/Ethernet_over_twisted_pair
//https://en.wikipedia.org/wiki/Fast_Ethernet#100BASE-T1
//https://en.wikipedia.org/wiki/10BASE5
Expand All @@ -244,8 +261,10 @@ enum class WireProtocol : unsigned int
Ethernet__25GBASE___T, //25 Gbps
Ethernet__40GBASE___T, //40 Gbps
MAX_VERSION_Ethernet,
END_CATEGORY_Ethernet,

// Wireless
START_CATEGORY_Wireless,
//https://en.wikipedia.org/wiki/Wi-Fi
MIN_VERSION_Wi___Fi,
Wi___Fi__0__802_11, //1997
Expand Down Expand Up @@ -280,6 +299,7 @@ enum class WireProtocol : unsigned int
MAX_VERSION_Bluetooth,
//https://www.windowscentral.com/xbox-wireless
Xbox__Wireless,
END_CATEGORY_Wireless,

// Other Protocols
//https://en.wikipedia.org/wiki/Thunderbolt_(interface)
Expand Down Expand Up @@ -340,3 +360,89 @@ static string NameFromProtocol(WireProtocol proto)
return ret;
}

///////////////////////////////
/// CATEGORIES

struct ProtocolCategoryInfo : CategoryInfo
{
vector<WireProtocol> protocols;
};

static vector<WireProtocol> GetUncategorizedProtocols()
{
vector<WireProtocol> ret;

bool in_category = false;
for (const auto& possible_proto : magic_enum::enum_values<WireProtocol>())
{
if (possible_proto == WireProtocol::UNRECOGNIZED)
continue;

auto proto_string = NameFromProtocol(possible_proto);
EnumName_Underscore2Symbol(proto_string);
auto cat_strpos = proto_string.find(".CATEGORY.");
if (cat_strpos != string::npos)
{
if (!in_category)
{
in_category = true;
}
else
{
in_category = false;
}
}
else
{
if (!in_category)
ret.push_back(possible_proto);
}
}

return ret;
}

static vector<ProtocolCategoryInfo> GetProtocolCategories()
{
vector<ProtocolCategoryInfo> ret;

bool in_category = false;
ProtocolCategoryInfo current_category;
for (const auto& possible_proto : magic_enum::enum_values<WireProtocol>())
{
if (possible_proto == WireProtocol::UNRECOGNIZED)
continue;

auto proto_string = NameFromProtocol(possible_proto);
EnumName_Underscore2Symbol(proto_string);

if (proto_string.find(".VERSION.") != string::npos)
continue;

auto cat_strpos = proto_string.find(".CATEGORY.");
if (cat_strpos != string::npos)
{
if (!in_category)
{
auto name_strpos = cat_strpos + string(".CATEGORY.").length();
current_category.name = proto_string.substr(name_strpos);
current_category.index_of_first = magic_enum::enum_index<WireProtocol>(possible_proto).value() + 1;
in_category = true;
}
else
{
current_category.index_after_last = magic_enum::enum_index<WireProtocol>(possible_proto).value();
in_category = false;
ret.push_back(current_category);
current_category.protocols.clear();
}
}
else
{
if (in_category)
current_category.protocols.push_back(possible_proto);
}
}

return ret;
}

0 comments on commit c1db5dc

Please sign in to comment.