2025年2月26日 星期三

requireJs 中使用 Vue3 框架


 參考 requireJs中使用Vue3及Vue3框架(viewUIPlus、elementPlus)

目录结构


HTML页面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>hello</title>
    <script src="js/lib/require.js" data-main="js/script/main"></script>
</head>
<body>

main 配置文件

require.config({
    // 加載 js 的目錄,paths 中以此目錄為標準讀取
    baseUrl: 'js',

    // 類庫别名和路徑配置
    paths: {
        jquery: 'lib/jquery-3.7.1',
        // vue 别名必须為 vue,由於其他框架或模块寻找 vue 时查询的是 vue 的别名
        vue: 'lib/vue3/vue.global.prod',
        // viewUIPlus框架
        viewUIPlus: 'lib/viewUiPlus/viewuiplus.min',
        // elementPlus 框架
        elementPlus: 'lib/elementPlus/index.full.min',
        // elementPlus 字体库
        elementPlusIconsVue: 'lib/elementPlus/icons-vue/dist/index.iife.min',
    },

    // 依赖以及导出设置,key值需对应paths中的别名,用于非AMD标准的类库进行导出
    shim: {
        // 由于vue3不是标准的AMD模块,需要手动抛出Vue变量,供其他框架使用
        'vue': {
            exports: 'Vue'
        },
        // viewUIPlus css
        'viewUIPlus': ['vue', 'css!lib/viewUiPlus/styles/viewuiplus.css'],
        // elementPlus 字体库依赖vue 没有这个配置,加载字体库时可能因为vue还未加载而报错
        'elementPlusIconsVue': {
            // 依赖
            deps: ['vue'],
            // 导出变量
            exports: 'ElementPlusIconsVue',
        },
        // elementPlus css 字體庫
        'elementPlus': ['vue', 'css!lib/elementPlus/index.css', 'elementPlusIconsVue',],
    },

    // 插件以及其他模塊配置
    map: {
        '*': {
            // 加載 css 插件
            'css': 'lib/require-css'
        },
    },
});

// 單獨使用 vue
require(['vue'], function (Vue) {
    const {createApp} = Vue
    const app = createApp({
        data() {
            return {
                message: 'Hello Vue!',
            }
        },
        methods: {}
    })
    app.mount("#app");
})

// viewUIPlus vue依赖已在shim中配置,无需再次引入
require(['viewUIPlus'], function (ViewUIPlus) {
    const {createApp} = Vue
    const app = createApp({
        data() {
            return {
                message: 'Hello viewUiPlus!',
            }
        },
        methods: {}
    })
    app.use(ViewUIPlus);
    app.mount("#viewUi");
})

// elementPlus 字体库和vue依赖已在shim中配置,无需再次引入
require(['elementPlus'], function (ElementPlus) {
    const {createApp} = Vue
    const app = createApp({
        data() {
            return {
                message: 'Hello elementPlus'
            }
        },
        methods: {}
    })
    // 字体库组件
    for ([name, comp] of Object.entries(ElementPlusIconsVue)) {
        app.component(name, comp);
    }
    app.use(ElementPlus);
    app.mount("#ele");
})

效果

Vue2 及 Vue3 同時存在

require.config({
  baseUrl: ntuweb.baseUrl+'/assets',
  paths: {
    "jquery": "jquery-1.12.4.min",
    "jqueryform": "jquery.form.4.2.2.min",
    "jqueryui": "jquery-ui/jquery-ui-1.10.4.custom.min",
    "vue": "vue_2.6.14",  
    'vue3': "vue.global-3.5.12.min",
    "showModalDialog": "showModalDialog",
    'corejs': 'corejs-2.6.12_shim.min'
    , 'swal': 'sweetalert2-10.min'
  },
  // 以下為非 AMD 程式,有固定的載入順序
  shim : {
    // 由於 vue3 不是準的 AMD 模塊,需要手動拋出 Vue 變量,用於非AMD標準類庫進行導出
    'vue3': {
      exports: 'Vue'
    },
    "jqueryui": ["jquery"],
    "jqueryform": ["jquery"]
    , 'swal': ['corejs']
    , "showModalDialog": ["jqueryui"]
    , 'wbSingle': ['swal']
  }
});

使用 Vue2

require(['jquery', 'vue', 'showModalDialog', 'jqueryform'], function($, Vue)
{
    vm = new Vue({
        el: '#main-div',
        data: {
            dat: <?= json_encode($gdat) ?>,
            frm_label: '',
            LbState: 0, 
        },
        computed: {
            .....
        },
        methods: {
            .....
        }
    });
});

使用 Vue3

rrequire(['jquery', 'vue3', 'showModalDialog', 'jqueryform'], function($, Vue)
{
    const { createApp, ref ,reactive, computed} = Vue;

    vm = createApp({
        setup() {
            const dat = reactive({
                cou_code: ref(''),
                cou_cname: ref(''),
                credit: ref(0),
		..........
            });

            const frm_label = ref('');
            const LbState = ref(0); 

            return {
                dat, frm_label, LbState,
            }
        },
        computed: {
            ..........
        },
        methods: {
            ...........
        }
    }).mount('#main-div');
});

更新物件 dat 的屬性的值

Object.keys(vm.dat).forEach(function (kk) {
    vm.dat[kk] = ret[kk];
});











2025年2月21日 星期五

LCD debug

9341 正常的訊息 

-----------
[    1.664021] ili9341@0 enforce active low on GPIO handle
[    6.580043] fb_ili9341: module is from the staging directory, the quality is 
unknown, you have been warned.
[    6.580648] fb_ili9341 spi0.0: fbtft_property_value: width = 240
[    6.580674] fb_ili9341 spi0.0: fbtft_property_value: height = 320
[    6.580685] fb_ili9341 spi0.0: fbtft_property_value: buswidth = 8
[    6.580697] fb_ili9341 spi0.0: fbtft_property_value: debug = 4
[    6.580706] fb_ili9341 spi0.0: fbtft_property_value: rotate = 90
[    6.580716] fb_ili9341 spi0.0: fbtft_property_value: fps = 30
[    6.580973] fb_ili9341 spi0.0: fbtft_request_one_gpio: 'reset' GPIO
[    6.581032] fb_ili9341 spi0.0: fbtft_request_one_gpio: 'dc' GPIO
[    6.581067] fb_ili9341 spi0.0: fbtft_request_one_gpio: 'rd' GPIO
 ........... 一直重複 -----------
[    6.581590] fb_ili9341 spi0.0: fbtft_request_one_gpio: 'db' GPIO
...
[    6.887247] fb_ili9341 spi0.0: Display update: 3837 kB/s, fps=0
[    6.888155] Console: switching to colour frame buffer device 40x30
[    6.888772] graphics fb0: fb_ili9341 frame buffer, 320x240, 150 KiB video memory, 16 KiB buffer memory, fps=31, spi0.0 at 40 MHz
[    6.999727] systemd[1]: Starting systemd-backlight@backlight:fb_ili9341.service - Load/Save Screen Backlight Brightness of backlight:fb_ili9341...
[    7.003913] systemd[1]: Finished systemd-binfmt.service - Set Up Additional Binary Formats.
[    7.023356] usb 2-1: Firmware revision 11.1 (signature 0x88e1)
[    7.080231] systemd[1]: Finished systemd-backlight@backlight:fb_ili9341.service - Load/Save Screen Backlight Brightness of backlight:fb_ili9341.

--------------

使用 lsmod 

-------------
Module                  Size  Used by
fb_ili9341             12288  1
fbtft                  36864  1 fb_ili9341
-------------


https://mjmwired.net/kernel/Documentation/devicetree/bindings/display/ilitek,ili9486.yaml

參考 Using GPIO from a Linux Shell

--------------
$ dmesg | grep -i ads
[    7.067079] ads7846 spi0.1: supply vcc not found, using dummy regulator
[    7.072789] ads7846 spi0.1: touchscreen, irq 47
[    7.073534] input: ADS7846 Touchscreen as /devices/platform/soc/1c68000.spi/spi_master/spi0/spi0.1/input/input1

$ cat /proc/interrupts | grep ads
 47:         22          0          0          0  sunxi_pio_edge   6 Edge      ads7846

$ sudo gpiodetect
gpiochip0 [1c20800.pinctrl] (224 lines)
gpiochip1 [1f02c00.pinctrl] (32 lines)

$ sudo gpioinfo
gpiochip0 - 224 lines:
line   0:      unnamed       unused   input  active-high 
.....
line   5:      unnamed       unused   input  active-high 
line   6:      unnamed    "pendown"   input   active-low [used]
line   7:      unnamed        "led"  output  active-high [used]
line   8:      unnamed         "dc"  output  active-high [used]
line   9:      unnamed      "reset"  output   active-low [used]
line  10:      unnamed   "spi0 CS0"  output   active-low [used]
line  11:      unnamed       unused   input  active-high 
line  12:      unnamed       unused   input  active-high 
line  13:      unnamed       unused   input  active-high 
line  14:      unnamed       unused   input  active-high 
line  15:      unnamed "orangepi:red:status" output active-high [used]
line  16:      unnamed       unused   input  active-high 
.....
line  20:      unnamed   "spi0 CS1"  output  active-high [used]
.....
line 165:      unnamed       unused   input  active-high 
line 166:      unnamed         "cd"   input   active-low [used]
        ..... 
line 204:      unnamed "usb0_id_det" input active-high [used]
line 205:      unnamed       unused   input  active-high 

--------------

https://www.kernel.org/doc/Documentation/devicetree/bindings/input/touchscreen/ads7846.txt

https://github.com/raspberrypi/linux/pull/6029 (Mar 13, 2024)

The driver has been converted to use gpiod, which will normalise polarity based on DT.

The piscreen overlay (and others) incorrectly defines the pendown GPIO as being ACTIVE_HIGH (0), althought triggering on the high-low edge for pen down. It therefore tries reading the pen position when not being touched, and stops when it is touched.

Tested with piscreen and ads7846 overlays. Also fixed on others where the interrupt says high->low but the polarity was ACTIVE_HIGH.


ADS7846 Touch controller does not work anymore after upgrade to the latest kernel 6.6.20 on 64-bit Raspberry Pi OS Bookworm. It works well with the older kernel 6.1.0.

https://github.com/raspberrypi/linux/blob/rpi-6.6.y/arch/arm/boot/dts/overlays/ads7846-overlay.dts

-----------
pendown-gpio = <&pio 0 19 0>;
line  19:      unnamed    "pendown"   input  active-high [used]

pendown-gpio = <&pio 0 19 1>;
line  19:      unnamed    "pendown"   input   active-low [used]
---------------






2025年2月16日 星期日

在 Klipper 中使用 Fly 3D 的 D5

以前買來就直接使用。最近,怎麼都連不上。比較裝置的代碼,才發現不同

 /dev/serial/by-id/usb-katapult_stm32f072xb_MELLOW-if00

燒了 Klipper 的 firmware,應是

/dev/serial/by-id/usb-Klipper_stm32f072xb_3C0029000557465036383420-if00

原來,在2024年9月1号之后出厂的D5已经刷好Katapult固件。 

照著它的文件,就可以重新設定和 build 映像檔了。

https://mellow.klipper.cn/docs/ProductDoc/MainBoard/fly-d/fly-d5/flash/usb

燒入的指令

~/katapult/scripts$ python3 flashtool.py -d  /dev/serial/by-id/usb-katapult_stm32f072xb_MELLOW-if00

喇叭要關掉,要設 default 值。


網誌存檔