cnCalc计算器论坛

 找回密码
 注册
搜索
查看: 9413|回复: 6

[Nspire] Ndless开始开发

[复制链接]
发表于 2012-12-23 21:07:06 | 显示全部楼层 |阅读模式
前提
你需要C语言编程基础

Ndless SDK
下载Ndless SDK。选择一个版本最高的。

对于Windows
解压SDK压缩包,保证路径中没有空格。
如果你用过之前基于命令行的SDK,请删除PATH变量中的相关定义,新的SDK可能与它们冲突。
按照 emu_resources/_ReadMe.txt中的步骤安装SDK集成的TI-Nspire模拟器
你可能还希望把c和h文件与NdlessEditor.exe关联起来。
现在一切都已就绪,从编辑器到编译器,Ndless SDK都已经准备好了,不需要其它步骤。

对于Linux
SDK提供了编译器脚本、头文件和库,但是你必须自己建立GCC编译工具链,使用你自己的编辑器和模拟器。可以参考这个教程.

Ndless编辑器
Ndless编辑器是一个基于SciTE的文本编辑器,但是经过了配置和扩展,使他十分适合用来编写C语言程序。
ndlesseditor11.jpg
打开SDK根目录下的 NdlessEditor.exe

和Ndless有关的命令在 Tools 菜单下。运行命令时,相关消息会显示在屏幕下方。

你的第一个程序
我们将会用一个经典的HelloWorld来开始。这个例程中我们将会使用SDK提供的nspireio库。接下来,你将会了解到如何新建一个工程,编译,并在模拟器中运行。

使用 Tools > New Ndless project 来建立一个新的ndless工程
newproject.jpg
把他保存到工程目录里,我们将把源码命名为 hello.c 并保存在  helloworld/ 文件夹中

编写代码

接下来我们就用nspireio2库来显示一句Hello World.

首先引用一下
#include <os.h>
#include <nspireio2.h>
定义一个nspireio控制台,初始化为灰度模式,然后清屏
nio_console csl;
lcd_ingray();
clrscr();
设置一下
// 53 columns, 29 rows. 0px offset for x/y.
// Background color 0 (black), foreground color 15 (white)
nio_InitConsole(&csl, 53, 29, 0, 0, 0, 15);
nio_DrawConsole(&csl);
然后显示Hello World,等待按键按下
nio_printf(&csl, "hello world!");
wait_key_pressed();
最后程序退出时释放控制台
nio_CleanUp(&csl);
return 0;
我们来看看完整的程序
  1. #include <os.h>
  2. #include <nspireio2.h>

  3. int main(void) {
  4.         nio_console csl;
  5.         lcd_ingray();
  6.         clrscr();
  7.         // 53 columns, 29 rows. 0px offset for x/y.
  8.         // Background color 0 (black), foreground color 15 (white)
  9.         nio_InitConsole(&csl, 53, 29, 0, 0, 0, 15);
  10.         nio_DrawConsole(&csl);
  11.         nio_printf(&csl, "hello world!");
  12.         wait_key_pressed();
  13.         nio_CleanUp(&csl);
  14.         return 0;
  15. }
复制代码
关于更多这里使用的函数,请参考 nspireio’s documentation 和 libndls’s documentation (libndls 是由Sdk提供的 TI-Nspire 定义库).

编译
使用 Tools > Build (或者按下F7)来编译程序。第一次编译时必须给程序命名。Type ‘helloworld’ in the at the bottom of the editor, and press enter. This will be the name of the generated .tns.
choose-prgm-name1.jpg
A Makefile is created in the program’s directory. If you want to change the name of the program later, you’ll be able to edit the Makefile and change the EXE variable.

The build commands result are displayed in the message pane. If you get an error, double check the source code of the program.
program-build.jpg

Emulating
Testing the first versions of your program with the emulator may be faster than transferring them after each build to a real TI-Nspire. Let’s run the TI-Nspire emulator with the Tools > TI-Nspire emulator command. Wait for a few seconds until the OS is fully loaded.
emulator.jpg
If you have any issue here, make sure you have followed every step described in emu_resources/_ReadMe.txt of the Ndless SDK.

We can now send the helloworld.tns file we have just built. In the Ndless Editor where hello.c is open, use the command Tools > Transfer the program. The program will be automatically sent to the ‘ndless’ directory of the TI-Nspire OS.
helloworld-sent.jpg
Finally let make it say hello to the world: open the ‘ndless’ directory in the emulator and open helloworld.tns. If a popup is displayed telling you that ‘This document format is not supported’, Ndless was not installed correctly. Follow again the instructions in emu_resources/_ReadMe.txt.

helloworld.tns is stored in the ‘hello/’ directory of the computer we have created at the beginning of the tutorial. What about trying it on your own TI-Nspire?

Going further
You can explore the program samples in the ‘_samples/’ directory of the SDK.

Also make sure to have a look at the libdndls’s documentation for TI-Nspire specific functions, and the syscalls page for the supported standard functions. You will then be interested by advanced usage of the Ndless SDK.

To try to port SDL-based programs and games, use hoffa’s nSDL library. The library itself is already provided with the Ndless SDK, you just have to include <SDL/SDL.h> at the beginning of the program. See _samples/helloworld-sdl/ in the Ndless SDK directory for a sample program.

Advanced editing
The Ndless Editor’s Tools menu provides the following additional commands:

Compile: compile the currently open .c file, but not the whole program. This command can be used to quickly check the file for syntax errors.
Clean Build: rebuild the whole program. Building with the Build command is incremental. A Clean Build can sometimes solve building issues.
Clean: clean any file generated by the build.
Ndless SDK console: open a MSYS (Unix-like) console in the current program directory. This can be useful if you have customized the program’s Makefile and want to run specific Make targets.
Since the Ndless Editor is SciTE-based, you may want to fiddle with SciTE’s configuration options to customize it for a better TI-Nspire development experience. Overriding the default Ndless SDK configuration with the file SciTEUser.properties is the recommended way to go.

评分

参与人数 1金钱 +3 收起 理由
Cyvre + 3 赞一个!

查看全部评分

发表于 2012-12-24 13:15:36 | 显示全部楼层
必须支持!
发表于 2012-12-24 17:36:37 | 显示全部楼层
好   
发表于 2012-12-24 20:12:57 | 显示全部楼层
看不到更新啊,急啊!
发表于 2012-12-29 23:34:05 | 显示全部楼层
吾等小白都看懂了……
发表于 2013-3-24 14:34:15 | 显示全部楼层
跪求楼主不吝赐教~按照emu_resources/_ReadMe.txt中的步骤安装SDK集成的TI-Nspire模拟器
时有疑问……
后面的不会了……

鄙人nspire迷,C语言迷……
望楼主施舍知识……
发表于 2014-12-30 22:33:04 | 显示全部楼层
是时候开始捣鼓Ndless了。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|cnCalc计算器论坛

GMT+8, 2024-12-23 06:47 , Processed in 0.059195 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表