12月 16

[转载]golang pprof

https://blog.wolfogre.com/posts/go-ppof-practice/

<code>_ "net/http/pprof" // 引入 pprof 模块
//  主函数内存分析
go func() {
	http.ListenAndServe("0.0.0.0:8090", nil)
}()</code>
<code>//命令行,收集cpu 如果生成svg 和图片安装 graphviz 
// top list 定位问题
go tool pprof http://localhost:8090/debug/pprof/profile
// 收集内存
go tool pprof http://localhost:8090/debug/pprof/heap
// 内存回收
go tool pprof http://localhost:8090/debug/pprof/allocs</code>
12月 02

esp32 +oled显示英文、中文

from machine import Pin, I2C
from oled import SSD1306_I2C
# 定义管脚
scl = Pin(22)
sda = Pin(21)
# 初始化
i2c = I2C(scl=scl, sda=sda)
# 像素 128*64
oled = SSD1306_I2C(128, 64, i2c)
# 清屏
oled.fill(0)
oled.show()

# 显示英文,从0,0像素开始
oled.text('hello', 0, 0)
oled.show()

# 以下为显示中文,重新显示需要清屏。fonts字体为自定义取模。
# 字索引为utf-8 16进制
# https://www.23bei.com/tool-217.html 在线取模
fonts= {
    # 你
    0xe4bda0:
[0x11,0x11,0x11,0x23,0x22,0x64,0xA8,0x20,0x21,0x21,0x22,0x24,0x20,0x20,0x21,0x20,
0x00,0x00,0x00,0xFC,0x04,0x08,0x40,0x40,0x50,0x48,0x4C,0x44,0x40,0x40,0x40,0x80],
    # 好
    0xe5a5bd:
[0x10,0x11,0x10,0x10,0xFC,0x24,0x24,0x27,0x24,0x44,0x28,0x10,0x28,0x44,0x84,0x00,
0x00,0xFC,0x04,0x08,0x10,0x20,0x24,0xFE,0x20,0x20,0x20,0x20,0x20,0x20,0xA0,0x40]
    }

def chinese(ch_str, x_axis, y_axis): 
   offset_ = 0 
   y_axis = y_axis*8  # 中文高  
   x_axis = (x_axis*16)  # 中文宽
   for k in ch_str:
       code = 0x00  # 中文转成16进制编码 
       data_code = k.encode("utf-8")
       code |= data_code[0] << 16 
       code |= data_code[1] << 8
       code |= data_code[2]
       byte_data = fonts[code]
       for y in range(0, 16):
           a_ = bin(byte_data[y]).replace('0b', '')
           while len(a_) < 8:
               a_ = '0'+a_
           b_ = bin(byte_data[y+16]).replace('0b', '')
           while len(b_) < 8:
               b_ = '0'+b_
           for x in range(0, 8):
               oled.pixel(x_axis+offset_+x, y+y_axis, int(a_[x]))   
               oled.pixel(x_axis+offset_+x+8, y+y_axis, int(b_[x]))   
       offset_ += 16
       
chinese('你好',0,0)
oled.show()
6月 29

python3 多CPU加速

#!env python3
# -*- coding:utf-8 -*-
# Author:      simonzhang.net
import time
from multiprocessing import Pool

def toPrint(n):
    print(n, int(time.time()))
    time.slee(0.5)

if __name__=='__main__':
    # 系统有20个CPU
    p = Pool(20)
    # 加载数据
    for i in range(60):
        p.apply_async(toPrint, args=(i,))
    # 加载完成开始执行
    p.close()
    p.join() 

11月 23

3D打印机启停代码Gcode

Gcode开始和结束代码。停机回抽材料,返回原点,蜂鸣提醒。

开始

M104 S{print_temperature}
M140 S{print_bed_temperature}
M143 S270 ;喷头超出270度shutdown
M105
M109 S{print_temperature} E1
M190 S{print_bed_temperature}
M105
G21 ;metric values
G90 ;absolute positioning
M82 ;set extruder to absolute mode
M107 ;start with the fan off
G28 X0 Y0 ;move X/Y to min endstops
G28 Z0 ;move Z to min endstops
G1 Z15.0 F{travel_speed} ;move the platform down 15mm
G92 E0 ;zero the extruded length
G1 F200 E3 ;extrude 3mm of feed stock
G92 E0 ;zero the extruded length again
G1 F{travel_speed}
;Put printing message on LCD screen
M117 Printing…

结束代码

G91
G1 Z+5.0 E-5 F200 ;Z上移5mm 回抽10mm
G90
G28 X0 Y0
M300 S100 P1000 ;end sound
M104 S0 ;extruder heater off
M140 S0 ;heated bed heater off (if you have it ;retract the filament a bit before lifting the nozzle, to release some of the pressure
M106 S0
M84 ;steppers off
G90 ;absolute positioning
;{profile_string}

6月 02

echarts 在图片上做标注

主要思路:1、先有背景图,2、有刻度,3、隐藏X、Y轴显示,4、隐藏直线显示,5、进行标注。使用echarts实现,代码如下

var img = new Image(); //新建对象
img.src="http://pic.sc.chinaz.com/files/pic/pic9/201708/zzpic6006.jpg";

option = {
    // 背景
    backgroundColor: {
        type: "pattern",
        repeat: "repeat",
        image: img,
    },
    title: {
        text:"XXXXX"
    },
    xAxis: {
        show : false,
        data: [1,2,3,4,5,6,7,8,9]
    },
    yAxis: {
        show : false,
    },
    series: [{
        type:"line",
        data: [1,2,3,4,5,6,7,8,9],
        //隐藏直线
        showSymbol: false,
        lineStyle: {
            width: 0,
            color: 'rgba(0, 0, 0, 0)'
        },
        // 标注气泡
        markPoint: {
                data: [
                    {name: 'y', value:"嘴", xAxis:3, yAxis: 1.5},
                    {name: 'z', value:"眼睛", xAxis: 1, yAxis: 6},
                ]
            },
        },
    ]
};

随便找了张图片,效果如下: