Skip to main content

MOS350 GPIO Integration

Version 1.0

The MOS350 GPIO Config file is a JSON file that defines GPIO pin integration settings. This document covers all elements of the GPIO configuration definition file and their usage. Configuration files use the extension .cf.

tip

MOS350 includes a built-in Blockly visual editor that simplifies building config files without writing JSON by hand. The editor provides drag-and-drop blocks for all config elements and generates the .cf file automatically. Manual JSON editing is only needed for advanced or custom use cases.


Top-Level Elements

ElementTypeDescription
VERstringFile version
TYPintegerIntegration type. 1 = GPIO
FLGintegerGlobal flags. 1 = Auto Load
MAParrayArray of GPIO pin definitions

Example

{
"VER": "1.0",
"TYP": 1,
"FLG": 1,
"MAP": []
}

MAP — GPIO Pin Definitions

MAP is an array of pin objects. Each object maps a named pin to its hardware configuration.

ElementTypeDescription
NMstringPin name used to reference this pin in automation
TYPintegerGPIO access type. See GPIO Access Types
PINstringPin number or offset, depending on access type
DIRintegerPin direction. 1 = Output, 0 = Input
CHIPintegerChip number. Required when TYP is 3 (GPIO Device), ignored otherwise
ALOWintegerActive low. 1 = active low, 0 = active high (default)

GPIO Access Types

ValueDescription
1Sys Class — uses sys/class/gpio
2Kernel Driver — uses sys/class/<pin>
3GPIO Device — uses gpioget / gpioset with a chip number and pin offset
4Custom

Example

{
"VER": "1.0",
"TYP": 1,
"FLG": 1,
"MAP": [
{
"NM": "GRID_SENSE",
"TYP": 1,
"PIN": "17",
"DIR": 0,
"CHIP": 0,
"ALOW": 0
},
{
"NM": "RELAY_OUT",
"TYP": 3,
"PIN": "4",
"DIR": 1,
"CHIP": 0,
"ALOW": 0
}
]
}

Example — InHand Gateway (4 Digital Outputs, Active Low)

{
"VER": "1.0",
"TYP": 1,
"FLG": 1,
"MAP": [
{ "NM": "DO1", "TYP": 1, "PIN": "491", "DIR": 1, "CHIP": 0, "ALOW": 1 },
{ "NM": "DO2", "TYP": 1, "PIN": "492", "DIR": 1, "CHIP": 0, "ALOW": 1 },
{ "NM": "DO3", "TYP": 1, "PIN": "493", "DIR": 1, "CHIP": 0, "ALOW": 1 },
{ "NM": "DO4", "TYP": 1, "PIN": "494", "DIR": 1, "CHIP": 0, "ALOW": 1 }
]
}

Four digital output pins accessed via Sys Class (TYP: 1), mapped to sequential pin numbers starting at 491. All outputs are active low (ALOW: 1), meaning a logical 1 drives the pin low.


Using GPIO in Lua Scripts

Once configured, GPIO pins are accessible in Lua automation scripts via getDeviceState() and setDeviceState(). Reference the device by its user variable name (e.g. "_GPIO1") or device ID.

-- Read an input pin
local status, value = getDeviceState("_GPIO1")
if status then
print("GPIO state:", value)
end

-- Write to an output pin
setDeviceState("_GPIO1", 1)

See the Lua Scripting documentation for the full getDeviceState() and setDeviceState() API reference.