volatile char timerStatusRemote(char key, char first)
{
	static uint32_t startTime = 0;
	static uint8_t toggle = 0;

	if(first)
	{
		startTime = 0;
	}

	if(clock.Ms() > startTime + 100)
	{
		startTime = clock.Ms();
		lcd.cls();

		if(toggle == 0)
			remote.request(REMOTE_BATTERY);
		else if(toggle == 1)
			remote.send(REMOTE_BATTERY, REMOTE_TYPE_NOTIFY_SET);
		else if(toggle == 2)
			remote.request(REMOTE_START);
		else
			remote.request(REMOTE_STATUS);

		if(++toggle >= 10) toggle = 2;

		displayTimerStatus(1);

		menu.setTitle(TEXT("Remote"));
		if(remote.running)
			menu.setBar(TEXT("RETURN"), TEXT("STOP"));
		else
			menu.setBar(TEXT("RETURN"), BLANK_STR);
		lcd.update();
	}

	if(!remote.connected) return FN_CANCEL;

	switch(key)
	{
	   case FR_KEY:
		   remote.set(REMOTE_STOP);
		   break;
		   
	   case FL_KEY:
	   case LEFT_KEY:
		   remote.send(REMOTE_BATTERY, REMOTE_TYPE_NOTIFY_UNSET);
		   toggle = 0;
		   return FN_CANCEL;
	}

	return FN_CONTINUE;
}
예제 #2
0
파일: nit-rsh.cpp 프로젝트: noriter/nit
	virtual void onConsoleCommand(ConsoleWindow* con, const std::string& str)
	{ 
		if (_remote.getHostPeer() == NULL)
		{
			String cmd = str.c_str();
			if (StringUtil::startsWith(cmd, "connect"))
			{
				String addr = cmd.substr(8);

				if (_remote.connect(addr))
				{
					DataValue params = DataValue::fromJson("{ client:'nit-rsh', version:'1.0', log:true }");

					_remote.request(_remote.getHostPeer(), _channelID, RQ_ATTACH, params);
					_lastAddr = addr;
				}
				return;
			}
			else
			{
				if (!_lastAddr.empty())
				{
					if (_remote.connect(_lastAddr))
					{
						DataValue params = DataValue::fromJson("{ client:'nit-rsh', version:'1.0', log:true }");

						_remote.request(_remote.getHostPeer(), _channelID, RQ_ATTACH, params);
					}
				}

				if (_remote.getHostPeer() == NULL)
					LOG(0, "*** not connected\n");
			}
		}

		if (!str.empty())
		{
			Ref<RemotePeer> peer = _remote.getHostPeer();

			if (peer)
			{
				if (str == "bye")
					peer->disconnect();
				else
					_remote.notify(peer, _channelID, NT_COMMAND, DataValue(str.c_str(), (int) str.length()));
			}
		}
	}