Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu.Wang 2019-02-04 17:48:14 +08:00
commit ae5a36ec52
2 changed files with 67 additions and 74 deletions

View File

@ -1,16 +1,16 @@
[#]: collector: (lujun9972) [#]: collector: (lujun9972)
[#]: translator: (geekpi) [#]: translator: (geekpi)
[#]: reviewer: ( ) [#]: reviewer: (wxy)
[#]: publisher: ( ) [#]: publisher: (wxy)
[#]: url: ( ) [#]: url: (https://linux.cn/article-10507-1.html)
[#]: subject: (Get started with Roland, a random selection tool for the command line) [#]: subject: (Get started with Roland, a random selection tool for the command line)
[#]: via: (https://opensource.com/article/19/1/productivity-tools-roland) [#]: via: (https://opensource.com/article/19/1/productivity-tools-roland)
[#]: author: (Kevin Sonney https://opensource.com/users/ksonney (Kevin Sonney)) [#]: author: (Kevin Sonney https://opensource.com/users/ksonney (Kevin Sonney))
开始使用 Roland一款命令行随机选择工具 开始使用 Roland,一款命令行随机选择工具
====== ======
Roland 是我们在开源工具系列中的第七个工具,将帮助你在 2019 年提高工作效率。 > Roland 可以帮你做出艰难的决定,它是我们在开源工具系列中的第七个工具,将帮助你在 2019 年提高工作效率。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/dice_tabletop_board_gaming_game.jpg?itok=y93eW7HN) ![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/dice_tabletop_board_gaming_game.jpg?itok=y93eW7HN)
@ -22,13 +22,13 @@ Roland 是我们在开源工具系列中的第七个工具,它将帮助你在
当一周的工作结束后,我唯一想做的就是躺到沙发上打一个周末的游戏。但即使我的职业义务在工作日结束后停止了,但我仍然需要管理我的家庭。洗衣、宠物护理、确保我孩子有他所需要的东西,以及最重要的是:决定晚餐吃什么。 当一周的工作结束后,我唯一想做的就是躺到沙发上打一个周末的游戏。但即使我的职业义务在工作日结束后停止了,但我仍然需要管理我的家庭。洗衣、宠物护理、确保我孩子有他所需要的东西,以及最重要的是:决定晚餐吃什么。
像许多人一样,我经常受到[决策疲劳][1]的困扰,根据速度、准备难易以及(坦白地说)任何让我压力最小的方式都会导致不太健康的晚餐选择。 像许多人一样,我经常受到[决策疲劳][1]的困扰,根据速度、准备难易程度以及(坦白地说)任何让我压力最小的方式都会导致不太健康的晚餐选择。
![](https://opensource.com/sites/default/files/uploads/roland-1.png) ![](https://opensource.com/sites/default/files/uploads/roland-1.png)
[Roland][2]让我计划饭菜变得容易。Roland 是一款专为桌面角色扮演游戏设计的 Perl 应用。它从怪物和雇佣者等物品列表中随机挑选。从本质上讲Roland 在命令行做的事情与游戏大师在掷骰子时做的同样的事情,以便在游戏大师的《对玩家的坏事书》中的桌子上查找东西 [Roland][2] 让我计划饭菜变得容易。Roland 是一款专为桌面角色扮演游戏设计的 Perl 应用。它从怪物和雇佣者等项目列表中随机挑选。从本质上讲Roland 在命令行做的事情就像游戏管理员在桌子上掷骰子,以便在《要对玩家做的坏事全书》中找个东西一样
通过微小的修改Roland 可以做得更多。例如,只需添加一张桌子,我就可以让 Roland 帮我选择晚餐。 通过微小的修改Roland 可以做得更多。例如,只需添加一张,我就可以让 Roland 帮我选择晚餐。
第一步是安装 Roland 及其依赖项。 第一步是安装 Roland 及其依赖项。
@ -41,36 +41,36 @@ cpan install Getopt::Long::Descriptive Moose \
cd oland cd oland
``` ```
接下来,创建一个名为 **dinner** 的 YAML 文档,并输入我们所有的用餐选项。 接下来,创建一个名为 `dinner` 的 YAML 文档,并输入我们所有的用餐选项。
``` ```
type: list type: list
pick: 1 pick: 1
items: items:
- "frozen pizza" - "frozen pizza"
 - "chipotle black beans"   - "chipotle black beans"
 - "huevos rancheros"   - "huevos rancheros"
 - "nachos"   - "nachos"
 - "pork roast"   - "pork roast"
 - "15 bean soup"   - "15 bean soup"
 - "roast chicken"   - "roast chicken"
 - "pot roast"   - "pot roast"
 - "grilled cheese sandwiches"   - "grilled cheese sandwiches"
``` ```
运行命令 **bin/roland dinner** 将读取文件并选择其中一项。 运行命令 `bin/roland dinner` 将读取文件并选择其中一项。
![](https://opensource.com/sites/default/files/uploads/roland-2.png) ![](https://opensource.com/sites/default/files/uploads/roland-2.png)
我想提前计划一周,这样我可以提前购买所有食材。 **pick** 命令确定列表中要选择的物品数量,现在,**pick** 设置为 1。如果我想计划一周的晚餐菜单我可以将 **pick: 1** 变成 **pick: 7**,它会提供一周的菜单。你还可以使用 **-m** 选项手动输入选择。 我想提前计划一周,这样我可以提前购买所有食材。 `pick` 命令确定列表中要选择的物品数量,现在,`pick` 设置为 1。如果我想计划一周的晚餐菜单我可以将 `pick: 1` 变成 `pick: 7`,它会提供一周的菜单。你还可以使用 `-m` 选项手动输入选择。
![](https://opensource.com/sites/default/files/uploads/roland-3.png) ![](https://opensource.com/sites/default/files/uploads/roland-3.png)
你也可以用 Roland 做些有趣的事情,比如用经典短语添加一个名为 **8ball** 的文件。 你也可以用 Roland 做些有趣的事情,比如用经典短语添加一个名为 `8ball` 的文件。
![](https://opensource.com/sites/default/files/uploads/roland-4.png) ![](https://opensource.com/sites/default/files/uploads/roland-4.png)
你可以创建各种文件来帮助做出长时间工作后看起来非常难做的常见决策。即使你不用来做这个,你仍然可以用它来决定为今晚的游戏设置哪个狡猾的陷阱。 你可以创建各种文件来帮助做出长时间工作后看起来非常难做的常见决策。即使你不用来做这个,你仍然可以用它来为今晚的游戏设置哪个狡猾的陷阱做个决定
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -80,7 +80,7 @@ via: https://opensource.com/article/19/1/productivity-tools-roland
作者:[Kevin Sonney][a] 作者:[Kevin Sonney][a]
选题:[lujun9972][b] 选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi) 译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -9,88 +9,81 @@
translating by ezio translating by ezio
Computer Laboratory Raspberry Pi: Lesson 5 OK05 树莓派计算机实验室 课程 5 OK05
====== ======
The OK05 lesson builds on OK04 using it to flash the SOS Morse Code pattern (...---...). It is assumed you have the code for the [Lesson 4: OK04][1] operating system as a basis. OK05 课程构建于课程 OK04 的基础,使用更多代码方式烧、保存写莫尔斯码的 SOS 序列(`...---...`)。这里假设你已经有了 [课程 4: OK04][1] 操作系统的代码基础。
### 1 Data ### 1 数据
So far, all we've had to do with our operating system is provide instructions to be followed. Sometimes however, instructions are only half the story. Our operating systems may need data. 到目前为止,我们与操作系统有关的所有内容都提供了遵循的说明。然而有时候,说明只是一半。我们的操作系统可能需要数据
> 一些早期的操作系统确实只允许特定文件中的特定类型的数据,但是这通常被认为太严格了。现代方法确实使程序变得复杂的多。
通常,只是数据的值很重要。你可能经过训练,认为数据是指定类型,比如,一个文本文件包含文章,一个图像文件包含一幅图片,等等。说实话,这只是一个理想罢了。计算机上的全部数据都是二进制数字,重要的是我们选择用什么来解释这些数据。在这个例子中,我们会将一个闪灯序列作为数据保存下来。
`main.s` 结束处复制下面的代码:
``` ```
Some early Operating Systems did only allow certain types of data in certain files, but this was generally found to be too restrictive. The modern way does make programs a lot more complicated however. .section .data %定义 .data 段
``` .align 2 %对齐
pattern: %定义整形变量
In general data is just values that are important. You are probably trained to think of data as being of a specific type, e.g. a text file contains text, an image file contains an image, etc. This is, in truth, just an idea. All data on a computer is just binary numbers, how we choose to interpret them is what counts. In this example we're going to store a light flashing sequence as data.
At the end of 'main.s' copy the following code:
```
.section .data
.align 2
pattern:
.int 0b11111111101010100010001000101010 .int 0b11111111101010100010001000101010
``` ```
``` >`.align num` 保证下一行代码的地址是 `2^num` 的整数倍。
.align num ensures the address of the next line is a multiple of 2num .
.int val outputs the number val . >`.int val` 输出数值 `val`
```
To differentiate between data and code, we put all the data in the .data. I've included this on the operating system memory layout diagram here. I've just chosen to put the data after the end of the code. The reason for keeping our data and instructions separate is so that if we eventually implement some security on our operating system, we need to know what parts of the code can be executed, and what parts can't. 要区分数据和代码,我们将数据都放在 `.data` 区域。我已经将该区域包含在操作系统的内存布局图。我已经选择将数据放到代码后面。将我们的指令和数据分开保存的原因是,如果最后我们在自己的操作系统上实现一些安全措施,我们就需要知道代码的那些部分是可以执行的,而那些部分是不行的。
I've used two new commands here. .align and .int. .align ensures alignment of the following data to a specified power of 2. In this case I've used .align 2 which means that this data will definitely be placed at an address which is a multiple of 22 = 4. It is really important to do this, because the ldr instruction we used to read memory only works at addresses that are multiples of 4. 我在这里使用了两个新命令 `.align``.int`。`.align` 保证下来的数据是按照 2 的乘方对齐的。在这个里,我使用 `.align 2` ,意味着数据最终存放的地址是 `2^2=4` 的整数倍。这个操作是很重要的,因为我们用来读取内寸的指令 `ldr` 要求内存地址是 4 的倍数。
The .int command copies the constant after it into the output directly. That means that 111111111010101000100010001010102 will be placed into the output, and so the label pattern actually labels this piece of data as pattern. The .int command copies the constant after it into the output directly. That means that 111111111010101000100010001010102 will be placed into the output, and so the label pattern actually labels this piece of data as pattern.
``` 命令 `.int` 直接复制它后面的常量到输出。这意味着 `11111111101010100010001000101010`(二进制数) 将会被存放到输出,所以标签模式实际将标记这段数据作为模式。
One challenge with data is finding an efficient and useful representation. This method of storing the sequence as on and off units of time is easy to run, but would be difficult to edit, as the concept of a Morse - or . is lost.
```
As I mentioned, data can mean whatever you want. In this case I've encoded the Morse Code SOS sequence, which is ...---... for those unfamiliar. I've used a 0 to represent a unit of time with the LED off, and a 1 to represent a unit of time with the LED on. That way, we can write some code which just displays a sequence in data like this one, and then all we have to do to make it display a different sequence is change the data. This is a very simple example of what operating systems must do all the time; interpret and display data. > 关于数据的一个挑战是寻找一个高效和有用的展示形式。这种保存一个开、关的时间单元的序列的方式,运行起来很容易,但是将很难编辑,因为摩尔斯的原理 `-``.` 丢失了。
Copy the following lines before the loop$ label in 'main.s'. 如我提到的,数据可以意味这你想要的所有东西。在这里我编码了摩尔斯代码 SOS 序列,对于不熟悉的人,就是 `...---...`。我使用 0 表示一个时间单元的 LED 灭灯,而 1 表示一个时间单元的 LED 亮。这样,我们可以像这样编写一些代码在数据中显示一个序列,然后要显示不同序列,我们所有需要做的就是修改这段数据。下面是一个非常简单的例子,操作系统必须一直执行这段程序,解释和展示数据。
复制下面几行到 `main.s` 中的标记 `loop$` 之前。
``` ```
ptrn .req r4 ptrn .req r4 %重命名 r4 为 ptrn
ldr ptrn,=pattern ldr ptrn,=pattern %加载 pattern 的地址到 ptrn
ldr ptrn,[ptrn] ldr ptrn,[ptrn] %加载地址 ptrn 所在内存的值
seq .req r5 seq .req r5 %重命名 r5 为 seq
mov seq,#0 mov seq,#0 %seq 赋值为 0
``` ```
This code loads the pattern into r4, and loads 0 into r5. r5 will be our sequence position, so we can keep track of how much of the pattern we have displayed. 这段代码加载 `pattrern` 到寄存器 `r4`,并加载 0 到寄存器 `r5`。`r5` 将是我们的序列位置,所以我们可以追踪有多少 `pattern` 我们已经展示了。
The following code puts a non-zero into r1 if and only if there is a 1 in the current part of the pattern. 下面的代码将非零值放入 `r1` ,如果仅仅是如果,这里有个 1 在当前位置的 `pattern`
``` ```
mov r1,#1 mov r1,#1 %加载1到 r1
lsl r1,seq lsl r1,seq %对r1 的值逻辑左移 seq 次
and r1,ptrn and r1,ptrn %按位与
``` ```
This code is useful for your calls to SetGpio, which must have a non-zero value to turn the LED off, and a value of zero to turn the LED on. 这段代码对你调用 `SetGpio` 很有用,它必须有一个非零值来关掉 LED而一个0值会打开 LED。
Now modify all of your code in 'main.s' so that each loop the code sets the LED based on the current sequence number, waits for 250000 micro seconds (or any other appropriate delay), and then increments the sequence number. When the sequence number reaches 32, it needs to go back to 0. See if you can implement this, and for an extra challenge, try to do it using only 1 instruction (solution in the download). 现在修改 `main.s` 中全部你的代码,这样代码中每次循环会根据当前的序列数设置 LED等待 250000 毫秒(或者其他合适的延时),然后增加序列数。当这个序列数到达 32 就需要返回 0.看看你是否能实现这个功能,作为额外的挑战,也可以试着只使用一条指令。
### 2 Time Flies When You're Having Fun... ### 2 Time Flies When You're Having Fun... 当你玩得开心时,过得很快
You're now ready to test this on the Raspberry Pi. It should flash out a sequence of 3 short pulses, 3 long pulses and then 3 more short pulses. After a delay, the pattern should repeat. If it doesn't work please see our troubleshooting page. 你现在准备好在树莓派上实验。应该闪烁一串包含 3 个短脉冲3 个长脉冲,然后 3 个更短脉冲的序列。在一次延时之后,这种模式应该重复。如果这部工作,请查看我们的问题页。
Once it works, congratulations you have reached the end of the OK series of tutorials. 一旦它工作,祝贺你已经达到 OK 系列教程的结束。
In this series we've learnt about assembly code, the GPIO controller and the System Timer. We've learnt about functions and the ABI, as well as several basic Operating System concepts, and also about data. 在这个谢列我们学习了汇编代码GPIO 控制器和系统定时器。我们已经学习了函数和 ABI以及几个基础的操作系统原理和关于数据的知识。
You're now ready to move onto one of the more advanced series. 你现在已经准备好下面几个更高级的课程的某一个。
* [Screen][2] 系列是接下来的,会教你如何通过汇编代码使用屏幕。
* The [Screen][2] series is next and teaches you how to use the screen with assembly code. * [Input][3] 系列教授你如何使用键盘和鼠标。
* The [Input][3] series teaches you how to use the keyboard and mouse.
到现在,你已经有了足够的信息来制作操作系统,用其它方法和 GPIO 交互。如果你有任何机器人工具,你可能会想尝试编写一个通过 GPIO 管教控制的机器人操作系统。
By now you already have enough information to make Operating Systems that interact with the GPIO in other ways. If you have any robot kits, you may want to try writing a robot operating system controlled with the GPIO pins!
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -98,7 +91,7 @@ via: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok05.html
作者:[Robert Mullins][a] 作者:[Robert Mullins][a]
选题:[lujun9972][b] 选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID) 译者:[ezio](https://github.com/oska874)
校对:[校对者ID](https://github.com/校对者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出