Example #1
0
	//
	// On Ajax XHTML request Event
	//
	virtual void onRequest(const int index, CString &result) {
		CTime tm;

		switch(index) {
		case CGI_INDEX_TEMP:
			result.printf("%0.2f, %0.2f, %d, %d, %d",
					sht1x.temp,
					sht1x.humi,
					(MAX_USER_POOL-heapAvailableSize())*100/MAX_USER_POOL,	// MAX user's memory=35KB
					sys.m_cpu,
					sys.m_net);
			break;

		case SSI_INDEX_DATE:
			tm = CTime::now();
			result.printf("%04d/%02d/%02d",
					tm.getYear(),
					tm.getMonth(),
					tm.getDay()
					);
			break;

		case SSI_INDEX_TIME:
			tm = CTime::now();
			result.printf("%02d:%02d:%02d",
					tm.getHour(),
					tm.getMinute(),
					tm.getSecond()
					);
			break;
		}
	}
Example #2
0
/* ==============================================
 main task routine
 ============================================== */
int main(void) {
	pool_memadd((uint32_t) pool, sizeof(pool));

#ifdef DEBUG
	dbg.start();
#endif

	// Simple demo Code (removable)
	CPin led(LED1);

	//
	// Add WebSocket Server with service 'sslm-k-056b'
	//
	MyWebSocketServer server;
	server.add("/sslm-k-056b", WSS_INDEX_SSLM);

	//
	// set reversion LED module index
	//
	sslm.setting(2, sslmREVERSE);
	sslm.setting(4, sslmREVERSE);
	sslm.start();

	//
	// set default LED brightness
	//
	sslm.brightness(0.5);	// brightness=50%

	// LED Test
	for (int v=0; v<16; v++) {
		for (int i=0; i<6; i++) {
			sslm.write(i, v);
			sslm.dot(i, (v & 0x01)? true: false);
		}
		sslm.trigger();
		sleep(500);
	}
	sslm.clear();

	CTime tm;
	int   v0, v1, v2;

	gnShowType = SHOW_FOR_TIME;
	gnHourType = SHOW_HOUR_24;

	// set dots : for time display
	sslm.dot(1, true);
	sslm.dot(2, true);
	sslm.dot(3, true);
	sslm.dot(4, true);

	// Enter an endless loop
	while (1) {
		// Simple demo Code (removable)
		led = !led;
		sleep(500);

		// update time
		tm = CTime::now();		// get system date/time

		if ( gnShowType==SHOW_FOR_TIME ) {
			// blink decimal point for Time Format
			if ( led ) {
				sslm.dot(1, true);
				sslm.dot(2, true);
				sslm.dot(3, true);
				sslm.dot(4, true);
			} else {
				sslm.dot(1, false);
				sslm.dot(2, false);
				sslm.dot(3, false);
				sslm.dot(4, false);
			}

			v0 = tm.getHour();
			if ( gnHourType==SHOW_HOUR_12 ) {
				if ( v0>12 ) v0 -=12;
			}
			v1 = tm.getMinute();
			v2 = tm.getSecond();

		} else {
			//
			// Show Date Info
			//
			v0 = tm.getYear() % 100;
			v1 = tm.getMonth();
			v2 = tm.getDay();
		}

		// update sslm
		sslm.write(5, v2 % 10);
		sslm.write(4, v2 / 10);
		sslm.write(3, v1 % 10);
		sslm.write(2, v1 / 10);
		sslm.write(1, v0 % 10);
		sslm.write(0, v0 / 10);
		sslm.trigger();
	}
	return 0;
}