예제 #1
0
    def webform_load(self):  # create html page for settings
        choice2 = int(float(
            self.taskdevicepluginconfig[1]))  # store i2c address
        options = ["0x3c", "0x3d"]
        optionvalues = [0x3c, 0x3d]
        ws.addFormSelector("Address", "p023_adr", len(options), options,
                           optionvalues, None, choice2)
        ws.addFormNote(
            "Enable <a href='hardware'>I2C bus</a> first, than <a href='i2cscanner'>search for the used address</a>!"
        )
        choice3 = int(float(
            self.taskdevicepluginconfig[2]))  # store rotation state
        options = ["Normal", "Rotate by 180"]
        optionvalues = [0, 2]
        ws.addFormSelector("Mode", "p023_rotate", len(optionvalues), options,
                           optionvalues, None, choice3)
        options = [
            "128x64", "128x128", "128x32", "96x96", "96x64", "64x48", "64x32"
        ]
        choice4 = self.taskdevicepluginconfig[3]  # store resolution
        ws.addHtml("<tr><td>Resolution:<td>")
        ws.addSelector_Head("p023_res", False)
        for d in range(len(options)):
            ws.addSelector_Item(options[d], options[d],
                                (choice4 == options[d]), False)
        ws.addSelector_Foot()

        choice5 = int(float(
            self.taskdevicepluginconfig[4]))  # store line count
        ws.addHtml("<tr><td>Number of lines:<td>")
        ws.addSelector_Head("p023_linecount", False)
        for l in range(1, self.P23_Nlines + 1):
            ws.addSelector_Item(str(l), l, (l == choice5), False)
        ws.addSelector_Foot()
        ws.addFormNumericBox("Try to display # characters per row",
                             "p023_charperl", self.taskdevicepluginconfig[5],
                             1, 32)
        ws.addFormNote("Leave it '1' if you do not care")
        ws.addFormCheckBox("Clear only used lines", "p023_partialclear",
                           self.taskdevicepluginconfig[6])
        if choice5 > 0 and choice5 < 9:
            lc = choice5
        else:
            lc = self.P23_Nlines
        for l in range(lc):
            try:
                linestr = self.lines[l]
            except:
                linestr = ""
            ws.addFormTextBox("Line" + str(l + 1), "p023_template" + str(l),
                              linestr, 128)

        return True
예제 #2
0
 def webform_load(self):
     choice1 = self.addresstostr(self.taskdevicepluginconfig[0])
     self._roms = self.find_dsb_devices()
     options = []
     for opts in self._roms:
         options.append(self.addresstostr(opts))
     if len(options) > 0:
         ws.addHtml("<tr><td>Device Address:<td>")
         ws.addSelector_Head("p004_addr", True)
         for o in range(len(options)):
             ws.addSelector_Item(options[o], options[o],
                                 (str(options[o]) == str(choice1)), False)
         ws.addSelector_Foot()
     return True
예제 #3
0
 def webform_load(self): # create html page for settings
  ws.addFormCheckBox("Use standard HTML head","p212_head",self.taskdevicepluginconfig[2])
  try:
   sp = settings.AdvSettings["startpage"]
  except:
   sp = "/"
  ws.addFormCheckBox("Set as startpage","p212_start",(sp=="/dash"))
  ws.addHtml("<tr><td>Columns:<td>")
  ws.addSelector_Head("p212_cols",False)
  for o in range(7):
   ws.addSelector_Item(str(o),o,(str(o)==str(self.taskdevicepluginconfig[0])),False)
  ws.addSelector_Foot()

  ws.addHtml("<tr><td>Rows:<td>")
  ws.addSelector_Head("p212_rows",False)
  for o in range(16):
   ws.addSelector_Item(str(o),o,(str(o)==str(self.taskdevicepluginconfig[1])),False)
  ws.addSelector_Foot()

  if int(self.taskdevicepluginconfig[0])>0 and int(self.taskdevicepluginconfig[1])>0:
   if self.enabled:
    ws.addHtml("<tr><td>Dashboard address:</td><td><a href='dash'>/dash</a></td></tr>")
   options1 = ["None","Text","Binary input","Switch output","Meter","Gauge","Slider output","Select output"]
   optionvalues1 = [-1,0,1,2,3,4,5,6]
   options2 = ["None"]
   optionvalues2 = ["_"]
   try:
    for t in range(0,len(settings.Tasks)):
     if (settings.Tasks[t] and (type(settings.Tasks[t]) is not bool)):
      for v in range(0,settings.Tasks[t].valuecount):
       options2.append("T"+str(t+1)+"-"+str(v+1)+" / "+str(settings.Tasks[t].taskname)+"-"+str(settings.Tasks[t].valuenames[v]))
       optionvalues2.append(str(t)+"_"+str(v))
   except Exception as e:
    print(e)
   for r in range(int(self.taskdevicepluginconfig[1])):
    try:
     for c in range(int(self.taskdevicepluginconfig[0])):
      offs = (r * int(self.taskdevicepluginconfig[0])) + c
      try:
       adata = self.celldata[offs]
      except:
       adata = {}
      dtype = -1
      if "type" in adata:
       dtype = int(adata["type"])
      ws.addHtml("<tr><td><b>Cell"+str(offs)+" (y"+str(r)+"x"+str(c)+")</b><td>")

      dname = ""
      if "name" in adata:
       dname = str(adata["name"])
      ws.addFormTextBox("Name overwrite","p212_names_"+str(offs),dname,64)

      ws.addFormSelector("Type","p212_type_"+str(offs),len(options1),options1,optionvalues1,None,dtype)
      ws.addHtml("<tr><td>Data source:<td>")
      ddata = "_"
      if "data" in adata:
       ddata = str(adata["data"])
      ws.addSelector_Head("p212_data_"+str(offs),False)
      for o in range(len(options2)):
       ws.addSelector_Item(options2[o],optionvalues2[o],(str(optionvalues2[o])==str(ddata)),False)
      ws.addSelector_Foot()

      if dtype in (0,4):
       try:
        udata = str(adata["unit"])
       except:
        udata = ""
       ws.addFormTextBox("Unit","p212_unit_"+str(offs),udata,16)
      if dtype in (3,4,5):
       try:
        umin = float(adata["min"])
       except:
        umin = 0
       try:
        umax = float(adata["max"])
       except:
        umax = 100
       ws.addFormFloatNumberBox("Min value","p212_min_"+str(offs),umin,-65535.0,65535.0)
       ws.addFormFloatNumberBox("Max value","p212_max_"+str(offs),umax,-65535.0,65535.0)
      elif dtype == 6:
       try:
        uon = str(adata["optionnames"])
       except:
        uon = ""
       try:
        uopt = str(adata["options"])
       except:
        uopt = ""
       ws.addFormTextBox("Option name list","p212_optionnames_"+str(offs),uon,1024)
       ws.addFormTextBox("Option value list","p212_options_"+str(offs),uopt,1024)
       ws.addFormNote("Input comma separated values for selector boxes!")
     httpResponse._write(ws.TXBuffer,strEncoding='UTF-8')
     ws.TXBuffer = ""
    except:
     pass
  return True
예제 #4
0
def handle_devices(httpResponse, responsearr):
    ws.navMenuIndex = 4
    ws.TXBuffer = ""
    httpResponse.WriteResponseOk(headers=({
        'Cache-Control': 'no-cache'
    }),
                                 contentType='text/html',
                                 contentCharset='UTF-8',
                                 content="")

    taskdevicenumber = ws.arg('TDNUM', responsearr)
    if taskdevicenumber == '':
        taskdevicenumber = 0
    else:
        taskdevicenumber = int(float(taskdevicenumber))

    taskdevicetimer = ws.arg('TDT', responsearr)
    if taskdevicetimer == '':
        taskdevicetimer = 0
    else:
        taskdevicetimer = float(taskdevicetimer)

    edit = ws.arg("edit", responsearr)
    page = ws.arg("page", responsearr)
    setpage = ws.arg("setpage", responsearr)
    taskIndex = ws.arg("index", responsearr)
    runIndex = ws.arg("run", responsearr)

    if page == '':
        page = 0
    else:
        page = int(float(page))
    if page == 0:
        page = 1
    if setpage == '':
        setpage = 0
    else:
        setpage = int(float(setpage))
    if (setpage > 0):
        if setpage <= (pglobals.TASKS_MAX / ws.TASKS_PER_PAGE):
            page = setpage
        else:
            page = int(pglobals.TASKS_MAX / ws.TASKS_PER_PAGE)

    ws.sendHeadandTail("TmplStd", ws._HEAD)
    taskIndexNotSet = (taskIndex == 0) or (taskIndex == '')

    if taskIndex != "":
        taskIndex = int(taskIndex) - 1
    if ws.arg('del', responsearr) != '':
        taskdevicenumber = 0
        ttid = -1
        try:
            ttid = settings.Tasks[taskIndex].pluginid
        except:
            ttid = -1

        if ttid != -1:
            try:
                settings.Tasks[taskIndex].plugin_exit()
                taskIndexNotSet = True
                settings.Tasks[taskIndex] = False
                settings.savetasks()  # savetasksettings!!!
            except Exception as e:
                misc.addLog(pglobals.LOG_LEVEL_ERROR,
                            "Deleting failed: " + str(e))

    if runIndex != "":
        if len(settings.Tasks) < 1:
            return False
        try:
            s = int(runIndex)
        except:
            s = -1
        try:
            if s > 0 and (s <= len(settings.Tasks)):
                s = s - 1  # array is 0 based, tasks is 1 based
                if (type(settings.Tasks[s]) != bool) and (settings.Tasks[s]):
                    if (settings.Tasks[s].enabled):
                        settings.Tasks[s].plugin_read()
        except Exception as e:
            print(e)
    httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
    ws.TXBuffer = ""

    if taskIndexNotSet == False:  #Show edit form if a specific entry is chosen with the edit button

        ws.TXBuffer += "<form name='frmselect' method='post'><table class='normal'>"
        ws.addFormHeader("Task Settings")
        ws.TXBuffer += "<TR><TD style='width:150px;' align='left'>Device:<TD>"
        tte = taskdevicenumber
        try:
            tte = settings.Tasks[taskIndex].pluginid
        except:
            pass
        if (tte <= 0):
            ws.addSelector_Head("TDNUM", True)
            for y in range(0, len(pglobals.deviceselector)):
                pname = pglobals.deviceselector[y][2]
                try:
                    if int(pglobals.deviceselector[y][1]) != 0:
                        pname = "P" + str(int(
                            pglobals.deviceselector[y][1])).rjust(
                                3, "0") + " - " + pglobals.deviceselector[y][2]
                except:
                    pass
                ws.addSelector_Item(pname, int(pglobals.deviceselector[y][1]),
                                    (pglobals.deviceselector[y][1] == tte),
                                    False, "")
            ws.addSelector_Foot()
            httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
            ws.TXBuffer = ""
        else:  # device selected
            createnewdevice = True
            try:
                if (settings.Tasks[taskIndex].getpluginid() == int(tte)):
                    createnewdevice = False
            except:
                pass
            exceptstr = ""
            gc.collect()
            if createnewdevice:
                for y in range(len(pglobals.deviceselector)):
                    if int(pglobals.deviceselector[y][1]) == int(tte):
                        if len(settings.Tasks) <= taskIndex:
                            while len(settings.Tasks) <= taskIndex:
                                settings.Tasks.append(False)
                        try:
                            m = __import__(pglobals.deviceselector[y][0])
                        except Exception as e:
                            settings.Tasks[taskIndex] = False
                            exceptstr += str(e)
                            m = False
                        if m:
                            try:
                                settings.Tasks[taskIndex] = m.Plugin(taskIndex)
                            except Exception as e:
                                settings.Tasks.append(m.Plugin(taskIndex))
                                exceptstr += str(e)
                        break
            if settings.Tasks[taskIndex] == False:
                ws.TXBuffer += "Importing failed: {0}</td></tr></table>".format(
                    exceptstr)
                ws.sendHeadandTail("TmplStd", ws._TAIL)
                httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
                ws.TXBuffer = ""
                return True
            else:
                try:
                    enableit = (ws.arg("TDE", responsearr) == "on")
                    #        print("plugin init",enableit)
                    if enableit:
                        settings.Tasks[taskIndex].plugin_init(
                            True
                        )  # call plugin init / (ws.arg("TDE",responsearr) == "on")
                    else:
                        settings.Tasks[taskIndex].plugin_init(
                        )  # call plugin init / (ws.arg("TDE",responsearr) == "on")
                except:
                    pass

            if edit != '' and not (taskIndexNotSet):  # when form submitted
                if taskdevicenumber != 0:  # save settings
                    if taskdevicetimer > 0:
                        settings.Tasks[taskIndex].interval = taskdevicetimer
                    else:
                        if not (settings.Tasks[taskIndex].timeroptional
                                ):  # set default delay
                            settings.Tasks[
                                taskIndex].interval = settings.Settings[
                                    "Delay"]
                        else:
                            settings.Tasks[taskIndex].interval = 0
                tasknamestr = str(ws.arg("TDN", responsearr)).strip()
                settings.Tasks[taskIndex].taskname = tasknamestr.replace(
                    " ", "")
                if tasknamestr:
                    settings.Tasks[taskIndex].taskdeviceport = ws.arg(
                        "TDP", responsearr)
                    maxcon = len(settings.Controllers)
                    if maxcon > pglobals.CONTROLLER_MAX:
                        maxcon = pglobals.CONTROLLER_MAX
                    for controllerNr in range(0, maxcon):
                        if ((settings.Controllers[controllerNr]) and
                            (settings.Controllers[controllerNr].enabled)):
                            sid = "TDSD"
                            sid += str(controllerNr + 1)
                            settings.Tasks[taskIndex].senddataenabled[
                                controllerNr] = (ws.arg(sid,
                                                        responsearr) == "on")
                            if (settings.Tasks[taskIndex].
                                    senddataenabled[controllerNr]):
                                if (settings.Controllers[controllerNr]):
                                    if (settings.Controllers[controllerNr].
                                            enabled):
                                        settings.Tasks[taskIndex].controllercb[
                                            controllerNr] = settings.Controllers[
                                                controllerNr].senddata
                            if (settings.Tasks[taskIndex].
                                    senddataenabled[controllerNr]):
                                sid = "TDID"
                                sid += str(controllerNr + 1)
                                ctrlidx = str(ws.arg(sid, responsearr)).strip()
                                if ctrlidx == "":
                                    ctrlidx = -1
                                else:
                                    ctrlidx = int(ctrlidx)
                                settings.Tasks[taskIndex].controlleridx[
                                    controllerNr] = ctrlidx

                    for pins in range(0, 4):
                        pinnum = ws.arg("taskdevicepin" + str(pins + 1),
                                        responsearr)
                        if pinnum:
                            settings.Tasks[taskIndex].taskdevicepin[
                                pins] = int(pinnum)


#        if settings.Tasks[taskIndex].pullupoption:
#         settings.Tasks[taskIndex].pullup = (ws.arg("TDPPU",responsearr) == "on")
                    if settings.Tasks[taskIndex].inverselogicoption:
                        settings.Tasks[taskIndex].pininversed = (ws.arg(
                            "TDPI", responsearr) == "on")

                    for varnr in range(0,
                                       settings.Tasks[taskIndex].valuecount):
                        tvname = str(
                            ws.arg("TDVN" + str(varnr + 1), responsearr))
                        if tvname:
                            settings.Tasks[taskIndex].valuenames[
                                varnr] = tvname.replace(" ", "")
                            settings.Tasks[taskIndex].formula[varnr] = ws.arg(
                                "TDF" + str(varnr + 1), responsearr)
                            tvdec = ws.arg("TDVD" + str(varnr + 1),
                                           responsearr)
                            if tvdec == "" or tvdec == False or tvdec == None:
                                tvdec = 0
                            settings.Tasks[taskIndex].decimals[varnr] = tvdec
                        else:
                            settings.Tasks[taskIndex].valuenames[varnr] = ""

                    try:
                        settings.Tasks[taskIndex].i2c = int(
                            ws.arg("i2c", responsearr))
                    except:
                        settings.Tasks[taskIndex].i2c = -1
                    try:
                        settings.Tasks[taskIndex].spi = int(
                            ws.arg("spi", responsearr))
                    except:
                        settings.Tasks[taskIndex].spi = -1

                    if settings.Tasks[taskIndex].taskname == "":
                        settings.Tasks[taskIndex].enabled = False

                    settings.Tasks[taskIndex].webform_save(
                        responsearr)  # call plugin read FORM
                    settings.Tasks[taskIndex].enabled = (ws.arg(
                        "TDE", responsearr) == "on")
                    settings.savetasks()  # savetasksettings!!!

            ws.TXBuffer += "<input type='hidden' name='TDNUM' value='{0}'>{1}".format(
                settings.Tasks[taskIndex].pluginid,
                settings.Tasks[taskIndex].getdevicename())

            ws.addFormTextBox("Name", "TDN",
                              str(settings.Tasks[taskIndex].gettaskname()), 40)
            ws.addFormCheckBox("Enabled", "TDE",
                               settings.Tasks[taskIndex].enabled)
            # section: Sensor / Actuator
            httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
            ws.TXBuffer = ""
            if (settings.Tasks[taskIndex].dtype >= pglobals.DEVICE_TYPE_SINGLE
                    and settings.Tasks[taskIndex].dtype <=
                    pglobals.DEVICE_TYPE_QUAD):
                ws.addFormSubHeader("Sensor" if settings.Tasks[taskIndex].
                                    senddataoption else "Actuator")

                #        if (Settings.Tasks[taskIndex].ports != 0):
                #          addFormNumericBox("Port", "TDP", Settings.Tasks[taskIndex].taskdeviceport)
                #        if (settings.Tasks[taskIndex].pullupoption):
                #          ws.addFormCheckBox("Internal PullUp", "TDPPU", settings.Tasks[taskIndex].pullup)
                if (settings.Tasks[taskIndex].inverselogicoption):
                    ws.addFormCheckBox("Inversed Logic", "TDPI",
                                       settings.Tasks[taskIndex].pininversed)
                if (settings.Tasks[taskIndex].dtype >=
                        pglobals.DEVICE_TYPE_SINGLE
                        and settings.Tasks[taskIndex].dtype <=
                        pglobals.DEVICE_TYPE_QUAD):
                    ws.addFormPinSelect(
                        "1st GPIO", "taskdevicepin1",
                        settings.Tasks[taskIndex].taskdevicepin[0],
                        settings.Tasks[taskIndex].pinfilter[0])
                if (settings.Tasks[taskIndex].dtype >=
                        pglobals.DEVICE_TYPE_DUAL
                        and settings.Tasks[taskIndex].dtype <=
                        pglobals.DEVICE_TYPE_QUAD):
                    ws.addFormPinSelect(
                        "2nd GPIO", "taskdevicepin2",
                        settings.Tasks[taskIndex].taskdevicepin[1],
                        settings.Tasks[taskIndex].pinfilter[1])
                if (settings.Tasks[taskIndex].dtype >=
                        pglobals.DEVICE_TYPE_TRIPLE
                        and settings.Tasks[taskIndex].dtype <=
                        pglobals.DEVICE_TYPE_QUAD):
                    ws.addFormPinSelect(
                        "3rd GPIO", "taskdevicepin3",
                        settings.Tasks[taskIndex].taskdevicepin[2],
                        settings.Tasks[taskIndex].pinfilter[2])
                if (settings.Tasks[taskIndex].dtype ==
                        pglobals.DEVICE_TYPE_QUAD):
                    ws.addFormPinSelect(
                        "4th GPIO", "taskdevicepin4",
                        settings.Tasks[taskIndex].taskdevicepin[3],
                        settings.Tasks[taskIndex].pinfilter[3])
            if (settings.Tasks[taskIndex].dtype == pglobals.DEVICE_TYPE_I2C):
                try:
                    import inc.libhw as libhw
                    options = libhw.geti2clist()
                except:
                    options = []
                ws.addHtml("<tr><td>I2C line:<td>")
                ws.addSelector_Head("i2c", True)
                for d in range(len(options)):
                    ws.addSelector_Item(
                        "I2C" + str(options[d]), options[d],
                        (settings.Tasks[taskIndex].i2c == options[d]), False)
                ws.addSelector_Foot()
            if (settings.Tasks[taskIndex].dtype == pglobals.DEVICE_TYPE_SPI):
                try:
                    import inc.libhw as libhw
                    options = libhw.getspilist()
                except:
                    options = []
                ws.addHtml("<tr><td>SPI line:<td>")
                ws.addSelector_Head("spi", True)
                for d in range(len(options)):
                    ws.addSelector_Item(
                        "SPI" + str(options[d]), options[d],
                        (settings.Tasks[taskIndex].spi == options[d]), False)
                ws.addSelector_Foot()

            httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
            ws.TXBuffer = ""
            try:
                settings.Tasks[taskIndex].webform_load(
                )  # call plugin function to fill ws.TXBuffer
            except Exception as e:
                print(e)
            httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
            ws.TXBuffer = ""

            if (settings.Tasks[taskIndex].senddataoption
                ):  # section: Data Acquisition
                ws.addFormSubHeader("Data Acquisition")
                maxcon = len(settings.Controllers)
                if maxcon > pglobals.CONTROLLER_MAX:
                    maxcon = pglobals.CONTROLLER_MAX
                for controllerNr in range(0, maxcon):
                    if ((settings.Controllers[controllerNr])
                            and (settings.Controllers[controllerNr].enabled)):
                        sid = "TDSD"
                        sid += str(controllerNr + 1)

                        ws.TXBuffer += "<TR><TD>Send to Controller {0}<TD>".format(
                            ws.getControllerSymbol(controllerNr))
                        ws.addCheckBox(
                            sid, settings.Tasks[taskIndex].
                            senddataenabled[controllerNr])

                        sid = "TDID"
                        sid += str(controllerNr + 1)

                        if (settings.Controllers[controllerNr].enabled
                            ) and settings.Tasks[taskIndex].senddataenabled[
                                controllerNr]:
                            if (settings.Controllers[controllerNr].usesID):
                                ws.TXBuffer += "<TR><TD>IDX:<TD>"
                                ws.addNumericBox(
                                    sid, settings.Tasks[taskIndex].
                                    controlleridx[controllerNr], 0, 9999)
                            else:
                                ws.TXBuffer += "<input type='hidden' name='{0}' value='0'>".format(
                                    sid)  # no id, set to 0
                        else:
                            ws.TXBuffer += "<input type='hidden' name='{0}' value='-1'>".format(
                                sid)  # disabled set to -1

            ws.addFormSeparator(2)
            httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
            ws.TXBuffer = ""
            if (settings.Tasks[taskIndex].timeroption):
                ws.addFormNumericBox("Interval", "TDT",
                                     settings.Tasks[taskIndex].interval, 0,
                                     65535)
                ws.addUnit("sec")
                if (settings.Tasks[taskIndex].timeroptional):
                    ws.TXBuffer += " (Optional for this Device)"

            if (settings.Tasks[taskIndex].valuecount > 0):  # //section: Values
                ws.addFormSubHeader("Values")
                ws.TXBuffer += "</table><table class='normal'><TR><TH style='width:30px;' align='center'>#<TH align='left'>Name"
                if (settings.Tasks[taskIndex].formulaoption):
                    ws.TXBuffer += "<TH align='left'>Formula"

                if (settings.Tasks[taskIndex].formulaoption
                        or settings.Tasks[taskIndex].decimalsonly):
                    ws.TXBuffer += "<TH style='width:30px;' align='left'>Decimals"

                for varNr in range(0, settings.Tasks[taskIndex].valuecount):
                    ws.TXBuffer += "<TR><TD>{0}<TD>".format(str(varNr + 1))
                    sid = "TDVN" + str(varNr + 1)
                    ws.addTextBox(
                        sid,
                        settings.Tasks[taskIndex].getdevicevaluenames()[varNr],
                        40)

                    if (settings.Tasks[taskIndex].formulaoption):
                        ws.TXBuffer += "<TD>"
                        sid = "TDF" + str(varNr + 1)
                        ws.addTextBox(sid,
                                      settings.Tasks[taskIndex].formula[varNr],
                                      140)

                    if (settings.Tasks[taskIndex].formulaoption
                            or settings.Tasks[taskIndex].decimalsonly):
                        ws.TXBuffer += "<TD>"
                        sid = "TDVD" + str(varNr + 1)
                        ws.addNumericBox(
                            sid, settings.Tasks[taskIndex].decimals[varNr], 0,
                            6)

        ws.addFormSeparator(4)
        httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
        ws.TXBuffer = ""
        gc.collect()
        ws.TXBuffer += "<TR><TD><TD colspan='3'><a class='button link' href='devices?setpage={0}'>Close</a>".format(
            page)
        ws.addSubmitButton()
        ws.TXBuffer += "<input type='hidden' name='edit' value='1'>"
        if taskIndex != '':
            ws.TXBuffer += "<input type='hidden' name='index' value='{0}'>".format(
                taskIndex + 1)
        ws.TXBuffer += "<input type='hidden' name='page' value='1'>"

        if (tte > 0):  # if user selected a device, add the delete button
            ws.addSubmitButton("Delete", "del")

        ws.TXBuffer += "</table></form>"

    ws.sendHeadandTail("TmplStd", ws._TAIL)
    httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
    ws.TXBuffer = ""
예제 #5
0
def handle_controllers(httpResponse, responsearr):
    edit = ws.arg("edit", responsearr)
    controllerindex = ws.arg("index", responsearr)
    controllerNotSet = (controllerindex == 0) or (controllerindex == '')
    if controllerindex != "":
        controllerindex = int(controllerindex) - 1
    controllerip = ws.arg("controllerip", responsearr)
    controllerport = ws.arg("controllerport", responsearr)
    protocol = ws.arg("protocol", responsearr)
    if protocol != "":
        protocol = int(protocol)
    else:
        protocol = 0
    controlleruser = ws.arg("controlleruser", responsearr)
    controllerpassword = ws.arg("controllerpassword", responsearr)
    enabled = (ws.arg("controllerenabled", responsearr) == "on")

    if ((protocol == 0) and (edit == '') and
        (controllerindex != '')) or (ws.arg('del', responsearr) != ''):
        try:
            settings.Controllers[controllerindex].controller_exit()
        except:
            pass
        settings.Controllers[controllerindex] = False
        controllerNotSet = True
        settings.savecontrollers()

    if (controllerNotSet == False):  # submitted
        if (protocol > 0):  # submitted
            try:
                if (settings.Controllers[controllerindex]):
                    settings.Controllers[
                        controllerindex].controllerip = controllerip
                    settings.Controllers[
                        controllerindex].controllerport = controllerport
                    settings.Controllers[
                        controllerindex].controlleruser = controlleruser
                    if "**" not in controllerpassword:
                        settings.Controllers[
                            controllerindex].controllerpassword = controllerpassword
                    settings.Controllers[controllerindex].enabled = enabled
                    settings.Controllers[controllerindex].webform_save(
                        responsearr)
                    settings.savecontrollers()
            except:
                pass
        else:
            try:
                if (settings.Controllers[controllerindex]):
                    protocol = settings.Controllers[
                        controllerindex].controllerid
            except:
                pass
    ws.TXBuffer = ""
    httpResponse.WriteResponseOk(headers=({
        'Cache-Control': 'no-cache'
    }),
                                 contentType='text/html',
                                 contentCharset='UTF-8',
                                 content="")
    ws.navMenuIndex = 2
    ws.sendHeadandTail("TmplStd", ws._HEAD)

    ws.TXBuffer += "<form name='frmselect' method='post'>"
    if (controllerNotSet):  # show all in table
        ws.TXBuffer += "<table class='multirow' border=1px frame='box' rules='all'><TR><TH style='width:70px;'>"
        ws.TXBuffer += "<TH style='width:50px;'>Nr<TH style='width:100px;'>Enabled<TH>Protocol<TH>Host<TH>Port"
        for x in range(pglobals.CONTROLLER_MAX):
            ws.TXBuffer += "<tr><td><a class='button link' href=\"controllers?index="
            ws.TXBuffer += str(x + 1)
            ws.TXBuffer += "&edit=1\">Edit</a><td>"
            ws.TXBuffer += ws.getControllerSymbol(x)
            ws.TXBuffer += "</td><td>"
            try:
                if (settings.Controllers[x]):
                    ws.addEnabled(settings.Controllers[x].enabled)
                    ws.TXBuffer += "</td><td>"
                    ws.TXBuffer += str(
                        settings.Controllers[x].getcontrollername())
                    ws.TXBuffer += "</td><td>"
                    ws.TXBuffer += str(settings.Controllers[x].controllerip)
                    ws.TXBuffer += "</td><td>"
                    ws.TXBuffer += str(settings.Controllers[x].controllerport)
                else:
                    ws.TXBuffer += "<td><td><td>"
            except:
                ws.TXBuffer += "<td><td><td>"
            httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
            ws.TXBuffer = ""
        ws.TXBuffer += "</table></form>"
        httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
        ws.TXBuffer = ""
    else:  # edit
        ws.TXBuffer += "<table class='normal'><TR><TH style='width:150px;' align='left'>Controller Settings<TH>"
        ws.TXBuffer += "<tr><td>Protocol:<td>"
        ws.addSelector_Head("protocol", True)
        for x in range(len(pglobals.controllerselector)):
            ws.addSelector_Item(
                pglobals.controllerselector[x][2],
                int(pglobals.controllerselector[x][1]),
                (str(protocol) == str(pglobals.controllerselector[x][1])),
                False, "")
        ws.addSelector_Foot()
        httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
        ws.TXBuffer = ""
        #    print(protocol)#debug
        if (int(protocol) > 0):
            createnewcontroller = True
            try:
                if (settings.Controllers[controllerindex].getcontrollerid() ==
                        int(protocol)):
                    createnewcontroller = False
            except:
                pass
            exceptstr = ""
            if createnewcontroller:
                for y in range(len(pglobals.controllerselector)):
                    if int(pglobals.controllerselector[y][1]) == int(protocol):
                        if len(settings.Controllers) <= controllerindex:
                            while len(settings.Controllers) <= controllerindex:
                                settings.Controllers.append(False)
                        try:
                            m = __import__(pglobals.controllerselector[y][0])
                        except Exception as e:
                            #          print(str(e))
                            settings.Controllers[controllerindex] = False
                            exceptstr += str(e)
                            m = False
                        gc.collect()
                        if m:
                            try:
                                settings.Controllers[
                                    controllerindex] = m.Controller(
                                        controllerindex)
                            except Exception as e:
                                settings.Controllers.append(
                                    m.Controller(controllerindex))
                                exceptstr += str(e)
                        break
            if settings.Controllers[controllerindex] == False:
                ws.TXBuffer += "Importing failed: {0}</td></tr></table>".format(
                    exceptstr)
                ws.sendHeadandTail("TmplStd", ws._TAIL)
                httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
                ws.TXBuffer = ""
                return True
            else:
                try:
                    settings.Controllers[controllerindex].controller_init(
                    )  # call plugin init
                    if (settings.Controllers[controllerindex]):
                        if (settings.Controllers[controllerindex].enabled):
                            settings.Controllers[
                                controllerindex].setonmsgcallback(
                                    settings.callback_from_controllers)
                    for x in range(0, len(settings.Tasks)):
                        if (settings.Tasks[x] and type(Settings.Tasks[x])
                                is not bool):  # device exists
                            if (settings.Tasks[x].enabled):  # device enabled
                                if (settings.Tasks[x].
                                        senddataenabled[controllerindex]):
                                    if (settings.Controllers[controllerindex]):
                                        if (settings.Controllers[
                                                controllerindex].enabled):
                                            settings.Tasks[x].controllercb[
                                                controllerindex] = settings.Controllers[
                                                    controllerindex].senddata
                except:
                    pass
        if controllerindex != '':
            ws.TXBuffer += "<input type='hidden' name='index' value='" + str(
                controllerindex + 1) + "'>"
            if int(protocol) > 0:
                ws.addFormCheckBox(
                    "Enabled", "controllerenabled",
                    settings.Controllers[controllerindex].enabled)
                ws.addFormTextBox(
                    "Controller Host Address", "controllerip",
                    settings.Controllers[controllerindex].controllerip, 96)
                ws.addFormNumericBox(
                    "Controller Port", "controllerport",
                    settings.Controllers[controllerindex].controllerport, 1,
                    65535)
                if settings.Controllers[controllerindex].usesAccount:
                    ws.addFormTextBox(
                        "Controller User", "controlleruser",
                        settings.Controllers[controllerindex].controlleruser,
                        96)
                if settings.Controllers[controllerindex].usesPassword:
                    ws.addFormPasswordBox(
                        "Controller Password", "controllerpassword", settings.
                        Controllers[controllerindex].controllerpassword, 96)
#      try:
                settings.Controllers[controllerindex].webform_load()


#      except:
#       pass

        ws.addFormSeparator(2)
        ws.TXBuffer += "<tr><td><td>"
        ws.TXBuffer += "<a class='button link' href=\"controllers\">Close</a>"
        ws.addSubmitButton()
        if controllerindex != '':
            ws.addSubmitButton("Delete", "del")
        ws.TXBuffer += "</table></form>"

    ws.sendHeadandTail("TmplStd", ws._TAIL)
    httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
    ws.TXBuffer = ""
예제 #6
0
def handle_adv(httpResponse, responsearr):
    ws.navMenuIndex = 7
    ws.TXBuffer = ""
    httpResponse.WriteResponseOk(headers=({
        'Cache-Control': 'no-cache'
    }),
                                 contentType='text/html',
                                 contentCharset='UTF-8',
                                 content="")

    saved = ws.arg("Submit", responsearr)
    if (saved):
        settings.AdvSettings["webloglevel"] = int(
            ws.arg("webloglevel", responsearr))
        settings.AdvSettings["consoleloglevel"] = int(
            ws.arg("consoleloglevel", responsearr))
        settings.AdvSettings["usentp"] = (ws.arg("usentp",
                                                 responsearr) == "on")
        settings.AdvSettings["ntpserver"] = ws.arg("ntpserver", responsearr)
        settings.AdvSettings["timezone"] = int(ws.arg("timezone", responsearr))
        try:
            settings.AdvSettings["rtci2c"] = int(ws.arg("rtci2c", responsearr))
            if settings.AdvSettings["rtci2c"] >= 0:
                settings.AdvSettings["extrtc"] = int(
                    ws.arg("extrtc", responsearr))
            if settings.AdvSettings["rtcaddr"] >= 0:
                settings.AdvSettings["rtcaddr"] = int(
                    ws.arg("rtcaddr", responsearr))
        except:
            settings.AdvSettings["extrtc"] = 0
            settings.AdvSettings["rtci2c"] = 0
        try:
            settings.AdvSettings["dangerouspins"] = ws.arg(
                "dangerouspins", responsearr)
        except:
            settings.AdvSettings["dangerouspins"] = False
        try:
            settings.AdvSettings["Latitude"] = float(
                ws.arg("latitude", responsearr))
            settings.AdvSettings["Longitude"] = float(
                ws.arg("longitude", responsearr))
        except:
            settings.AdvSettings["Latitude"] = 0
            settings.AdvSettings["Longitude"] = 0
        try:
            settings.AdvSettings["startpage"] = str(
                ws.arg("startpage", responsearr))
        except:
            settings.AdvSettings["startpage"] = "/"
        settings.saveadvsettings()

    ws.sendHeadandTail("TmplStd", ws._HEAD)

    ws.TXBuffer += "<form  method='post'><table class='normal'>"
    ws.addFormHeader("Advanced Settings")
    ws.addFormSubHeader("Log Settings")
    httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
    ws.TXBuffer = ""
    ws.addFormLogLevelSelect("Console log Level", "consoleloglevel",
                             settings.AdvSettings["consoleloglevel"])
    ws.addFormLogLevelSelect("Web log Level", "webloglevel",
                             settings.AdvSettings["webloglevel"])
    ws.addFormSubHeader("Time Settings")
    ws.addFormCheckBox("Enable NTP", "usentp", settings.AdvSettings["usentp"])
    ws.addFormTextBox("NTP server name", "ntpserver",
                      settings.AdvSettings["ntpserver"], 100)
    ws.addFormNumericBox("Timezone offset", "timezone",
                         settings.AdvSettings["timezone"], -720, 840)
    ws.addUnit("min")
    try:
        extrtc = settings.AdvSettings["extrtc"]
    except:
        settings.AdvSettings["extrtc"] = 0
        extrtc = 0
    options = ["Disable", "DS1307", "DS3231", "PCF8523"]
    optionvalues = [0, 1307, 3231, 8523]
    ws.addFormSelector("External RTC type", "extrtc", len(optionvalues),
                       options, optionvalues, None, extrtc)
    try:
        import inc.libhw as libhw
        options = libhw.geti2clist()
    except:
        options = []
    try:
        rtci2c = settings.AdvSettings["rtci2c"]
    except:
        rtci2c = 0
        settings.AdvSettings["rtci2c"] = 0
    ws.addHtml("<tr><td>RTC I2C line:<td>")
    ws.addSelector_Head("rtci2c", True)
    for d in range(len(options)):
        ws.addSelector_Item("I2C" + str(options[d]), options[d],
                            (rtci2c == options[d]), False)
    ws.addSelector_Foot()
    try:
        rtcaddr = settings.AdvSettings["rtcaddr"]
    except:
        rtcaddr = 0
        settings.AdvSettings["rtcaddr"] = 0
    options = ["0", "0x68", "0x51"]
    optionvalues = [0, 0x68, 0x51]
    ws.addFormSelector("RTC I2C address", "rtcaddr", len(optionvalues),
                       options, optionvalues, None, rtcaddr)
    res = ""
    try:
        if settings.AdvSettings['extrtc'] > 0 and settings.AdvSettings[
                'rtci2c'] >= 0:
            import inc.mrtc as mrtc
            try:
                import inc.libhw as libhw
            except:
                pass
            if mrtc.I2C_RTC is None:
                if settings.AdvSettings['rtci2c'] == 0:
                    rtcok = mrtc.rtcinit(settings.AdvSettings['extrtc'],
                                         libhw.i2c0,
                                         settings.AdvSettings["rtcaddr"])
                elif settings.AdvSettings['rtci2c'] == 1:
                    rtcok = mrtc.rtcinit(settings.AdvSettings['extrtc'],
                                         libhw.i2c1,
                                         settings.AdvSettings["rtcaddr"])
            ret = mrtc.getrtctime()
            res = '{:04}-{:02}-{:02} {:02}:{:02}:{:02}'.format(
                ret[0], ret[1], ret[2], ret[4], ret[5], ret[6])
    except Exception as e:
        res = "RTC not available " + str(e)
    if settings.AdvSettings['extrtc'] > 0:
        ws.addFormNote(res)
    ws.addFormSubHeader("Misc Settings")
    try:
        dpins = settings.AdvSettings["dangerouspins"]
    except:
        dpins = False
    ws.addFormCheckBox("Show dangerous pins", "dangerouspins", dpins)

    try:
        sp = settings.AdvSettings["startpage"]
    except:
        sp = "/"
    ws.addFormTextBox("Start page", "startpage", sp, 64)

    ws.addFormSubHeader("Location Settings")
    try:
        lat = settings.AdvSettings["Latitude"]
        lon = settings.AdvSettings["Longitude"]
    except:
        lat = 0
        lon = 0
    ws.addFormFloatNumberBox("Latitude", "latitude", lat, -90.0, 90.0)
    ws.addUnit("&deg;")
    ws.addFormFloatNumberBox("Longitude", "longitude", lon, -180.0, 180.0)
    ws.addUnit("&deg;")

    ws.addFormSeparator(2)
    ws.TXBuffer += "<TR><TD style='width:150px;' align='left'><TD>"
    ws.addSubmitButton()
    ws.TXBuffer += "<input type='hidden' name='edit' value='1'>"
    ws.TXBuffer += "</table></form>"

    ws.sendHeadandTail("TmplStd", ws._TAIL)
    httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
    ws.TXBuffer = ""
예제 #7
0
def handle_notif(httpResponse,responsearr):
 edit = ws.arg("edit",responsearr)

 nindex = ws.arg("index",responsearr)
 nNotSet = (nindex == 0) or (nindex == '')
 if nindex!="":
  nindex = int(nindex) - 1
 enabled = (ws.arg("nenabled",responsearr)=="on")
 protocol = ws.arg("protocol",responsearr)
 if protocol!="":
  protocol=int(protocol)
 else:
  protocol=0

 if ((protocol == 0) and (edit=='') and (nindex!='')) or (ws.arg('del',responsearr) != ''):
   try:
    settings.Notifiers[nindex].plugin_exit()
   except:
    pass
   settings.Notifiers[nindex] = False
   nNotSet = True
   settings.savenotifiers()

 if (nNotSet==False): # submitted
  if (protocol > 0): # submitted
   try:
    if (settings.Notifiers[nindex]):
     settings.Notifiers[nindex].enabled = enabled
     settings.Notifiers[nindex].webform_save(responsearr)
     settings.savenotifiers()
   except:
    pass
  else:
   try:
    if (settings.Notifiers[nindex]):
     protocol = settings.Notifiers[nindex].number
   except:
    pass

 ws.TXBuffer = ""
 httpResponse.WriteResponseOk(
        headers = ({'Cache-Control': 'no-cache'}),
        contentType = 'text/html',
        contentCharset = 'UTF-8',
        content = "" )
 ws.navMenuIndex=6
 ws.sendHeadandTail("TmplStd",ws._HEAD)

 ws.TXBuffer += "<form name='frmselect' method='post'>"
 if (nNotSet): # show all in table
    ws.TXBuffer += "<table class='multirow' border=1px frame='box' rules='all'><TR><TH style='width:70px;'><TH style='width:50px;'>Nr<TH style='width:100px;'>Enabled<TH>Service<TH>ID"
    for x in range(pglobals.NOTIFICATION_MAX):
      ws.TXBuffer += "<tr><td><a class='button link' href=\"notifications?index={0}&edit=1\">Edit</a><td>{0}</td><td>".format(x+1)
      try:
       if (settings.Notifiers[x]):
        ws.addEnabled(settings.Notifiers[x].enabled)
        ws.TXBuffer += "</td><td>{0}</td><td>{1}".format(settings.Notifiers[x].getdevicename(),settings.Notifiers[x].getuniquename())
       else:
        ws.TXBuffer += "<td><td>"
      except:
       ws.TXBuffer += "<td><td>"
    ws.TXBuffer += "</table></form>"
 else: # edit
    ws.TXBuffer += "<table class='normal'><TR><TH style='width:150px;' align='left'>Notification Settings<TH><tr><td>Notification:<td>"
    ws.addSelector_Head("protocol", True)
    for x in range(len(pglobals.notifierselector)):
      ws.addSelector_Item(pglobals.notifierselector[x][2],int(pglobals.notifierselector[x][1]),(str(protocol) == str(pglobals.notifierselector[x][1])),False,"")
    ws.addSelector_Foot()
    if (int(protocol) > 0):
      createnewn = True
      try:
       if (settings.Notifiers[nindex].getnpluginid()==int(protocol)):
        createnewn = False
      except:
       pass
      exceptstr = ""
      if createnewn:
       for y in range(len(pglobals.notifierselector)):
        if int(pglobals.notifierselector[y][1]) == int(protocol):
         if len(settings.Notifiers)<=nindex:
          while len(settings.Notifiers)<=nindex:
           settings.Notifiers.append(False)
         try:
           m = __import__(pglobals.notifierselector[y][0])
         except Exception as e:
          settings.Notifiers[nindex] = False
          exceptstr += str(e)
          m = False
         if m:
          try:
           settings.Notifiers[nindex] = m.Plugin(nindex)
          except Exception as e:
           settings.Notifiers.append(m.Plugin(nindex))
           exceptstr += str(e)
         break
      if settings.Notifiers[nindex] == False:
       ws.TXBuffer += "Importing failed: {0}</td></tr></table>".format(exceptstr)
       ws.sendHeadandTail("TmplStd",ws._TAIL)
       httpResponse._write(ws.TXBuffer,strEncoding='UTF-8')
       ws.TXBuffer = ""
       return
      else:
       try:
        settings.Notifiers[nindex].plugin_init() # call plugin init
       except:
        pass
    if nindex != '':
     ws.TXBuffer += "<input type='hidden' name='index' value='{0}'>".format(nindex+1)
     if int(protocol)>0:
      ws.addFormCheckBox("Enabled", "nenabled", settings.Notifiers[nindex].enabled)
      settings.Notifiers[nindex].webform_load()
      if (ws.arg('test',responsearr) != ''):
       settings.Notifiers[nindex].notify("Test message")
    ws.addFormSeparator(2)
    ws.TXBuffer += "<tr><td><td><a class='button link' href=\"notifications\">Close</a>"
    ws.addSubmitButton()
    if nindex != '':
     ws.addSubmitButton("Delete", "del")
     ws.addSubmitButton("Test", "test")
    ws.TXBuffer += "</table></form>"

 ws.sendHeadandTail("TmplStd",ws._TAIL)
 httpResponse._write(ws.TXBuffer,strEncoding='UTF-8')
 ws.TXBuffer = ""
예제 #8
0
    def webform_load(self):
        ws.addFormNote("IP and Port parameter is not used!")
        ws.addFormNote("SX127x hardware supported by uPyLoRa library")
        ws.addHtml(
            "<p>Example sender sketches could be find <a href='https://github.com/enesbcs/EasyLora'>here</a>."
        )
        ws.addTableSeparator("Hardware settings", 2, 3)
        try:
            options = libhw.getspilist()
        except:
            options = []
        ws.addHtml("<tr><td>SPI line:<td>")
        ws.addSelector_Head("spi", True)
        for d in range(len(options)):
            ws.addSelector_Item("SPI" + str(options[d]), options[d],
                                (self.spi == options[d]), False)
        ws.addSelector_Foot()
        ws.addFormPinSelect("DIO0 (IRQ) pin", "dio_0", self.dio_0, 0)
        ws.addFormPinSelect("SS pin", "ss", self.ss, 1)
        ws.addFormPinSelect("RST pin", "rst", self.rst, 1)
        ws.addFormNote("Optional")
        ws.addFormPinSelect("LED pin", "led", self.led, 1)
        ws.addFormNote("Optional")
        try:
            ws.addTableSeparator("LoRa settings", 2, 3)
            ws.addFormFloatNumberBox("Frequency", "freq", self.freq, 433, 928)
            ws.addUnit("Mhz")
            if self._lora is not None:
                try:
                    afreq = (self._lora._frequency) / 1000000
                except:
                    afreq = "UNINITIALIZED"
                ws.addFormNote("Current frequency: " + str(afreq) + " Mhz")
            ws.addFormNote(
                "Please check local regulations for your selected frequency!")

            options = ["10%", "1%", "0.1%"]
            optionvalues = [10, 100, 1000]
            ws.addFormSelector("Duty cycle", "duty", len(optionvalues),
                               options, optionvalues, None, self.duty)
            ws.addFormNote(
                "Please check your local Duty cycle regulations for your selected frequency!"
            )

            ws.addFormNumericBox("Spreading factor", "spreading", self.sf, 6,
                                 12)
            options = [
                "7.8", "10.4", "15.6", "20.8", "31.25", "41.7", "62.5", "125",
                "250"
            ]
            optionvalues = [
                7.8E3, 10.4E3, 15.6E3, 20.8E3, 31.25E3, 41.7E3, 62.5E3, 125E3,
                250E3
            ]
            ws.addFormSelector("Bandwidth", "bw", len(optionvalues), options,
                               optionvalues, None, self.bw)
            ws.addUnit("khz")

            options = ["CR4/5", "CR4/6", "CR4/7", "CR4/8"]
            optionvalues = [5, 6, 7, 8]
            ws.addFormSelector("Coding rate", "coding", len(optionvalues),
                               options, optionvalues, None, self.coding)

            ws.addFormNumericBox("Sync Word", "sync", self.sync, 0, 255)
            ws.addHtml('( 0x{:02x} )'.format(self.sync))

            ws.addFormNote(
                "Default 0x12, LoRaWAN is 0x34. Nodes can only communicate each other if uses same sync word!"
            )

            ws.addFormCheckBox("Enable Sending", "sender", self.enablesend)
            ws.addFormNumericBox("Default destination node index",
                                 "defaultnode", self.defaultunit, 0, 255)
            ws.addFormNote("Default node index for data sending")
        except Exception as e:
            misc.addLog(pglobals.LOG_LEVEL_ERROR, str(e))
        return True
예제 #9
0
    def webform_load(self):  # create html page for settings
        gc.collect()
        ws.addFormNote("Enable <a href='hardware'>SPI bus</a> first!")
        ws.addFormPinSelect("CS", "p302_cs", self.cs, 1)
        ws.addFormPinSelect("DC", "p302_dc", self.dc, 1)
        ws.addFormPinSelect("RST", "p302_rst", self.rst, 1)
        ws.addFormNote("Optional")
        try:
            ws.addHtml("<tr><td>Variant:<td>")
            options = ['Red/M5StickC', 'Blue', 'Blue2', 'Green']
            optionvalues = ['r', 'b', 'b2', 'g']
            ws.addSelector_Head("p302_disptype", False)
            for d in range(len(options)):
                ws.addSelector_Item(options[d], optionvalues[d],
                                    (self.disptype == optionvalues[d]), False)
            ws.addSelector_Foot()
        except:
            pass
        gc.collect()
        ws.addFormNumericBox("Width", "p302_width", self.width, 1, 320)
        ws.addFormNumericBox("Height", "p302_height", self.height, 1, 320)

        ws.addFormNumericBox("X offset", "p302_xoffset", self.xoffset, 0, 100)
        ws.addFormNumericBox("Y offset", "p302_yoffset", self.yoffset, 0, 100)
        options = ["RGB", "BGR"]
        optionvalues = [1, 0]
        ws.addFormSelector("Color mode", "p302_rgb", len(optionvalues),
                           options, optionvalues, None, self.rgb)

        options = ["0", "90", "180", "270"]
        optionvalues = [0, 90, 180, 270]
        ws.addFormSelector("Rotation", "p302_rotate", len(optionvalues),
                           options, optionvalues, None, self.rotate)
        ws.addUnit("deg")
        try:
            choice5 = int(float(
                self.taskdevicepluginconfig[4]))  # store line count
            ws.addHtml("<tr><td>Number of lines:<td>")
            ws.addSelector_Head("p302_linecount", False)
            for l in range(1, self.P302_Nlines + 1):
                ws.addSelector_Item(str(l), l, (l == choice5), False)
            ws.addSelector_Foot()
        except:
            pass
        ws.addFormNumericBox("Try to display # characters per row",
                             "p302_charperl", self.taskdevicepluginconfig[5],
                             1, 32)
        ws.addFormNote("Leave it '1' if you do not care")
        ws.addFormCheckBox("Clear only used lines", "p302_partialclear",
                           self.taskdevicepluginconfig[6])
        if choice5 > 0 and choice5 < 9:
            lc = choice5
        else:
            lc = self.P302_Nlines
        for l in range(lc):
            try:
                linestr = self.lines[l]
            except:
                linestr = ""
            ws.addFormTextBox("Line" + str(l + 1), "p302_template" + str(l),
                              linestr, 128)
        return True