2019年7月18日 星期四

Bluepy Scanner disconnects exist connections

解決 blueby 每次 scan 就會中斷先前連線的問題

困擾了很久
試過各種寫法 thread / lock / wait / pause / sleep 都無效

結果很簡單,只要 scan 時增加 passive=True 就好了

            scanner = Scanner().withDelegate(ScanDelegate())
            devices = scanner.scan(1.0, passive=True)

2019年7月16日 星期二

Raspberry pi 同時使用 藍牙及 UART

sudo raspi-config
Interface > Serial > No

sudo nano /boot/config.txt
新增底下三行
core_freq=250
dtoverlay=pi3-miniuart-bt
enable_uart=1

注意此時 uart 是使用系統時脈產生 baud rate,不能太快

2019年7月15日 星期一

RPI Hash-sum mismatch on apt-get

apt-get update 出現問題

嚐試使用低下方式解決…

sudo rm /var/lib/apt/lists/* -vf

sudo apt-get update

2019年7月9日 星期二

NXP S9KEAZN64 Disable NMI


陷阱題:

KE 系列 MCU,PTB4 腳在 reset 後預設會使用 NMI 功能
導致無法當一般 GPIO 使用
因此要 Disable 掉
不然會 d 到天荒地老

在 system_SKEAZN642.c 中 void SystemInit (void) 函式 增加一行…
SIM->SOPT &= ~SIM_SOPT_NMIE_MASK;                //禁用NMI

2019年7月8日 星期一

Keil C axf 轉 elf

Keil C options-->user-->after build
使用 fromelf 轉換格式…
fromelf --elf --output=$L@L.elf #L


2019年4月10日 星期三

Flutter/Dart神奇的語法

習慣傳統程式語言,這種的初看像謎之符號,細看覺得神奇!!
Future <bool> ShowYesNoDialog(
BuildContext context,
doYes,
doNo
) async
{
return showDialog(
context: context,
builder: (context) => AlertDialog(
actions: <Widget>[
RaisedButton(
onPressed: ((){doYes();}),
),
RaisedButton(
onPressed: ((){doNo();}),
),
],
),
) ??
false;
}

await ShowYesNoDialog(
context, 'SayYesNo', 'Yes or No?',
((){print('yes');}),
((){print('no')}),
);

2019年3月29日 星期五

python 處理 word 表格

# coding=utf-8
import docx
import glob
import os
import csv

#設置檔案路徑
path = '範例檔'
#設置輸出檔名
output = 'output.csv'

#開啟輸出的 CSV 檔案
with open(output, 'w', newline='') as csvfile:
  #建立 CSV 檔寫入器
  writer = csv.writer(csvfile)
  #header
  writer.writerow(['檔名','學校','班級','學生','國語','數學','社會','自然','藝術'])
 
for filename in glob.glob(os.path.join(path, '*.docx')):    #遍歷所有檔案
    #doc = docx.Document("範例檔\su_sn_11122.docx")
    doc = docx.Document(filename)
    for table in doc.tables:    #遍歷所有表格
        print("--------")
        _school = ''
        _class = ''
        _student = ''
        _score1 = ''
        _score2 = ''
        _score3 = ''
        _score4 = ''
        _score5 = ''
        done = False
        i = 0
        for row in table.rows:  #遍歷表格的所有 row
            #row_str = "\t".join([cell.text for cell in row.cells])  # 一行數據
            #print(row_str)
            j = 0
            for cell in row.cells:  #遍歷 row 中所有 cell
                #print( cell.text + "\t" )
                #print( str(i)+":"+str(j)+":"+table.cell( i, j ).text + "\t" )
                if cell.text == '學校':
                    _school = table.cell( i, j+1 ).text #抓右邊的 cell
                if cell.text == '班級':
                    _class = table.cell( i, j+1 ).text #抓右邊的 cell
                if cell.text == '學生':
                    _student = table.cell( i, j+1 ).text #抓右邊的 cell
                if cell.text == '國語':
                    _score1 = table.cell( i+1, j ).text  #抓下面的 cell
                if cell.text == '數學':
                    _score2 = table.cell( i+1, j ).text  #抓下面的 cell
                if cell.text == '社會':
                    _score3 = table.cell( i+1, j ).text  #下面的 cell
                if cell.text == '自然':
                    _score4 = table.cell( i+1, j ).text  #抓下面的 cell
                if cell.text == '藝術':
                    _score5 = table.cell( i+1, j ).text  #抓下面的 cell
                    done = True #這是最後一筆資料
                j = j + 1   #指向下一 cell
                if done:
                    break   #完成
            i = i + 1   #指向下一 row
            if done:
                break   #完成
        print( _school )
        print( _class )
        print( _student )
        print( _score1 )
        print( _score2 )
        print( _score3 )
        print( _score4 )
        print( _score5 )
        with open('output.csv', 'a', newline='') as csvfile:
            #建立 CSV 檔寫入器
            writer = csv.writer(csvfile)
            #內容
            writer.writerow([filename,_school,_class,_student,_score1,_score2,_score3,_score4,_score5])
        break #限制1檔1表

VirtualBox 空間減肥

sdelete64 -z c: VBoxManage  modifymedium  disk  "/Users/fellow/VirtualBox VMs/Win10/Win10.vdi"  --compact *.vdi 路徑可以在 VirtualBox 儲...