Skip to content

Toolbar: disable or enable developer mode

Jaume Olivé Petrus edited this page Nov 26, 2017 · 1 revision

If you are programming in blocks, the generated Lua code can be generated with the developer mode option enabled or disabled.

When the developer mode option is enabled the generated code is protected by a try / catch / finally structure, which catch and shows any generated exception in the IDE. Also, this mode, adds code to show the execution flow of your program.

The developer mode option is useful when you are writing programs, but when the programs have been tested and work correctly, you can disabled it to generate a more simple and efficient code.

For example, this program:

Lua program generated with the developer mode option enabled:

require("block")

-- this event is for sync the end of the board start with threads
-- that must wait for this situation
_eventBoardStarted = event.create()

-- thread
thread.start(function()
  _eventBoardStarted:wait()

  wcBlock.blockStart(2)
  while true do
    try(
      function()
        -- begin: invert digital pin value pio.GPIO26
        try(
          function()
            if ((_pio_GPIO26 == nil) or (_pio_GPIO26 == pio.INPUT)) then
              _pio_GPIO26 = pio.OUTPUT
              pio.pin.setdir(pio.OUTPUT, pio.GPIO26)
              pio.pin.setpull(pio.NOPULL, pio.GPIO26)
            end

            pio.pin.inv(pio.GPIO26)
          end,
          function(where, line, err, message)
            wcBlock.blockError(1, err, message)
          end
        )
        -- end: invert digital pin value pio.GPIO26

        -- wait some time
        tmr.delay(math.floor(1))
      end,
      function(where, line, err, message)
        wcBlock.blockError(2, err, message)
      end
    )
  end
  wcBlock.blockEnd(2)
end)

thread.start(function()
  -- board is started
  _eventBoardStarted:broadcast(false)
end)

Lua program generated without the developer mode option enabled:

require("block")

-- this event is for sync the end of the board start with threads
-- that must wait for this situation
_eventBoardStarted = event.create()

-- thread
thread.start(function()
  _eventBoardStarted:wait()

  while true do
    -- begin: invert digital pin value pio.GPIO26
    if ((_pio_GPIO26 == nil) or (_pio_GPIO26 == pio.INPUT)) then
      _pio_GPIO26 = pio.OUTPUT
      pio.pin.setdir(pio.OUTPUT, pio.GPIO26)
      pio.pin.setpull(pio.NOPULL, pio.GPIO26)
    end

    pio.pin.inv(pio.GPIO26)
    -- end: invert digital pin value pio.GPIO26

    -- wait some time
    tmr.delay(math.floor(1))
  end
end)

thread.start(function()
  -- board is started
  _eventBoardStarted:broadcast(false)
end)
Clone this wiki locally