什么unicode字符最适合在字符串中绘制方波

时间:2017-01-19 17:15:30

标签: java raspberry-pi

我试图用一串存储的GPIO事件和时序来表示字符串中的方波脉冲序列。代码正在运行,但我需要更好的Unicode字符进行转换。

这是我目前的方法

    public String waveform()
    {
    String s = "";
    int pulses;
    int pulseWidth;

    pulseWidth = events.get(1).duration; //mostly right!
    for (RF433Event e: events)
    {
        pulses = e.duration/pulseWidth;
        if (e.gpioEvent.getEdge() == PinEdge.RISING)
        {
            // rising edge so for the duration it was low
            for (int i = 0; i<pulses; i++) s = s+'_';
            s = s+"\u02E9";
        } else
        {
            // falling edge so for the duration it was high
            for (int i = 0; i<pulses; i++) s = s+"\u0305";
            s = s+"\u02E5";
        }

    }
    return s;
    }

Intellij控制台窗口中的输出如下所示 enter image description here

但奇怪的是没有出现在RPi上,我是否需要在Pi上安装其他东西?

1 个答案:

答案 0 :(得分:2)

经过多次实验,这对我有用

public String waveform()
{
    String s = "";
    int pulses;
    int pulseWidth;
    // Characters tried for drawing the pulse train
    // Low line - "_", "\u0332" Combining Low Line, "\uFF3F"; FULLWIDTH LOW LINE
    // High line - "\u0305" COMBINING OVERLINE, "\u203E" over line 
    // Vertical -  "\u20D2" COMBINING LONG VERTICAL LINE OVERLAY, "\u007C" Vertical line, "\u02E9" MODIFIER LETTER EXTRA-LOW TONE BAR
    if (events.get(0).duration > 50000) {return "Excessive duration in pluse 0 "+events.get(0).duration;}
    pulseWidth = 100; //gives a reasonable pulse train
    for (RF433Event e: events)
    {
        pulses = e.duration/pulseWidth;
        if (e.gpioEvent.getEdge() == PinEdge.RISING)
        {
            // rising edge so for the duration it was low
            for (int i = 0; i<pulses; i++) s = s+ "_";
            s = s+"\u20D2";
        } else
        {
            // falling edge so for the duration it was high
            for (int i = 0; i<pulses; i++) s = s+"\u0305";
            s = s+"\u20D2";
        }
    }
    return s;
}

这些是结果 Pulse Trains