some more

This commit is contained in:
2025-01-30 22:14:10 +03:00
parent 5441a87fff
commit 31c885ba02
8 changed files with 224 additions and 62 deletions

View File

@@ -24,33 +24,6 @@
conf_t Conf = {0};
/**
* @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;
if(!Conf.EncoderPath || Conf.EncoderSpeed < 1200){
DBG("Define encoder device path and speed");
return MCC_E_BADFORMAT;
}
if(!Conf.MountPath || Conf.MountSpeed < 1200){
DBG("Define mount device path and speed");
return MCC_E_BADFORMAT;
}
if(!openEncoder(Conf.EncoderPath, Conf.EncoderSpeed)){
DBG("Can't open %s with speed %d", Conf.EncoderPath, Conf.EncoderSpeed);
return MCC_E_ENCODERDEV;
}
if(!openMount(Conf.MountPath, Conf.MountSpeed)){
DBG("Can't open %s with speed %d", Conf.MountPath, Conf.MountSpeed);
return MCC_E_MOUNTDEV;
}
return MCC_E_OK;
}
/**
* @brief quit - close all opened and return to default state
*/
@@ -60,9 +33,38 @@ static void quit(){
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,
.getEnc = getEnc
.getMountData = getMD
};