Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This module contains code which is used to communicate with Arduino.
- -- Length of packets sent by Arduino on state requests
- local OUTPUTS_COUNT = 8
- local INPUTS_COUNT = 8
- local ANALOGS_COUNT = 8
- local RELAYS_COUNT = 6
- local TIME_LENGTH = 2+2
- local DATE_LENGTH = 4+2+2
- local STATE_PACKET_SIZE =
- RELAYS_COUNT +
- INPUTS_COUNT +
- OUTPUTS_COUNT +
- ANALOGS_COUNT*4 +
- TIME_LENGTH +
- DATE_LENGTH +
- 1 -- 'e'
- local message = "test 2"
- -- Utility functions.
- local function setData(data)
- message = data:gsub("%ยง","")
- end
- ---------------------------------------------------------------------------------------------------------------------
- local atmega = {}
- -- Send command, e.g. R1 or O2
- function atmega.sendCommand(cmd)
- uart.write(0, "C" .. cmd)
- end
- function atmega.getMessage()
- return message
- end
- ---------------------------------------------------------------------------------------------------------------------
- -- Arduino sends only state packets via Serial.
- --uart.on("data", "e", parseState, 0)
- uart.on("data", "ยง", setData, 0)
- -- Start polling
- tmr.alarm(3, 1000, 1, function()
- atmega.sendCommand("ss")
- end)
- ---------------------------------------------------------------------------------------------------------------------
- return atmega
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement