M♪o 之學習筆記本《巳》文章︰【䷊】包荒馮河

派生碼訊

巳 蛇

來氏《 易 》易註︰

九二,包荒,用馮河,不遐遺,朋亡,得尚于中行。

包荒者,包乎初也。初為草茅,荒穢之象也 。因本卦小往大來,陽來乎下,故包初。馮河者,二變則中爻成坎水矣,河之象也。河水在前,乾健利涉大川,馮之象也。用馮河者,用馮河之勇往也。二居柔位,故教之以勇。二變與五隔河,若馮河而往,則能就乎五矣。二與初為邇,隔三四,與五為遐。不遐遺者,不遺乎五也。朋者初也,三同陽體 ,牽連而進,二居其中,朋之象也,故咸卦中爻成乾,四居乾之中,亦曰朋從。朋亡者 ,亡乎初而事五也。尚者,尚往而事五也。中行,指六五,六五小《象》曰中以行願是也。卦以上下交為泰,故以尚中行為辭。曰得尚者,慶幸之辭也。若惟知包乎荒,則必不能馮河而就五矣,必遐遺乎五矣,必不能亡朋矣。用馮河以下,聖人教占者之辭。陽來居內,不向乎外,有惟知包乎內卦之初,遐遺乎外卦君上之象,故聖人于初教之以征 ,于二教之以尚。舊註不識象,所以失此爻之旨。

當泰之時,陽來于下,不知有上,故九二有包初之象,然二五君臣同德,天下太平,賢人君子,正當觀國用賓之時,故聖人教占者用馮河之勇,以奮其必為之志,不可因邇而忘遠。若能忘其所邇之朋,得尚往于中行之君,以共濟其泰,則上下交而其志同,可以收光大之事業,而泰道成矣。故其象占如此 。

《象》曰:包荒,得尚于中行,以光大也。

曰包荒兼下三句而言也。孔子小象多是如此 ,捨相比溺愛之朋,而尚往以事中德之君 ,豈不光明正大。乾陽大之象也,變離光之象也。

︰地氣居上而性趨下;天氣處下而情往上 。天地氤氳,萬物化醇。不泰又待何時?

今兒學堂氣氛有些低迷,同學們意興闌珊,有點悶悶不樂。想來是因為昨天有些議題,不能定奪結論,某些改寫嘗試,失敗告終。這因『辨』而『辯』與由『辯』能『辨』,應該如何決定分際?

《 文 》文說︰

辨,判也。从刀辡聲。

辯,治也。从言在辡之閒。

,彷彿說了似沒說!

沒多時學長來了。

 

派︰同學們,大家好。昨兒因故請假,晚上讀了 M♪o 的課堂摘記,看到大家合力完成的 TuxIOme 程式深感驚豔。別說當年我們學習時沒有這樣的創舉,就算當初在小學堂課綱之訂定時,也未曾設想過,真可以小學堂裡講程式文法的哩!所以今兒自備禮物 ── 環境溫度感測器 ──,給你們嘉獎,替同學們加油。同時特傳能看影音的 Kodi 安裝 秘 技 秘技,為大家助興。【熱烈鼓掌】

雖然說『包荒馮河』在於『勇』,更在『朋不遐遺』。 議 論 議論之旨,重在得 理 理。同或不同,以 辨辯 ,貴能 和 同異,方謂得 宜 宜。

程式語言的文法,道理博大精深,大家既已敲門叩關,更應當細思幕後法則,往往牽一髮而動全身。於此略對入出針文法,作個 平 平說︰

【函元之不妥】

通常研習程式文法實務,精通了算術表達式,大概思過半矣。這事早由 λ 運算所揭示,所以知道『函式求值』與『變元代換』的概念看來似乎簡單,其中的精巧細密,除非深入探究,並不容易掌握。如果考察派生語法,它並沒有『抽象函數』運算︰

(f + g) (x) = f (x) + g (x)

(f - g) (x) = f (x) - g (x)

(f * g) (x) = f (x) * g (x)

(f / g) (x) = f (x) / g (x)

(f \circ g) (x) = f (g (x) )

,這是因為首先『 def 』關鍵字所定義的『函式』,可以不是數學上講的『函數』,而是執行某種『功能』 function 。 再者從語用上說,針對特定領域應用,設計特殊語法,並不是普通程式語言應該專注的目標,多半經由『程式庫』來作擴充。比方講 NumPy 方便了科學運算, SymPy 開啟符號代數系統。它們並不直接擴張 Python 的基本語法。因此對於入出針文法,也需要思考它的『目的性』。由於 TPG 只是普通派生定義的『 class 』類,所謂文法的『內』與『外』就有很多彈性,可以在應用上作適度規劃。由此觀之,函元 ,或該叫做函式,之擴張並非『必要的』,因此認為不妥。

 

【文法之整合】

假使將 TuxIOme 的系統溫度文法,如此修改

# 原先
            |   "系統溫度"                        e = 讀取系統溫度()         ; # 改作             |   "系統溫度" self["CPU溫度"] = e = 讀取系統溫度()
        ;

,原先的用法依舊,『變元』裡將增加一項『 CPU溫度』,於是就可以用『顯示』文法,將系統溫度顯示在數碼管上。現今又多了『環境溫度』的感測器,可以思考如何『相容』『整合』的作文法擴充 。

 

【功能之衡量】

現在已經有了 IRTX 和 IRRX 的『功能』。如果我們將 紅 外 線紅外線發射碼中的 KEY_0、KEY_1 … KEY_9 看成『數字碼』,用來傳遞『四位數字訊息』,舉例︰

1314 ──→ 一生一世

5200 ──→ 我愛人人

等等,可以用『明文』,也可以用『亂數加密』成『密訊』。如此除了將需要『明文』或『密訊』的『發文』與『收文』之文法外,還需要『亂數』產生器,下面程式片段定義了一種『基本』 Atom 原子資料,稱為『Random』,是『四位亂數』的製造者,

        Atom/a ->
                real/a
            |   integer/a
            |   Function/a
            |   Var/a
            |   '' Expr/a ''
            |   Random/a
        ;

        Function/y ->
                函數一/f '' Expr/x ''               y = f(x)             |   函數二/f '<img src="http://www.freesandal.org/wp-content/ql-cache/quicklatex.com-5618a7a7b23dfd84e41ef622fed8142e_l3.png" class="ql-img-inline-formula quicklatex-auto-format" alt="' Expr/x1 ',' Expr/x2 '" title="Rendered by QuickLaTeX.com" height="19" width="165" style="vertical-align: -5px;"/>' y = f(x1,x2)
        ;

        Random/x -> "四位亂數"                          x = random.randint(0, 9999)         ;</pre> ,把它當成起始點,試以『應用』為中心,探索『亂數』的用途。     <a href="http://www.freesandal.org/wp-content/uploads/%E7%94%9F.png"><img class="alignnone size-full wp-image-32797" src="http://www.freesandal.org/wp-content/uploads/%E7%94%9F.png" alt="生" width="48" height="48" /></a> <span style="color: #ff0000;"><strong>生</strong></span>︰由於 Linux 核心的向前發展,直接支援了某些遙控器。欲了解這個改變,就先從閱讀這篇《 <a href="http://www.freesandal.org/wp-content/uploads/網.gif"><img class="alignnone size-full wp-image-33767" src="http://www.freesandal.org/wp-content/uploads/網.gif" alt="網" width="22" height="44" /></a> 》網文開始︰ <h1 align="CENTER"><a href="http://www.lirc.org/html/configuration-guide.html#key-symbols-using-linux-input-layer">Configuration guide</a></h1>  <hr width="70%" />  <h2 align="center">About this guide</h2> This guide tries to describe the basic configuration steps for commonly used hardware. It's focused on the basic usage scenario to get the remote up and running, the more advanced features are not covered. This includes irexec, lircmd, ir blasting and the TCP/IP-based remote features.  <hr />  <h2 align="center">Why should I use LIRC?</h2> Recent Linux kernels have built-in support for IR remotes. Using that, pressing an up-arrow on the remote works the same way as pressing the up-arrow on a keyboard. This is a modern "just works" solution. On the other hand, LIRC is an old style linux application which can be tweaked to do almost anything, but is tricky to setup. So, why would you use LIRC? <ul> 	<li>You might have a remote which is supported by LIRC but not the kernel.</li> 	<li>If you have a remote which isn't supported at all, LIRC is probably your best bet to get it running.</li> 	<li>You might be on a non-Linux platform supporting lirc e. g., MacOS.</li> 	<li>You might have an application which is more or less designed to use LIRC.</li> 	<li>You might need LIRC's capabilities e. g., modes where a single remote button can be teached to deliver different keys to the application.</li> 	<li>You might want to send IR signals to other devices (IR blasting).</li> 	<li>Handling several applications with one remote is easier with LIRC. E. g., you can use irexec(1) to run arbitrary commands in parallel with an application such as mythtv or xbmc.</li> </ul> So, while the kernel built-in handling works out of the box in many cases, there are still scenarios when LIRC is the right tool.  <hr />  <h2 align="center">Overall Configuration Decisions.</h2> <pre>       ----------         ---------------------               ----------        |        |         |                   |               |        |        |        |----→----| Linux input layer |-------→-------| Appli- |        |        |         |                   |  /dev/input   | cation |        |        |         ---------------------               |        | ---→---| kernel |                |        |                   ---------- remote |        |       devinput v        |        |        |                |        ^ uinput        |        |                |        |                   ----------        |        |         ---------------------               | Appli- |        |        |----→----|      lirc         |-------→-------| cation |--        |        |         |                   | /var/run/lirc |        | |        ----------         ---------------------               ---------- |--                                                                 |        | |                                                                 ---------- |                                                                   |        |                                                                   ---------- </pre> LIRC can be run together with the kernel in different ways. You need to decide on a general approach first.  Depending on whether lirc is used or not application will get data either from the input layer (/dev/input) or from LIRC (/var/run/lirc). Using the LIRC data requires application support. Support for LIRC is common in typical linux htpc applications like mythtv, xbmc and vlc.  The /var/run/lirc interfaces allows several applications to receive input events. On the other hand, the /dev/input interfaces only allows one application to receive the events. <ul> 	<li>A common scenario is to not involve lirc at all, the upmost path in the picture (kernel -> Linux input layer -> application). Unless there is reason to use lirc <a href="http://www.lirc.org/html/configuration-guide.html#why-use-lirc">(above)</a>) this is probably the way to go.</li> </ul> If you need to use lirc, there is two cases depending on if your remote is supported by the kernel or not. <ul> 	<li>If it's supported, you should probably at least first try using the linux input layer decoding and use that as input to lirc. This is the devinput data path in picture (kernel -> Linux input layer -> lirc -> app).</li> 	<li>If the kernel built-in decoding can't be used you need to use a lirc driver instead. This is the bottom data path (kernel ->lirc -> app).</li> </ul> Last option is to connect the LIRC driver to the linux input layer using LIRC's --uinput option. This means that application sees the input as coming from the kernel, and LIRC's other capabilities are not available. This is not described here.  ……  △ 現在系統上所用的『lircd.conf』檔案,遙控器的『名稱』叫做  name /home/pi/lircd.conf  ,如今也許應該重新命名為『tuxiome』︰ <pre class="lang:sh decode:true">pi@raspberrypi ~ more /etc/lirc/lircd.conf 
# Please make this file available to others
# by sending it to <lirc@bartelmus.de>
#
# this config file was automatically generated
# using lirc-0.9.0-pre1(default) on Tue Oct  8 07:05:38 2013
#
# contributed by
#
# brand:                       /home/pi/lircd.conf
# model no. of remote control:
# devices being controlled by this remote:
#
 
begin remote
 
  name  tuxiome
  bits           16
  flags SPACE_ENC|CONST_LENGTH
  eps            30
  aeps          100
 
  header       9006  4447
  one           594  1648
  zero          594   526
  ptrail        587
  repeat       9006  2210
  pre_data_bits   16
  pre_data       0xFD
  gap          107633
  toggle_bit_mask 0x0

,當然『TuxIOme』程式中的

def 紅外線輸出(字碼):
    global 重複次數
    subprocess.call(['irsend', 'SEND_ONCE', 'tuxiome', 字碼,"--count=" +str(重複次數) ])
    return "已送出"

也當對應修改。

其實所用遙控器的『lircd.conf』是由 LIRC 之『irrecord』程式產生的︰

IRRECORD

NAME

irrecord – application for recording IR-codes for usage with LIRC

SYNOPSIS

irrecord [-f] [-n] [-H driver] [-d device] [file]
irrecord -a <file>
irrecord -l
irrecord –help | –version

DESCRIPTION

This program will record the signals from your remote control and create a config file for lircd. A proper config file for lircd is maybe the most vital part of this package, so you should invest some time to create a working config file. Although I put a good deal of effort in this program it is often not possible to automatically recognize all features of a remote control.

If the program fails to recognize the protocol of the remote control you should use the –force option to at least create a config file in raw mode.

If file is not specified it defaults to “irrecord.conf”

If file already exists and contains a valid config irrecord will use the protocol description found there and will only try to record the buttons. This is very useful if you want to learn a remote where config files of the same brand are already available. Of course this will only work if the remotes use the same protocol but it’s worth a try. You will find template files for the most common protocols in the remotes/generic/ directory of this package. The name of the new file is created by appending .conf to the given filename in this case.

OPTIONS

-h –help
display this message
-v –version
display version
-a –analyse
Analyse a raw_codes config file, trying to convert it to a regular configuration.
-f –force
Force raw mode. Use this if recording fails otherwise. This creates a raw codes configuration file which can be used as-is or converted using the -a option.
-n –disable-namespace
disables namespace checks
-l –list-namespace
list valid button names
-H –driver=driver
Use given driver. -H help lists available drivers.
-d –device=device
read from given device
-D –loglevel=level
Determine the amount of logging information. [level] can be a symbolic syslog level: ‘error’,’warning, ‘info’, ‘notice’ or ‘debug’. lircd also defines three additional levels ‘trace’, ‘trace1’ and ‘trace2’ which gives even more messages (‘trace2’ bringing the most). However, in the log these messages are marked as ‘debug’. The level can also be an integer in the range 3 (almost no messages) to 10.

……

如果能深入了解它的用法與限制,你將可以『拷貝』 Copy 或應講『備份』 Backup 一般的家用遙控器,這也就是『學習型』遙控器的基本原理。

 

△ 如何安裝 kodi 『家庭劇院』 Home Theatre︰

sudo nano /etc/apt/sources.list.d/mene.list

# 輸入內容
deb http://archive.mene.za.net/raspbian wheezy contrib

# 安裝
sudo apt-get update
sudo apt-get install kodi

 

首次用『選單』執行 Kodi Media Center 媒體中心,系統將會產生『~/.kodi/』的目錄,請建立如下的遙控器設定參考檔案︰

pi@raspberrypi ~ more ~/.kodi/userdata/Lircmap.xml  <lircmap>   <remote device="tuxiome">     <select>KEY_ENTER</select>     <back>KEY_BACK</back>     <stop>KEY_STOP</stop>     <playpause>KEY_PLAYPAUSE</playpause>     <volumeup>KEY_VOLUMEUP</volumeup>     <volumedown>KEY_VOLUMEDOWN</volumedown>   </remote> </lircmap> pi@raspberrypi ~ 

以及

pi@raspberrypi ~ more ~/.kodi/userdata/keymaps/remote.xml  <keymap>   <global>     <remote>       <select>Select</select>       <back>PreviousMenu</back>       <stop>Stop</stop>       <playpause>PlayPause</playpause>       <volumeup>VolumeUp</volumeup>       <volumedown>VolumeDown</volumedown>     </remote>   </global> </keymap> pi@raspberrypi ~ 

,研究

一、為何沒有 KEY_LEFT、KEY_RIGHT、KEY_UP、KEY_DOWN 卻還能左右上下的呢?

二、遙控器難以操控的原因?

三、可以用 irsend 來控制嗎?

 

碼 ︰會 習 。學長講習後時間已經很晚,同學們興高采烈正忙著安裝與驗證諸諸種種軟體。何不……

長 長︰同學們請安靜。今天的會習,改為自由習作與自由討論 ……【鼓掌通過】

 

訊 ︰☿ 今日方真知︰循循善誘,誠非易事。