Esempio n. 1
0
/*****************************************************************************
	LED(h/l)
*****************************************************************************/
bool CGainer::SetLED(bool isOn)
{
	check_config();

	if ( isOn ) {
		return command_send("h*").size() != 0;
	}
	else {
		return command_send("l*").size() != 0;
	}
}
Esempio n. 2
0
/*****************************************************************************
	全サーボ設定
*****************************************************************************/
bool CGainer::SetServoAll(const std::vector<WORD> &data)
{
	check_config();

	int limit = 8;
	if ( m_config != 8 ) { return false; }

	std::string c("P");
	char buf[32];

	size_t n = data.size();
	if ( n > limit ) {
		n = limit;
	}

	for ( size_t i = 0 ; i < n ; ++i ) {
		sprintf(buf,"%02X",data[i]);
		c += buf;
	}

	int diff = limit - n;
	while ( diff > 0 ) {
		c += "00";
		--diff;
	}
	c += "*";

	return command_send(c).size() != 0;
}
Esempio n. 3
0
File: hlib.c Progetto: cafiend/W12
int Fill3f(Display *display, int r, int g, int b) {
	/* There's probably more error checking to do here since
	 * changing the colorMode actually defines the max values 
	 * acceptable here. Default is 1.0 so we'll start with that...
	 */
	if (r > 1.0 || g > 1.0 || b > 1.0) {
		return -1;
	}
	Command *cmd = NULL;
    Socket *socket = NULL;
    
    socket = display->socket;
    
    /* cmd = command_format("FI_F %f %f %f", r, g, b); */
    cmd = command_format_json("FI_F", "%f %f %f", r, g, b);
    if (cmd == NULL)
        return -1;
        
    if (command_send(cmd, socket) != 0) {
        command_free(cmd);
        return -1;
    }
    
    return 0;
}
Esempio n. 4
0
File: hlib.c Progetto: cafiend/W12
/* Create a text area over the canvas to receive text directly */
int CreateTextArea(Display *display, const char *id, int x, int y, int width, int height, int readonly)
{
	Command *cmd = NULL;
    Socket *socket = NULL;
    
    socket = display->socket;
        
    if (id == NULL)
        return -1;
    
    if (strlen(id) == 0)
        return 0;
       
    if (readonly != TRUE && readonly != FALSE)
		return 0;
        
    cmd = command_format_json("NEW_TXT_AREA", "\"%s\" %d %d %d %d %d", id, x, y, width, height, readonly);
    if (cmd == NULL)
        return -1;
    
    if (command_send(cmd, socket) != 0) {
        command_free(cmd);
        return -1;
    }
    
    return 0;
}
Esempio n. 5
0
File: hlib.c Progetto: cafiend/W12
int SendKeyboardCallbackMsg(Display *display, char* type, char* list)
{
	Command *cmd = NULL;
	Socket *socket = NULL;
	int i,size;
	char *str, args[10];

	socket = display->socket;

	if (list == NULL) {
		cmd = command_format_json(type, "\"%s\"", "ALL");
	} else {
		size = strlen(list);
		str = calloc(size*5, sizeof(char));
		for (i = 0; i < size; i ++) {
			if (i != size -1) sprintf(args, "%hu,", list[i]);
			else sprintf(args, "%hu", list[i]);
			strcat(str, args);
		}
		cmd = command_format_json(type, "%s", str);
		free(str);
	}

	if (cmd == NULL)
		return -1;

	if (command_send(cmd, socket) != 0) {
		command_free(cmd);
		return -1;
	}

	return 0;
}
Esempio n. 6
0
File: hlib.c Progetto: cafiend/W12
/*
 * This is a general purpose way to call jquery from C.
 *
 * Just a front for $("#id").css("name", "value");
 */
int TextAreaSetCss(Display *display, const char *id, const char *name, const char *value)
{
	Command *cmd = NULL;
	Socket *socket = NULL;

	socket = display->socket;

	if (id == NULL)
		return -1;

	if (strlen(id) == 0 || strlen(name) == 0 || strlen(value) == 0)
		return 0;

	cmd = command_format_json("TXT_AREA_CSS", "\"%s\" \"%s\" \"%s\"", id, name, value);
	if (cmd == NULL)
		return -1;

	if (command_send(cmd, socket) != 0) {
		command_free(cmd);
		return -1;
	}

	return 0;

}
Esempio n. 7
0
File: hlib.c Progetto: cafiend/W12
int AppendTextArea(Display *display, const char *target, const char *text)
{
	Command *cmd = NULL;
    Socket *socket = NULL;
    
    socket = display->socket;
        
    if (target == NULL || text == NULL)
        return -1;
    
    if (strlen(target) == 0)
        return 0;
       
    if (strlen(text) == 0)
		return 0;
        
    cmd = command_format_json("APPEND", "\"%s\" \"%s\"", target, text);
    if (cmd == NULL)
        return -1;
    
    if (command_send(cmd, socket) != 0) {
        command_free(cmd);
        return -1;
    }
    
    return 0;
}
Esempio n. 8
0
File: hlib.c Progetto: cafiend/W12
/* TODO: remove this */
int SendText(Display *display, int x, int y, char *text)
{
    Command *cmd = NULL;
    Socket *socket = NULL;
    int textlen = 0;
    
    socket = display->socket;
        
    if (text == NULL)
        return -1;
    
    textlen = strlen(text);
    if (textlen == 0)
        return 0;
        
    //command_format("TXT %d %d %s", x, y, text);
    cmd = command_format_json("TXT", "\"%s\" %d %d", text, x, y);
    if (cmd == NULL)
        return -1;
    
    if (command_send(cmd, socket) != 0) {
        command_free(cmd);
        return -1;
    }
    
    return 0;
}
Esempio n. 9
0
/*****************************************************************************
	全アナログ設定
*****************************************************************************/
bool CGainer::SetAnalogAll(const std::vector<WORD> &data)
{
	int limit = CONFIG[m_config][AOUT];
	if ( ! limit ) {
		return false;
	}

	check_config();

	std::string c("A");
	char buf[32];

	size_t n = data.size();
	if ( n > limit ) {
		n = limit;
	}

	for ( size_t i = 0 ; i < n ; ++i ) {
		sprintf(buf,"%02X",data[i]);
		c += buf;
	}

	int diff = limit - n;
	while ( diff > 0 ) {
		c += "00";
		--diff;
	}
	c += "*";

	return command_send(c).size() != 0;
}
Esempio n. 10
0
bool CGainer::ScanLine(size_t row,BYTE data[GAINER_LED_MATRIX])
{
	check_config();

	if ( m_config != 7 ) { return false; }
	if ( row > GAINER_LED_MATRIX-1 ) { return false; }

	//最適化:前と同じなら実行しない
	if ( ScanLineCompare(data,m_LEDMatrixOutputs[row]) ) {
		return true;
	}

	std::string c = "a";
	size_t i;
	char buf[32];

	sprintf(buf,"%u",row);
	c += buf;

	for ( i = 0 ; i < GAINER_LED_MATRIX ; ++i ) {
		if ( data[i] > 15 ) {
			data[i] = 15;
		}
		sprintf(buf,"%01X",data[i]);
		c += buf;
	}
	c += "*";

	command_send(c,true);

	memcpy(m_LEDMatrixOutputs[row],data,sizeof(m_LEDMatrixOutputs[row]));

	return true;
}
Esempio n. 11
0
/*****************************************************************************
	再起動
*****************************************************************************/
void CGainer::Reboot(bool nowait)
{
	command_send("Q*",nowait);
	m_config = 0;
	if ( ! nowait ) {
		Sleep(100);
	}
}
Esempio n. 12
0
/*****************************************************************************
	初期化
*****************************************************************************/
bool CGainer::Init(int portNum, int mode)
{
	if ( m_inited ) {
		return true;
	}

	m_led = false;
	m_config = mode;
	m_port = portNum;
	m_endFlag = false;
	m_hwnd_sstp = NULL;

	m_analog_period = 0;
	m_analog_last = 0;
	m_digital_period = 0;
	m_digital_last = 0;

	ZeroMemory(m_LEDMatrixOutputs,sizeof(m_LEDMatrixOutputs));

	m_receive_buffer.assign(RECV_BUFFER,0);
	
	InitializeCriticalSection(&m_receive_queue_lock);
	
	m_receive_queue_semaphore = ::CreateSemaphore(NULL,0,9999,NULL);

	// COM port open
	if ( ! m_serial.Open(m_port, RECV_BUFFER, SEND_BUFFER) ) {
		return false;
	}
	// setting of COM port
	if ( ! m_serial.SetConfig(COMLIBFLAG_38400|COMLIBFLAG_NO|COMLIBFLAG_1|COMLIBFLAG_8|COMLIBFLAG_NO_FLOW_CONTROL) ) {
		m_serial.Close();
		return false;
	}

	// setting receiving timeout
	m_serial.SetTimeout(RECV_TIMEOUT_COMM, RECV_TIMEOUT_INTERVAL, SEND_TIMEOUT_COMM);

	// software reset
	Reboot(true);
	m_thread_handle = (HANDLE)_beginthreadex(NULL, 0, receiver, this, 0, NULL);
	wait_recv();

	// ver.
	m_version_string = command_send("?*");
	m_version_string.erase(0,1);
	m_version_string.erase(m_version_string.size()-1,1);

	// set configulation mode
	if ( m_config ) {
		SetConfiguration(m_config);
	}

	m_inited = true;
	g_gainer_open_ports.push_back(m_port);
	return true;
}
Esempio n. 13
0
File: hlib.c Progetto: cafiend/W12
/* This is partly controlled by the BUFSIZE (currently 128) in command.c and partly due to JSON overhead. */
int OverwriteTextArea(Display *display, const char *target, const char *text)
{
	Command *cmd = NULL;
    Socket *socket = NULL;
    int i,j,count, len;
    char *tmp;
    
    socket = display->socket;
        
    if (target == NULL || text == NULL || strchr(target, '\n') != NULL)
        return -1;
    
    if (strlen(target) == 0)
        return 0;

    len = strlen(text);

    if (len == 0)
		return 0;

    if (strchr(text, '\n') || strchr(text, '\r')) {
    	/* at least one newline to deal with */
    	count = 0;
    	j = 0;
    	for(i = 0; i < len; i++) {
    		if (text[i] == '\n' || text[i] == '\r') count++;
    	}
    	tmp = calloc(len+count, sizeof(char));
    	for(i = 0; i < len; i++) {
    		if (text[i] == '\n') {
    			tmp[j++]	= '\\';
    			tmp[j]		= 'n';
    		} else if (text[i] == '\r') {
    			tmp[j++]	= '\\';
    			tmp[j]		= 'r';
    		} else {
    			tmp[j]	= text[i];
    		}
    		j++;
    	}
    	cmd = command_format_json("OVERWRITE", "\"%s\" \"%s\"", target, tmp);
    	free(tmp);
    } else {
    	cmd = command_format_json("OVERWRITE", "\"%s\" \"%s\"", target, text);
    }

    if (cmd == NULL)
        return -1;
    
    if (command_send(cmd, socket) != 0) {
        command_free(cmd);
        return -1;
    }
    
    return 0;
}
Esempio n. 14
0
void CGainer::ExecuteContinuousAnalog(DWORD period)
{
	check_config();

	if ( ! CONFIG[m_config][AIN] ) {
		return;
	}

	m_analog_period = period;
	command_send("i*",true);
}
Esempio n. 15
0
/*****************************************************************************
	Continuous系
*****************************************************************************/
void CGainer::ExecuteContinuousDigital(DWORD period)
{
	check_config();

	if ( ! CONFIG[m_config][DIN] ) {
		return;
	}

	m_digital_period = period;
	command_send("r*",true);
}
Esempio n. 16
0
/*****************************************************************************
	単独サーボ設定
*****************************************************************************/
bool CGainer::SetServoSingle(int port,BYTE value)
{
	check_config();

	int limit = 8;
	if ( m_config != 8 ) { return false; }

	char buf[64];
	sprintf(buf,"p%d%02X*",port,value);
	return command_send(buf).size() != 0;
}
Esempio n. 17
0
/*****************************************************************************
	全デジタル設定
*****************************************************************************/
bool CGainer::SetDigitalAll(int value)
{
	if ( ! CONFIG[m_config][DOUT] ) {
		return false;
	}

	check_config();

	char c[32];
	sprintf(c,"D%04X*",value);
	return command_send(c).size() != 0;
}
Esempio n. 18
0
/*****************************************************************************
	単独アナログ設定
*****************************************************************************/
bool CGainer::SetAnalogSingle(int port,BYTE value)
{
	if ( ! CONFIG[m_config][AOUT] ) {
		return false;
	}

	check_config();

	char buf[64];
	sprintf(buf,"a%d%02X*",port,value);
	return command_send(buf).size() != 0;
}
Esempio n. 19
0
/*****************************************************************************
	全デジタル取得
*****************************************************************************/
bool CGainer::GetDigitalAll(WORD &result,size_t &bits)
{
	check_config();

	if ( ! CONFIG[m_config][DIN] ) {
		return false;
	}

	std::string r = command_send("R*");
	result = m_digitalInputs;
	bits = CONFIG[m_config][DIN];
	return r.size() != 0;
}
Esempio n. 20
0
int main()
{
	char *cp, lbuf[BUFSIZE];

	while (fgets(lbuf, BUFSIZE, stdin) != NULL) {
		if ((cp = strchr(lbuf, '\n')) != NULL)
			*cp = '\0';

		command_send(lbuf);
	}

	return 0;
}
Esempio n. 21
0
/**@brief Process ANT message on ANT scanner
 *
 * @param[in] p_ant_event ANT message content.
 */
void continuous_scan_event_handler(ant_evt_t * p_ant_evt)
{
    uint32_t err_code;
    uint8_t  message_rssi;
    uint16_t message_device_number;

    ANT_MESSAGE * p_ant_message = (ANT_MESSAGE *) p_ant_evt->msg.evt_buffer;

    switch (p_ant_evt->event)
    {
        case EVENT_RX:
            if (p_ant_message->ANT_MESSAGE_aucPayload[0] == DEVICE_STATUS_PAGE)
            {
                LEDS_INVERT(BSP_LED_1_MASK);
                if (p_ant_message->ANT_MESSAGE_stExtMesgBF.bANTDeviceID &&
                    p_ant_message->ANT_MESSAGE_stExtMesgBF.bANTRssi)
                {
                    message_device_number =
                        (uint16_t)(p_ant_message->ANT_MESSAGE_aucExtData[0] |
                                   ((uint16_t)p_ant_message->ANT_MESSAGE_aucExtData[1] << 8));
                    message_rssi = p_ant_message->ANT_MESSAGE_aucExtData[5];
                    node_to_list_add(message_device_number, message_rssi);
                }
            }
            break;

        case EVENT_TRANSFER_TX_COMPLETED:
            LEDS_OFF(BSP_LED_0_MASK | BSP_LED_1_MASK);
            err_code = sd_ant_channel_close(ANT_SCAN_CHANNEL_NUMBER);
            APP_ERROR_CHECK(err_code);
            break;

        case EVENT_TRANSFER_TX_FAILED:
            if (m_retries > 0)
            {
                command_send();
                m_retries--;
            }
            else
            {
                LEDS_OFF(BSP_LED_0_MASK | BSP_LED_1_MASK);
                err_code = sd_ant_channel_close(ANT_SCAN_CHANNEL_NUMBER);
                APP_ERROR_CHECK(err_code);
            }
            break;

        default:
            break; // No implementation needed
    }
}
Esempio n. 22
0
/*****************************************************************************
	全アナログ取得
*****************************************************************************/
bool CGainer::GetAnalogAll(std::vector<BYTE> &result)
{
	check_config();

	if ( ! CONFIG[m_config][AIN] ) {
		return false;
	}

	std::string r = command_send("I*");
	size_t n = CONFIG[m_config][AIN];
	for ( size_t i = 0 ; i < n ; ++i ) {
		result.push_back(m_analogInputs[i]);
	}
	return r.size() != 0 && result.size() != 0;
}
Esempio n. 23
0
File: hlib.c Progetto: cafiend/W12
/* ie that sets the listeners to return false */
int DisableKeyList(Display *display, EventType etype, char* list)
{
	Command *cmd = NULL;
	Socket *socket = NULL;
	int i,size;
	char *str, args[10];
	char *name;

	if (etype == KeyPressed)
		name = strdup("CB_KEY_P_STOP");
	else if (etype == KeyTyped)
		name = strdup("CB_KEY_T_STOP");
	else
		return -2;

	socket = display->socket;

	if (list == NULL) {
		cmd = command_format_json(name, "\"%s\"", "NONE");
	} else if (strcmp(list, "ALL") == 0 ) {
		cmd = command_format_json(name, "\"%s\"", "ALL");
	} else {
		size = strlen(list);
		str = calloc(size*5, sizeof(char));
		for (i = 0; i < size; i ++) {
			if (i != size -1) sprintf(args, "%hu,", list[i]);
			else sprintf(args, "%hu", list[i]);
			strcat(str, args);
		}
		cmd = command_format_json(name, "%s", str);
		free(str);
	}
	free(name);

	if (cmd == NULL)
		return -1;

	if (command_send(cmd, socket) != 0) {
		command_free(cmd);
		return -3;
	}

	return 0;


}
Esempio n. 24
0
File: hlib.c Progetto: cafiend/W12
/* This could actually add inline <style> tags too and we could have two methods for adding fonts */
int CreateFont(Display *display, const char *fontName, const char *fontURL) {
	Command *cmd = NULL;
    Socket *socket = NULL;
    
    socket = display->socket;
    
    cmd = command_format_json("PRELOAD", "\"%s\" \"%s\"",  fontName, fontURL);
    if (cmd == NULL)
        return -1;
        
    if (command_send(cmd, socket) != 0) {
        command_free(cmd);
        return -1;
    }
    
    return 0;
}
Esempio n. 25
0
/*****************************************************************************
	単独デジタル設定
*****************************************************************************/
bool CGainer::SetDigitalSingle(int port,bool high)
{
	if ( ! CONFIG[m_config][DOUT] ) {
		return false;
	}

	check_config();

	char buf[32];
	if ( high ) {
		sprintf(buf,"H%d*",port);
	}
	else {
		sprintf(buf,"L%d*",port);
	}
	return command_send(buf).size() != 0;
}
Esempio n. 26
0
File: hlib.c Progetto: cafiend/W12
int Rotate(Display *display, float angle) {
	Command *cmd = NULL;
    Socket *socket = NULL;
    
    socket = display->socket;
    
    /* cmd = command_format("ROTATE %f", angle); */
    cmd = command_format_json("ROTATE", "%f", angle);
    if (cmd == NULL)
        return -1;
        
    if (command_send(cmd, socket) != 0) {
        command_free(cmd);
        return -1;
    }
    
    return 0;
}
Esempio n. 27
0
File: hlib.c Progetto: cafiend/W12
int Vertex2D(Display *display, int x, int y) {
	Command *cmd = NULL;
    Socket *socket = NULL;
    
    socket = display->socket;
    
    /* cmd = command_format("VERTEX %d %d", x, y); */
    cmd = command_format_json("VERTEX", "%d %d", x, y);
    if (cmd == NULL)
        return -1;
        
    if (command_send(cmd, socket) != 0) {
        command_free(cmd);
        return -1;
    }
    
    return 0;
}
Esempio n. 28
0
File: hlib.c Progetto: cafiend/W12
int LoadFont(Display *display, const char *fontName, int size) {
	Command *cmd = NULL;
    Socket *socket = NULL;
    
    socket = display->socket;
    
    /* cmd = command_format("LOAD_FONT %d '%s'", size, fontName); */
    cmd = command_format_json("LOAD_FONT", "\"%s\" %d",  fontName, size);
    if (cmd == NULL)
        return -1;
        
    if (command_send(cmd, socket) != 0) {
        command_free(cmd);
        return -1;
    }
    
    return 0;
}
Esempio n. 29
0
File: hlib.c Progetto: cafiend/W12
int PopMatrix(Display *display) {
	Command *cmd = NULL;
    Socket *socket = NULL;
    
    socket = display->socket;
    
    /* cmd = command_format("POP_MAT"); */
    cmd = command_format_json("POP_MAT", "");
    if (cmd == NULL)
        return -1;
        
    if (command_send(cmd, socket) != 0) {
        command_free(cmd);
        return -1;
    }
    
    return 0;
}
Esempio n. 30
0
File: hlib.c Progetto: cafiend/W12
int Translate2f(Display *display, float x, float y) {
	Command *cmd = NULL;
    Socket *socket = NULL;
    
    socket = display->socket;
    
    /* cmd = command_format("TRANSL_2f %f %f", x, y); */
    cmd = command_format_json("TRANSL_2f", "%f %f", x, y);
    if (cmd == NULL)
        return -1;
        
    if (command_send(cmd, socket) != 0) {
        command_free(cmd);
        return -1;
    }
    
    return 0;
}