added serial text brick using ascii characters
This commit is contained in:
@ -5,5 +5,8 @@ datablock fxDTSBrickData(LogicGate_AND_Data : LogicGate_OR_Data)
|
||||
logicUIName = "AND";
|
||||
logicUIDesc = "C is true if A and B are true";
|
||||
logicUpdate = "return function(gate) gate.ports[3]:setstate(gate.ports[1].state and gate.ports[2].state) end";
|
||||
|
||||
logicForceColor = "YELLOW";
|
||||
logicForcePrint = "ANDGATE";
|
||||
};
|
||||
lualogic_registergatedefinition("LogicGate_AND_Data");
|
||||
|
@ -5,20 +5,12 @@ datablock fxDTSBrickData(LogicGate_NOT_Data : LogicGate_Diode_Data)
|
||||
|
||||
logicUIName = "NOT";
|
||||
logicUIDesc = "B is the opposite of A";
|
||||
|
||||
logicForceColor = "RED";
|
||||
logicForcePrint = "ARROW";
|
||||
|
||||
logicUpdate = "return function(gate) gate.ports[2]:setstate(not gate.ports[1].state) end";
|
||||
|
||||
numLogicPorts = 2;
|
||||
};
|
||||
lualogic_registergatedefinition("LogicGate_NOT_Data");
|
||||
|
||||
function LogicGate_NOT_Data::onPlant(%this, %obj)
|
||||
{
|
||||
if(lualogic_iscolor("RED"))
|
||||
%obj.setColor(lualogic_getcolor("RED"));
|
||||
|
||||
if(lualogic_isprint("ARROW"))
|
||||
%obj.setPrint(lualogic_getprint("ARROW"));
|
||||
|
||||
parent::onPlant(%this, %obj);
|
||||
}
|
||||
|
@ -12,6 +12,9 @@ datablock fxDTSBrickData(LogicGate_Diode_Data)
|
||||
isLogicGate = 1;
|
||||
logicUIName = "Diode";
|
||||
logicUIDesc = "B is A";
|
||||
|
||||
logicForceColor = "GREEN";
|
||||
logicForcePrint = "ARROW";
|
||||
|
||||
logicUpdate = "return function(gate) gate.ports[2]:setstate(gate.ports[1].state) end";
|
||||
|
||||
@ -31,14 +34,3 @@ datablock fxDTSBrickData(LogicGate_Diode_Data)
|
||||
logicPortUIDesc[1] = "";
|
||||
};
|
||||
lualogic_registergatedefinition("LogicGate_Diode_Data");
|
||||
|
||||
function LogicGate_Diode_Data::onPlant(%this, %obj)
|
||||
{
|
||||
if(lualogic_iscolor("GREEN"))
|
||||
%obj.setColor(lualogic_getcolor("GREEN"));
|
||||
|
||||
if(lualogic_isprint("ARROW"))
|
||||
%obj.setPrint(lualogic_getprint("ARROW"));
|
||||
|
||||
parent::onPlant(%this, %obj);
|
||||
}
|
||||
|
@ -15,6 +15,9 @@ datablock fxDTSBrickData(LogicGate_DiodeUp_Data)
|
||||
|
||||
logicUIName = "Diode Up";
|
||||
logicUIDesc = "B is A";
|
||||
|
||||
logicForceColor = "GREEN";
|
||||
logicForcePrint = "UPARROW";
|
||||
|
||||
logicUpdate = "return function(gate) gate.ports[2]:setstate(gate.ports[1].state) end";
|
||||
|
||||
@ -40,30 +43,11 @@ datablock fxDTSBrickData(LogicGate_DiodeDown_Data : LogicGate_DiodeUp_Data)
|
||||
iconName = $LuaLogic::Path @ "icons/Diode Down";
|
||||
|
||||
logicUIName = "Diode Down";
|
||||
|
||||
logicForceColor = "GREEN";
|
||||
logicForcePrint = "DOWNARROW";
|
||||
|
||||
logicPortDir[0] = 4;
|
||||
logicPortDir[1] = 5;
|
||||
};
|
||||
lualogic_registergatedefinition("LogicGate_DiodeDown_Data");
|
||||
|
||||
function LogicGate_DiodeUp_Data::onPlant(%this, %obj)
|
||||
{
|
||||
if(lualogic_iscolor("GREEN"))
|
||||
%obj.setColor(lualogic_getcolor("GREEN"));
|
||||
|
||||
if(lualogic_isprint("UPARROW"))
|
||||
%obj.setPrint(lualogic_getprint("UPARROW"));
|
||||
|
||||
parent::onPlant(%this, %obj);
|
||||
}
|
||||
|
||||
function LogicGate_DiodeDown_Data::onPlant(%this, %obj)
|
||||
{
|
||||
if(lualogic_iscolor("GREEN"))
|
||||
%obj.setColor(lualogic_getcolor("GREEN"));
|
||||
|
||||
if(lualogic_isprint("DOWNARROW"))
|
||||
%obj.setPrint(lualogic_getprint("DOWNARROW"));
|
||||
|
||||
parent::onPlant(%this, %obj);
|
||||
}
|
||||
|
@ -5,6 +5,9 @@ datablock fxDTSBrickData(LogicGate_NotUp_Data : LogicGate_DiodeUp_Data)
|
||||
|
||||
logicUIName = "Not Up";
|
||||
logicUIDesc = "B is the inverse of A";
|
||||
|
||||
logicForceColor = "RED";
|
||||
logicForcePrint = "UPARROW";
|
||||
|
||||
logicUpdate = "return function(gate) gate.ports[2]:setstate(not gate.ports[1].state) end";
|
||||
};
|
||||
@ -17,29 +20,10 @@ datablock fxDTSBrickData(LogicGate_NotDown_Data : LogicGate_DiodeDown_Data)
|
||||
|
||||
logicUIName = "Not Down";
|
||||
logicUIDesc = "B is the inverse of A";
|
||||
|
||||
logicForceColor = "RED";
|
||||
logicForcePrint = "DOWNARROW";
|
||||
|
||||
logicUpdate = "return function(gate) gate.ports[2]:setstate(not gate.ports[1].state) end";
|
||||
};
|
||||
lualogic_registergatedefinition("LogicGate_NotDown_Data");
|
||||
|
||||
function LogicGate_NotUp_Data::onPlant(%this, %obj)
|
||||
{
|
||||
if(lualogic_iscolor("RED"))
|
||||
%obj.setColor(lualogic_getcolor("RED"));
|
||||
|
||||
if(lualogic_isprint("UPARROW"))
|
||||
%obj.setPrint(lualogic_getprint("UPARROW"));
|
||||
|
||||
parent::onPlant(%this, %obj);
|
||||
}
|
||||
|
||||
function LogicGate_NotDown_Data::onPlant(%this, %obj)
|
||||
{
|
||||
if(lualogic_iscolor("RED"))
|
||||
%obj.setColor(lualogic_getcolor("RED"));
|
||||
|
||||
if(lualogic_isprint("DOWNARROW"))
|
||||
%obj.setPrint(lualogic_getprint("DOWNARROW"));
|
||||
|
||||
parent::onPlant(%this, %obj);
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ keyboard_keyToCode = {
|
||||
["["] = 0x75,
|
||||
["\\"] = 0x76,
|
||||
["]"] = 0x77,
|
||||
[" ="] = 0x78,
|
||||
["="] = 0x78,
|
||||
["apostrophe"] = 0x79,
|
||||
|
||||
["invalid"] = 0x7F,
|
||||
|
35
bricks/outputs/TextBrick2.cs
Normal file
35
bricks/outputs/TextBrick2.cs
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
datablock fxDTSBrickData(LogicGate_TextBrick2_Data){
|
||||
brickFile = $LuaLogic::Path @ "bricks/blb/TextBrick.blb";
|
||||
category = "Logic Bricks";
|
||||
subCategory = "Outputs";
|
||||
uiName = "Text Brick 2";
|
||||
iconName = $LuaLogic::Path @ "icons/Text Brick";
|
||||
hasPrint = 1;
|
||||
printAspectRatio = "Logic";
|
||||
orientationFix = 3;
|
||||
|
||||
isLogic = true;
|
||||
isLogicGate = true;
|
||||
isLogicInput = false;
|
||||
|
||||
logicUIName = "Text Brick 2";
|
||||
logicUIDesc = "Takes 7-bit serial input for ascii character";
|
||||
|
||||
logicInit = lualogic_readfile($LuaLogic::Path @ "bricks/outputs/text2-init.lua" );
|
||||
logicUpdate = lualogic_readfile($LuaLogic::Path @ "bricks/outputs/text2-update.lua");
|
||||
logicGlobal = lualogic_readfile($LuaLogic::Path @ "bricks/outputs/text2-global.lua");
|
||||
|
||||
numLogicPorts = 1;
|
||||
|
||||
logicPortType[0] = 1;
|
||||
logicPortPos[0] = "0 0 -1";
|
||||
logicPortDir[0] = 3;
|
||||
logicPortCauseUpdate[0] = true;
|
||||
logicPortUIName[0] = "In";
|
||||
};
|
||||
lualogic_registergatedefinition("LogicGate_TextBrick2_Data");
|
||||
|
||||
function LogicGate_TextBrick2_Data::LuaLogic_Callback(%data, %brick, %printname){
|
||||
%brick.setPrint(lualogic_getprint(%printname));
|
||||
}
|
146
bricks/outputs/text2-global.lua
Normal file
146
bricks/outputs/text2-global.lua
Normal file
@ -0,0 +1,146 @@
|
||||
|
||||
textbrick2_bitsNeeded = 7
|
||||
|
||||
textbrick2_idxToPrint = {
|
||||
[0x00] = "space",
|
||||
[0x01] = "space",
|
||||
[0x02] = "space",
|
||||
[0x03] = "space",
|
||||
[0x04] = "space",
|
||||
[0x05] = "space",
|
||||
[0x06] = "space",
|
||||
[0x07] = "space",
|
||||
[0x08] = "space",
|
||||
[0x09] = "space",
|
||||
[0x0A] = "space",
|
||||
[0x0B] = "space",
|
||||
[0x0C] = "space",
|
||||
[0x0D] = "space",
|
||||
[0x0E] = "space",
|
||||
[0x0F] = "space",
|
||||
|
||||
[0x10] = "space",
|
||||
[0x11] = "space",
|
||||
[0x12] = "space",
|
||||
[0x13] = "space",
|
||||
[0x14] = "space",
|
||||
[0x15] = "space",
|
||||
[0x16] = "space",
|
||||
[0x17] = "space",
|
||||
[0x18] = "space",
|
||||
[0x19] = "space",
|
||||
[0x1A] = "space",
|
||||
[0x1B] = "space",
|
||||
[0x1C] = "space",
|
||||
[0x1D] = "space",
|
||||
[0x1E] = "space",
|
||||
[0x1F] = "space",
|
||||
|
||||
[0x20] = "space",
|
||||
[0x21] = "bang",
|
||||
[0x22] = "apostrophe2",
|
||||
[0x23] = "pound",
|
||||
[0x24] = "dollar",
|
||||
[0x25] = "percent",
|
||||
[0x26] = "and",
|
||||
[0x27] = "apostrophe",
|
||||
[0x28] = "roundbracketleft",
|
||||
[0x29] = "roundbracketright",
|
||||
[0x2A] = "asterisk",
|
||||
[0x2B] = "plus",
|
||||
[0x2C] = "comma",
|
||||
[0x2D] = "minus",
|
||||
[0x2E] = "period",
|
||||
[0x2F] = "slashright",
|
||||
|
||||
[0x30] = "0",
|
||||
[0x31] = "1",
|
||||
[0x32] = "2",
|
||||
[0x33] = "3",
|
||||
[0x34] = "4",
|
||||
[0x35] = "5",
|
||||
[0x36] = "6",
|
||||
[0x37] = "7",
|
||||
[0x38] = "8",
|
||||
[0x39] = "9",
|
||||
[0x3A] = "colon",
|
||||
[0x3B] = "semicolon",
|
||||
[0x3C] = "less_than",
|
||||
[0x3D] = "equals",
|
||||
[0x3E] = "greater_than",
|
||||
[0x3F] = "qmark",
|
||||
|
||||
[0x40] = "at",
|
||||
[0x41] = "A",
|
||||
[0x42] = "B",
|
||||
[0x43] = "C",
|
||||
[0x44] = "D",
|
||||
[0x45] = "E",
|
||||
[0x46] = "F",
|
||||
[0x47] = "G",
|
||||
[0x48] = "H",
|
||||
[0x49] = "I",
|
||||
[0x4A] = "J",
|
||||
[0x4B] = "K",
|
||||
[0x4C] = "L",
|
||||
[0x4D] = "M",
|
||||
[0x4E] = "N",
|
||||
[0x4F] = "O",
|
||||
|
||||
[0x50] = "P",
|
||||
[0x51] = "Q",
|
||||
[0x52] = "R",
|
||||
[0x53] = "S",
|
||||
[0x54] = "T",
|
||||
[0x55] = "U",
|
||||
[0x56] = "V",
|
||||
[0x57] = "W",
|
||||
[0x58] = "X",
|
||||
[0x59] = "Y",
|
||||
[0x5A] = "Z",
|
||||
[0x5B] = "squarebracketleft",
|
||||
[0x5C] = "slashleft",
|
||||
[0x5D] = "squarebracketright",
|
||||
[0x5E] = "caret",
|
||||
[0x5F] = "underscore",
|
||||
|
||||
[0x60] = "backtick",
|
||||
[0x61] = "Alcase",
|
||||
[0x62] = "Blcase",
|
||||
[0x63] = "Clcase",
|
||||
[0x64] = "Dlcase",
|
||||
[0x65] = "Elcase",
|
||||
[0x66] = "Flcase",
|
||||
[0x67] = "Glcase",
|
||||
[0x68] = "Hlcase",
|
||||
[0x69] = "Ilcase",
|
||||
[0x6A] = "Jlcase",
|
||||
[0x6B] = "Klcase",
|
||||
[0x6C] = "Llcase",
|
||||
[0x6D] = "Mlcase",
|
||||
[0x6E] = "Nlcase",
|
||||
[0x6F] = "Olcase",
|
||||
|
||||
[0x70] = "Plcase",
|
||||
[0x71] = "Qlcase",
|
||||
[0x72] = "Rlcase",
|
||||
[0x73] = "Slcase",
|
||||
[0x74] = "Tlcase",
|
||||
[0x75] = "Ulcase",
|
||||
[0x76] = "Vlcase",
|
||||
[0x77] = "Wlcase",
|
||||
[0x78] = "Xlcase",
|
||||
[0x79] = "Ylcase",
|
||||
[0x7A] = "Zlcase",
|
||||
[0x7B] = "curlybracketleft",
|
||||
[0x7C] = "verticalbar",
|
||||
[0x7D] = "curlybracketright",
|
||||
[0x7E] = "tilde",
|
||||
[0x7F] = "space",
|
||||
|
||||
[0x80] = "poundsymbol",
|
||||
[0x81] = "currencysign",
|
||||
[0x82] = "euro",
|
||||
[0x83] = "onehalf",
|
||||
[0x84] = "umlaut",
|
||||
}
|
7
bricks/outputs/text2-init.lua
Normal file
7
bricks/outputs/text2-init.lua
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
return function(gate)
|
||||
gate.lastTickChanged = 0
|
||||
gate.listenState = "wait"
|
||||
gate.bitsReceived = 0
|
||||
gate.valReceived = 0
|
||||
end
|
57
bricks/outputs/text2-update.lua
Normal file
57
bricks/outputs/text2-update.lua
Normal file
@ -0,0 +1,57 @@
|
||||
|
||||
local function getBit(gate, val)
|
||||
--print("get bit", val)
|
||||
if gate.listenState=="wait" then
|
||||
if val==1 then
|
||||
gate.listenState = "getbits"
|
||||
gate.bitsReceived = 0
|
||||
--print("", "state = listen")
|
||||
end
|
||||
elseif gate.listenState=="getbits" then
|
||||
gate.valReceived = gate.valReceived + math.pow(2, textbrick2_bitsNeeded-1-gate.bitsReceived)*val
|
||||
gate.bitsReceived = gate.bitsReceived+1
|
||||
|
||||
--print("", "append", gate.bitsReceived-1, val)
|
||||
|
||||
if gate.bitsReceived==textbrick2_bitsNeeded then
|
||||
|
||||
gate.listenState = "terminate"
|
||||
end
|
||||
elseif gate.listenState=="terminate" then
|
||||
if val==1 then
|
||||
print("", "terminate")
|
||||
|
||||
local printid = gate.valReceived
|
||||
local printname = textbrick2_idxToPrint[printid]
|
||||
|
||||
gate:cb(printname)
|
||||
|
||||
--print("", "set print", string.format("%02x", printid), printname)
|
||||
end
|
||||
|
||||
gate.listenState = "wait"
|
||||
|
||||
gate.bitsReceived = 0
|
||||
gate.valReceived = 0
|
||||
end
|
||||
end
|
||||
|
||||
local function changeTo(gate, val)
|
||||
local tick = gate:gettick()
|
||||
local ticks = tick-gate.lastTickChanged
|
||||
|
||||
local bits = math.min(ticks, 10)
|
||||
for i = 1, bits do
|
||||
getBit(gate, val)
|
||||
end
|
||||
|
||||
gate.lastTickChanged = tick
|
||||
end
|
||||
|
||||
return function(gate)
|
||||
if gate.ports[1]:isrising() then
|
||||
changeTo(gate, 0)
|
||||
elseif gate.ports[1]:isfalling() then
|
||||
changeTo(gate, 1)
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user