github.com/simpleiot/simpleiot@v0.18.3/frontend/src/Components/NodeModbus.elm (about)

     1  module Components.NodeModbus exposing (view)
     2  
     3  import Api.Point as Point
     4  import Components.NodeOptions exposing (NodeOptions, oToInputO)
     5  import Element exposing (..)
     6  import Element.Border as Border
     7  import UI.Icon as Icon
     8  import UI.NodeInputs as NodeInputs
     9  import UI.Style exposing (colors)
    10  import UI.ViewIf exposing (viewIf)
    11  
    12  
    13  view : NodeOptions msg -> Element msg
    14  view o =
    15      let
    16          disabled =
    17              Point.getBool o.node.points Point.typeDisabled ""
    18      in
    19      column
    20          [ width fill
    21          , Border.widthEach { top = 2, bottom = 0, left = 0, right = 0 }
    22          , Border.color colors.black
    23          , spacing 6
    24          ]
    25      <|
    26          wrappedRow [ spacing 10 ]
    27              [ Icon.bus
    28              , text <|
    29                  Point.getText o.node.points Point.typeDescription ""
    30              , viewIf disabled <| text "(disabled)"
    31              ]
    32              :: (if o.expDetail then
    33                      let
    34                          labelWidth =
    35                              180
    36  
    37                          opts =
    38                              oToInputO o labelWidth
    39  
    40                          textInput =
    41                              NodeInputs.nodeTextInput opts "0"
    42  
    43                          numberInput =
    44                              NodeInputs.nodeNumberInput opts "0"
    45  
    46                          counterWithReset =
    47                              NodeInputs.nodeCounterWithReset opts "0"
    48  
    49                          optionInput =
    50                              NodeInputs.nodeOptionInput opts "0"
    51  
    52                          checkboxInput =
    53                              NodeInputs.nodeCheckboxInput opts "0"
    54  
    55                          clientServer =
    56                              Point.getText o.node.points Point.typeClientServer ""
    57  
    58                          protocol =
    59                              Point.getText o.node.points Point.typeProtocol ""
    60                      in
    61                      [ textInput Point.typeDescription "Description" ""
    62                      , optionInput Point.typeClientServer
    63                          "Client/Server"
    64                          [ ( Point.valueClient, "client" )
    65                          , ( Point.valueServer, "server" )
    66                          ]
    67                      , optionInput Point.typeProtocol
    68                          "Protocol"
    69                          [ ( Point.valueRTU, "RTU" )
    70                          , ( Point.valueTCP, "TCP" )
    71                          ]
    72                      , viewIf
    73                          (protocol == Point.valueRTU)
    74                        <|
    75                          textInput Point.typePort "Port" "/dev/ttyUSB0"
    76                      , viewIf
    77                          (protocol
    78                              == Point.valueTCP
    79                              && clientServer
    80                              == Point.valueServer
    81                          )
    82                        <|
    83                          textInput Point.typePort "Port" "502"
    84                      , viewIf
    85                          (protocol
    86                              == Point.valueTCP
    87                              && clientServer
    88                              == Point.valueClient
    89                          )
    90                        <|
    91                          textInput Point.typeURI "URI" "192.168.1.201:502"
    92                      , viewIf (protocol == Point.valueRTU) <| textInput Point.typeBaud "Baud" "9600"
    93                      , viewIf (clientServer == Point.valueServer) <|
    94                          numberInput Point.typeID "Device ID"
    95                      , viewIf (clientServer == Point.valueClient) <|
    96                          numberInput Point.typePollPeriod "Poll period (ms)"
    97                      , numberInput Point.typeDebug "Debug level (0-9)"
    98                      , checkboxInput Point.typeDisabled "Disabled"
    99                      , counterWithReset Point.typeErrorCount Point.typeErrorCountReset "Error Count"
   100                      , counterWithReset Point.typeErrorCountEOF Point.typeErrorCountEOFReset "EOF Error Count"
   101                      , counterWithReset Point.typeErrorCountCRC Point.typeErrorCountCRCReset "CRC Error Count"
   102                      , NodeInputs.nodeKeyValueInput opts Point.typeTag "Tags" "Add Tag"
   103                      ]
   104  
   105                  else
   106                      []
   107                 )