Bläddra i källkod

fix:lcd demo tp添加防护判断

Dozingfiretruck 1 år sedan
förälder
incheckning
2f680a55b7
1 ändrade filer med 21 tillägg och 20 borttagningar
  1. 21 20
      demo/lcd/main.lua

+ 21 - 20
demo/lcd/main.lua

@@ -134,9 +134,8 @@ sys.taskInit(function()
     -- 开启缓冲区, 刷屏速度回加快, 但也消耗2倍屏幕分辨率的内存
     if lcd_use_buff then
         lcd.setupBuff(nil, true) -- 使用sys内存, 只需要选一种
+        -- lcd.setupBuff()       -- 使用lua内存, 只需要选一种
         lcd.autoFlush(false)
-    else
-        lcd.setupBuff()          -- 使用lua内存
     end
 
     while 1 do 
@@ -161,26 +160,28 @@ sys.taskInit(function()
     end
 end)
 
-local function tp_callBack(tp_device,tp_data)
-    sys.publish("TP",tp_device,tp_data)
-end
-
-tp_device = tp.init("gt911",{port=0,pin_rst = 22,pin_int = 23,w = 320,h = 480},tp_callBack)
--- softI2C = i2c.createSoft(20, 21)
--- tp_device =  tp.init("gt911",{port=softI2C,pin_rst = 22,pin_int = 23,w = 320,h = 480},tp_callBack)
-if tp_device then
-    print(tp_device)
-    sys.taskInit(function()
-        while 1 do 
-            local result, tp_device, tp_data = sys.waitUntil("TP")
-            if result then
-                lcd.drawPoint(tp_data[1].x, tp_data[1].y, 0xF800)
-                if lcd_use_buff then
-                    lcd.flush()
+if tp then
+    local function tp_callBack(tp_device,tp_data)
+        sys.publish("TP",tp_device,tp_data)
+    end
+    
+    tp_device = tp.init("gt911",{port=0,pin_rst = 22,pin_int = 23,w = 320,h = 480},tp_callBack)
+    -- softI2C = i2c.createSoft(20, 21)
+    -- tp_device =  tp.init("gt911",{port=softI2C,pin_rst = 22,pin_int = 23,w = 320,h = 480},tp_callBack)
+    if tp_device then
+        print(tp_device)
+        sys.taskInit(function()
+            while 1 do 
+                local result, tp_device, tp_data = sys.waitUntil("TP")
+                if result then
+                    lcd.drawPoint(tp_data[1].x, tp_data[1].y, 0xF800)
+                    if lcd_use_buff then
+                        lcd.flush()
+                    end
                 end
             end
-        end
-    end)
+        end)
+    end
 end