Dozingfiretruck 3 лет назад
Родитель
Сommit
31704f5d42

+ 0 - 15
script/turnkey/EinkBook/.gitignore

@@ -1,15 +0,0 @@
-.vscode/*
-!.vscode/settings.json
-!.vscode/tasks.json
-!.vscode/launch.json
-!.vscode/extensions.json
-*.code-workspace
-
-# Local History for Visual Studio Code
-.history/
-
-*.exe
-
-*.soc
-
-.idea

+ 0 - 71
script/turnkey/EinkBook/Scripts/httpLib.lua

@@ -1,71 +0,0 @@
-local httpLib = {}
--- printTable(esphttp)
--- {
--- 	"init" = function: 42008586,
--- 	"post_field" = function: 42008A58,
--- 	"perform" = function: 42008BA0,
--- 	"status_code" = function: 42008A0E,
--- 	"content_length" = function: 42008C28,
--- 	"read_response" = function: 42008992,
--- 	"set_header" = function: 42008910,
--- 	"get_header" = function: 420088A0,
--- 	"cleanup" = function: 42008848,
--- 	"is_done" = function: 420087EE,
--- 	"go" = function: 42008B1E,
--- 	"GET" = 0,
--- 	"POST" = 1,
--- 	"PUT" = 2,
--- 	"PATCH" = 3,
--- 	"DELETE" = 4,
--- 	"EVENT_ON_FINISH" = 5,
--- 	"EVENT_ERROR" = 0,
--- 	"EVENT_DISCONNECTED" = 6,
--- 	"EVENT_ON_DATA" = 4,
--- }
-
-local methodTable = {
-    GET = esphttp.GET,
-    POST = esphttp.POST,
-    PUT = esphttp.PUT,
-    DELETE = esphttp.DELETE
-}
-
-function httpLib.request(method, url, head)
-    local responseCode = 0
-    local httpc = esphttp.init(methodTable[method], url)
-    if httpc == nil then
-        esphttp.cleanup(httpc)
-        return false, responseCode, "create httpClient error"
-    end
-    if head ~= nil then
-        for k, v in pairs(head) do
-            esphttp.set_header(httpc, k, v)
-        end
-    end
-    local ok, err = esphttp.perform(httpc, true)
-    if ok then
-        local response = ""
-        while 1 do
-            local result, c, ret, data = sys.waitUntil("ESPHTTP_EVT", 20000)
-            -- log.info("ESPHTTP_EVT", result, c, ret, data)
-            if result == false then
-                esphttp.cleanup(httpc)
-                return false, responseCode, "wait for http response timeout"
-            end
-            if c == httpc then
-                if esphttp.is_done(httpc, ret) then
-                    esphttp.cleanup(httpc)
-                    return true, esphttp.status_code(httpc), response
-                end
-                if ret == esphttp.EVENT_ON_DATA then
-                    response = response .. data
-                end
-            end
-        end
-    else
-        esphttp.cleanup(httpc)
-        return false, responseCode, "perform httpClient error " .. err
-    end
-end
-
-return httpLib

+ 9 - 7
script/turnkey/EinkBook/Scripts/main.lua

@@ -3,8 +3,8 @@ VERSION = "1.0.0"
 MOD_TYPE = rtos.bsp()
 log.info("MOD_TYPE", MOD_TYPE)
 sys = require("sys")
+require("sysplus")
 wifiLib = require("wifiLib")
-httpLib = require("httpLib")
 
 tag = "EINKBOOK"
 -- 是否启用配网功能(配合esptouch使用)
@@ -150,9 +150,9 @@ function showBook(bookName, bookUrl, page)
     sys.taskInit(function()
         waitHttpTask = true
         for i = 1, 3 do
-            local result, code, data = httpLib.request("GET", bookUrl .. "/" .. page)
-            log.info("SHOWBOOK", result, code)
-            if result == false or code == -1 or code == 0 then
+            local code, headers, data = http2.request("GET",bookUrl .. "/" .. page).wait()
+            log.info("SHOWBOOK", code)
+            if code ~= 200 then
                 log.error("SHOWBOOK", "获取图书内容失败 ", data)
             else
                 local bookLines = json.decode(data)
@@ -298,7 +298,8 @@ sys.taskInit(function()
     eink.show(0, 0)
     eink.clear(1, true)
     eink.show(0, 0)
-    eink.setFont(fonts.get("sarasa_regular_12"))
+    -- eink.setFont(fonts.get("sarasa_regular_12"))
+    eink.setFont(eink.font_opposansm12_chinese)
 
     if USE_SMARTCONFIG == true then
         einkShowStr(0, 16, "开机中 等待配网...", 0, false, true)
@@ -316,8 +317,9 @@ sys.taskInit(function()
         end
     end
     for i = 1, 5 do
-        local result, code, data = httpLib.request("GET", serverAdress .. "getBooks")
-        if result == false or code == -1 or code == 0 then
+        local code, headers, data = http2.request("GET", serverAdress .. "getBooks").wait()
+        log.info("SHOWBOOK", code)
+        if code ~= 200 then
             log.error(tag, "获取图书列表失败 ", data)
             if i == 5 then
                 einkShowStr(0, 16, "连接图书服务器失败 正在重启", 0, true, true)