DSRemote/connection.cpp

111 wiersze
1.8 KiB
C++
Czysty Zwykły widok Historia

2015-06-27 09:04:41 +00:00
/*
***************************************************************************
*
* Author: Teunis van Beelen
*
2023-02-08 20:22:28 +00:00
* Copyright (C) 2015 - 2023 Teunis van Beelen
2015-06-27 09:04:41 +00:00
*
2019-05-28 06:36:25 +00:00
* Email: teuniz@protonmail.com
2015-06-27 09:04:41 +00:00
*
***************************************************************************
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
***************************************************************************
*/
#include "connection.h"
2015-06-27 14:42:01 +00:00
2015-06-27 09:04:41 +00:00
int tmc_connection_type;
2015-06-27 14:42:01 +00:00
struct tmcdev *tmc_device;
2015-06-27 09:04:41 +00:00
struct tmcdev * tmc_open_usb(const char *device)
{
tmc_connection_type = 0;
2015-06-27 14:42:01 +00:00
tmc_device = tmcdev_open(device);
2015-06-27 09:04:41 +00:00
2015-06-27 14:42:01 +00:00
return tmc_device;
2015-06-27 09:04:41 +00:00
}
2015-06-28 09:30:25 +00:00
struct tmcdev * tmc_open_lan(const char *address)
{
tmc_connection_type = 1;
tmc_device = tmclan_open(address);
return tmc_device;
}
2015-06-27 09:04:41 +00:00
void tmc_close(void)
{
if(tmc_connection_type == 0)
{
2015-06-27 14:42:01 +00:00
tmcdev_close(tmc_device);
}
else
{
2015-06-28 09:30:25 +00:00
tmclan_close(tmc_device);
2015-06-27 09:04:41 +00:00
}
2015-06-28 09:30:25 +00:00
tmc_device = NULL;
2015-06-27 09:04:41 +00:00
}
2015-06-27 14:42:01 +00:00
int tmc_write(const char *cmd)
2015-06-27 09:04:41 +00:00
{
if(tmc_connection_type == 0)
{
2015-06-27 14:42:01 +00:00
return tmcdev_write(tmc_device, cmd);
}
else
{
2015-06-28 09:30:25 +00:00
return tmclan_write(tmc_device, cmd);
2015-06-27 09:04:41 +00:00
}
return -1;
}
int tmc_read(void)
{
if(tmc_connection_type == 0)
{
2015-06-27 14:42:01 +00:00
return tmcdev_read(tmc_device);
}
else
{
2015-06-28 09:30:25 +00:00
return tmclan_read(tmc_device);
2015-06-27 09:04:41 +00:00
}
return -1;
}
2015-06-27 14:42:01 +00:00
2015-06-27 09:04:41 +00:00