2025-01-30 22:14:10 +03:00

71 lines
2.1 KiB
C

/*
* This file is part of the libsidservo project.
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
*
* 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 <stdio.h>
#include <stdlib.h>
#include "dbg.h"
#include "serial.h"
conf_t Conf = {0};
/**
* @brief quit - close all opened and return to default state
*/
static void quit(){
DBG("Close serial devices");
closeSerial();
DBG("Exit");
}
/**
* @brief init - open serial devices and do other job
* @param c - initial configuration
* @return error code
*/
static mcc_errcodes_t init(conf_t *c){
if(!c) return MCC_E_BADFORMAT;
Conf = *c;
mcc_errcodes_t ret = MCC_E_OK;
if(!Conf.MountPath || Conf.MountSpeed < 1200){
DBG("Define mount device path and speed");
ret = MCC_E_BADFORMAT;
}else if(!openMount(Conf.MountPath, Conf.MountSpeed)){
DBG("Can't open %s with speed %d", Conf.MountPath, Conf.MountSpeed);
ret = MCC_E_MOUNTDEV;
}
if(Conf.SepEncoder){
if(!Conf.EncoderPath || Conf.EncoderSpeed < 1200){
DBG("Define encoder device path and speed");
ret = MCC_E_BADFORMAT;
}else if(!openEncoder(Conf.EncoderPath, Conf.EncoderSpeed)){
DBG("Can't open %s with speed %d", Conf.EncoderPath, Conf.EncoderSpeed);
ret = MCC_E_ENCODERDEV;
}
}
if(ret != MCC_E_OK) quit();
return ret;
}
// init mount class
mount_t Mount = {
.init = init,
.quit = quit,
.getMountData = getMD
};