这是我的功能打开串口(使用Ubuntu 12.04):
int open_port(void)
{
int fd; /* File descriptor for the port */
fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
// Could not open the port.
perror("open_port: Unable to open /dev/ttyUSB0 - ");
}
else
fcntl(fd, F_SETFL, 0);
struct termios options;
tcgetattr(fd, &options);
//setting baud rates and stuff
cfsetispeed(&options, B19200);
cfsetospeed(&options, B19200);
options.c_cflag |= (CLOCAL | CREAD);
tcsetattr(fd, TCSANOW, &options);
tcsetattr(fd, TCSAFLUSH, &options);
options.c_cflag &= ~PARENB;//next 4 lines setting 8N1
options.c_cflag &= ~CSTOPB; …Run Code Online (Sandbox Code Playgroud) Ubuntu 11.04,G ++,freeglut和GLUT.
我根本不明白这一点.这是我得到的错误:
whatever.cc:315:59: error: cannot convert ‘std::string’ to ‘const unsigned char*’ for argument ‘2’ to ‘void glutStrokeString(void*, const unsigned char*)’
Run Code Online (Sandbox Code Playgroud)
如果我尝试glutBitmapString:
whatever.cc:315:59: error: cannot convert ‘std::string’ to ‘const unsigned char*’ for argument ‘2’ to ‘void glutBitmapString(void*, const unsigned char*)’
Run Code Online (Sandbox Code Playgroud)
这是相关的代码(我认为).
scoreStream << "Score: " << score << "\0";
scoreString = scoreStream.str();
// ...in another method:
glRasterPos2i(0, 0);
glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
glutBitmapString(GLUT_BITMAP_HELVETICA_18, scoreString);
Run Code Online (Sandbox Code Playgroud)
这个答案告诉我它应该有效,但事实并非如此.
引用那些不想跳的人:
// Draw blue text at screen coordinates (100, 120), where (0, 0) …Run Code Online (Sandbox Code Playgroud) 使用OpenGL/GLUT和C++制作游戏.
我听说在GLUT中管理键盘内容的最简单方法是使用bool数组.
基本上,这就是我所拥有的:
bool* keys = new bool[256];
Run Code Online (Sandbox Code Playgroud)
...
void keyDown(unsigned char ch, int x, int y)
{
keys[ch] = true;
}
void keyUp(unsigned char ch, int x, int y)
{
keys[ch] = false;
}
Run Code Online (Sandbox Code Playgroud)
然后,如果我想知道一个键的状态,我只需返回键[key].
我有一个类似的特殊键设置.现在,在我死后的游戏中,它会重置所有需要重置的值并再次启动游戏.直到现在,包括
keys = new bool[256];
Run Code Online (Sandbox Code Playgroud)
以及特殊键数组的类似声明.对我来说没有任何意义的是偶尔,这种假设的数组重置会导致键中的部分或全部值变为两位或三位整数(因此总是评估为真,并使得玩家角色不受控制地移动,直到一个或显然失望的更多钥匙被压抑了.我怀疑这发生了,因为在结束游戏时,其中一个键被按下,从而混淆了C++,当它试图使整个数组失真并发现有一件事被证实是真的.
伙计,那令人困惑.据我所知,通过消除密钥的所有额外初始化,问题已得到解决.但我不明白.任何人都对我如何设法将一些bool变成整数有任何想法?
我有一个问题,我试图解决一段时间.我按照网站上的说明创建了我的第一个Django应用程序.我目前正在访问管理页面,但它一直没有工作.另外,当我运行本地服务器时,出现"发生服务器错误.请联系管理员"的错误.在我尝试访问django管理页面之前没有发生这种情况.错误回调的最后一行是:
AttributeError: 'Settings' object has no attribute 'ROOT_URLCONF'
Run Code Online (Sandbox Code Playgroud)
完整的回调是:
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/home/username/Desktop/djangoajax/local/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 67, in __call__
return self.application(environ, start_response)
File "/home/username/Desktop/djangoajax/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 241, in __call__
response = self.get_response(request)
File "/home/username/Desktop/djangoajax/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 82, in get_response
urlconf = settings.ROOT_URLCONF
File "/home/username/Desktop/djangoajax/local/lib/python2.7/site-packages/django/utils/functional.py", line 185, in inner
return func(self._wrapped, *args)
AttributeError: 'Settings' object has no attribute 'ROOT_URLCONF'
Run Code Online (Sandbox Code Playgroud)
manage.py是:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") …Run Code Online (Sandbox Code Playgroud)