GNU/Light 😂

#一个简单到不能再简单的台灯

Background

由于寝室里照明不好,写作业浑身难受,加上通用技术课上需要做一个台灯。于是我就用 AutoCAD 画了图,然后用实验室的激光雕刻机雕刻的亚克力板,最后组装而成。

Details

  • 使用2.7mm厚的亚克力板
  • 使用LED灯带照明
  • 集成开关
  • 支持照明方向调节
  • 额定电压12v,额定功率约1w
  • 需要外部供电

BOM

  • 2.7mm 亚克力板
  • M3 圆头螺丝
  • 30mm M3 铜螺柱
  • M3 螺母
  • 12v LED 灯带
  • 船形开关
  • 5.5mm DC 插座
  • 导线

Downloads

DWG

Pictures

 

展厅用多媒体播放系统

Background

学校科学楼一楼展示了机器人社团的优秀作品,但仅仅只有海报上的文字和图片介绍,比较枯燥无味。于是老师安排某学长制作了一套多媒体播放系统。学长基于现成的某品牌播(kan)(xi)(ji)、Arduino Uno、光强传感器和红外发射器制作了最初版本。原理是:当用户的手指按在装有光强传感器的玻璃上,作为主控器的 Arduino 检测到信号,通过红外发射器向播放器发射播放机配的遥控器的“播放”键所对应的红外信号,播放器接收到信号开始播放。

但控制时常失灵,主控器“一脸懵逼”:“这是天黑了,还是用户手指按下去了?嗯,那我先把红外信号发出去再说。” 加上播放器的屏幕本身质量就差,在闷热的展柜里一直亮着,没过一个星期就坏了。老的系统就一直搁置在那里。

然后学期结束的时候,这锅就我背了。

Solve It

既然光强传感器不靠谱,难以区分是否是手指真的按下了。那就干脆用电容式触摸传感器——它不仅可以准确判断是否是人手触摸的,而且可以隔着一定厚度的玻璃、亚克力等非导电材料感应。

 

既然原有的播放器屏幕不靠谱,那就需要使用普通的电脑液晶屏+电源管理系统——只有当视频播放的时候屏幕电源才打开,否则一直保持待机状态。这样不仅节省电能,还能延长寿命,避免屏幕长时间保持点亮而老化。

 

所以问题来了,播放器(这里指响应触摸事件并读取、解码视频文件,并输出视频信号的设备)用什么呢?就用树莓派(Raspberry Pi)吧——它是一种基于Linux系统的微型计算机。

 

但是。。。树莓派默认是将Micro SD卡作为 Rootfs 的,以前常常因为意外断电,导致Micro SD卡里的文件系统崩溃,树莓派无法启动。或是因为在开机状态下Micro SD卡松动,导致系统崩溃。这卡可真不靠谱。为了解决这个问题,我尝试在 Bootloader 阶段(在 Linux 系统内核启动之前)将Micro SD卡里的预打包的系统镜像复制到内存指定的区域里,然后以内存作为 Rootfs 启动操作系统。这样的话,一旦文件复制完毕,就不需要再依赖Micro SD卡。妈妈再也不用担心Micro SD卡松动或者意外掉电导致各种崩溃啦!

Additional Notes
Traditional Boot-up Sequence:

1. Bootloader
pass the kernel cmdline with "root=/dev/mmcblk0p2" option
load the kernel into RAM
boot the kernel up

2. Linux Kernel
Mount the filesystem in the Micro SD as Rootfs
Start the /sbin/init to initialize the system in the Rootfs
...

RamFS-based Boot-up Sequence:

1. Bootloader
pass the kernel cmdline with "root=/dev/ram0" option
load the kernel into RAM
load the Ramdisk image (aka. prebuilt system image) in the Micro SD into RAM
boot the kernel up

2. Linux Kernel
Mount the filesystem in the RAM as Rootfs
Start the /sbin/init to initialize the system in the Rootfs

...

Features

  • 带硬件加速的视频解码,支持[email protected]视频
  • 自动电源管理(通过HDMI输出开关实现)
  • 基于 RamFS 的 Linaro Ubuntu Vivid 15.04 的操作系统

Downloads

// TODO

Hash Algorithm

#include <cstring>
#include <iostream>

template <class T>
class HashTable {
#ifndef HASH_K
#define HASH_K 100007
#endif
private:
	struct {
		int key;
		T value;
		bool used;
	} hashTable[HASH_K];
public:
	HashTable() {
		memset(hashTable, 0, sizeof(hashTable));
	}
	
	T &operator [] (const int &k) {
		int h = k % HASH_K;
		
		for (int i = 0; i < HASH_K; i++) {
			int hh = (h + i) % HASH_K;
			if (hashTable[hh].key == k || hashTable[hh].used == false) {
				hashTable[hh].used = true;
				hashTable[hh].key = k;
				return hashTable[hh].value;
			}
		}
	}
};

HashTable<int> ht;

int main() {
	using namespace std;

	ht[1] = 2;
	ht[3] = 5;
	ht[100008] = 233;
	
	cout << ht[1] << " " << ht[2] << " " << ht[100008] << endl;
	return 0;
}

E9 卡片电脑升级内核和Ubuntu系统

噫,E9 自带的 Ubuntu 12.02 真!是!太!老!了!

本来想用 E9 当个 Agar.io Server(现已做好,见上一篇文章),发现连 Node.js 版本太老(肯定是系统版本太老的问题)

于是各种逛论坛。。ww

发现其中只提供了内核和 Rootfs,并没有提及具体如何烧写到E9中。按照官方说明的烧写方法,需要 uImage 内核文件。在下载的 Rootfs 中,zImage 替代了它。

那么关键问题是如何不需要 uImage,用一台 Windows 电脑写入 E9 呢?

 

在升级之前,需要……

  • E9光盘上带的 Mfgtools For Windows;
  • E9卡片电脑;
  • RS232 – USB 转换线(可选);
  • MiniUSB 线;
  • 一台可以上网的电脑。

 

接下来……

  1. 下载 U-BootRootfs,感谢 RIX
  2. 将 U-Boot 和 Rootfs 拷贝到 Mfgtools\Profiles\MX6Q Linux Update\OS Firmware\files\ubuntu 下;
  3. rootfs.tgz 重命名为 oneiric.tgz
  4. 修改 Mfgtools\Profiles\MX6Q Linux Update\OS Firmware\ucl2.xml。取消uImage写入,具体方法如下:
  5.  

    在 109 行左右找到

        <CMD state="Updater" type="push" body="send" file="files/ubuntu/uImage">Sending kernel uImage</CMD>
        <CMD state="Updater" type="push" body="$ dd if=$FILE of=/dev/mmcblk0 bs=1M seek=1 conv=fsync">write ubuntu kernel image to sd card</CMD>
    

    将其注释,即改为

    <!--
        <CMD state="Updater" type="push" body="send" file="files/ubuntu/uImage">Sending kernel uImage</CMD>
        <CMD state="Updater" type="push" body="$ dd if=$FILE of=/dev/mmcblk0 bs=1M seek=1 conv=fsync">write ubuntu kernel image to sd card</CMD>
    --->
    
  6. 将E9跳线帽设为Download模式(参见官方手册),并上电,连接至电脑;
  7. 打开Mfgtools,猛戳Start,等待直到烧写完成;
  8. 享受新系统!

Agar 推荐配置

// Ogar configurations file
// Lines starting with slashes are comment lines

// [Server]
// serverGamemode: 0 = FFA, 1 = Teams, 2 = Experimental, 10 = Tournament, 11 = Hunger Games
// serverBots: Amount of player bots to spawn (Experimental)
// serverViewBase: Base view distance of players. Warning: high values may cause lag
// serverStatsPort: Port for the stats server. Having a negative number will disable the stats server.
// serverStatsUpdate: Amount of seconds per update for server stats
// serverLogLevel: Logging level of the server. 0 = No logs, 1 = Logs the console, 2 = Logs console and ip connections
serverMaxConnections = 64
serverPort = 96
serverGamemode = 2
serverBots = 0
serverViewBaseX = 1024
serverViewBaseY = 592
serverStatsPort = 88
serverStatsUpdate = 60
serverLogLevel = 1

// [Border]
// Border values of the map (Vanilla values are left/top = 0, right/bottom = 11180.3398875)
borderLeft = 0
borderRight = 12000
borderTop = 0
borderBottom = 12000

// [Spawn]
// Each interval is 1 tick (50 ms)
spawnInterval = 20
foodSpawnAmount = 10
foodStartAmount = 400
foodMaxAmount = 2000
foodMass = 10
virusMinAmount = 40
virusMaxAmount = 200
virusStartMass = 200
virusFeedAmount = 7

// [Ejected Mass]
// ejectMass: Mass of ejected cells
// ejectMassLoss: Mass lost when ejecting cells
// ejectSpeed: Base speed of ejected cells
// ejectSpawnPlayer: Chance for a player to spawn from ejected mass
ejectMass = 12
ejectMassLoss = 16
ejectSpeed = 160
ejectSpawnPlayer = 50

// [Player]
// playerRecombineTime: Base amount of ticks before a cell is allowed to recombine (1 tick = 1000 milliseconds)
// playerMassDecayRate: Amount of mass lost per tick (Multiplier) (1 tick = 1000 milliseconds)
// playerMinMassDecay: Minimum mass for decay to occur
// playerDisconnectTime: The amount of seconds it takes for a player cell to be removed after disconnection (If set to -1, cells are never removed)
playerStartMass = 100
playerMaxMass = 225000
playerMinMassEject = 32
playerMinMassSplit = 36
playerMaxCells = 512
playerRecombineTime = 1
playerMassDecayRate = .002
playerMinMassDecay = 9
playerMaxNickLength = 15
playerDisconnectTime = 60

// [Gamemode]
// Custom gamemode settings
// tourneyTimeLimit: Time limit of the game, in minutes.
// tourneyAutoFill: If set to a value higher than 0, the tournament match will automatically fill up with bots after value seconds
// tourneyAutoFillPlayers: The timer for filling the server with bots will not count down unless there is this amount of real players
tourneyMaxPlayers = 12
tourneyPrepTime = 10
tourneyEndTime = 30
tourneyTimeLimit = 20
tourneyAutoFill = 0
tourneyAutoFillPlayers = 1

Set Up Web Servers

For Debian / Ubuntu ONLY.
Execute the following commands in your terminal

Install PHP5, Apache2 and MySQL Server

$ sudo apt-get update
$ sudo apt-get install php5 apache2 mysql-server

Install additional modules

You can install additional modules like PHP5-MySQL, PHP5-cURL and more.

$ sudo apt-get install php5-mysql php5-curl

Then go to your WebRoot and upload some webpages

They are usually located in /var/www/html

Enjoy your new website!

By entering the IP address of your computer, you can enter your website now.

orz

无意中发现凡龙科技乱搞的学校媒体服务器的用于推送学校视频广播的RTMP端口竟然是——

对!公!网!开!放!的!

公!网!开!放!的!

网!开!放!的!

开!放!的!

放!的!

的!

 

也就是说我们稍微往那个端口里塞一点RTMP流媒体会出现可(dou)怕(bi)的后果。