-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial Version of AStarBox Initial version of AStarBox as a 3rd-party driver. * New version of AStarBox.cpp New version detects if there is a problem or not with the I2C connection. Also, changed the names to be consistent with Rodolphe's files. (AStarBox vs CAStarBox), and changed astarbox to indi-astarbox. * Update README Update to improve format. * Update README.md Again change format. * Another update Formatting again * And again Another format change. * Hopefully final update of README I hope I have this right now! * Readme Getting name right in Readme * Refactor of AStarBox.cpp Called openAllPorts into connect so can use results to indicate whether connection successful or not. Moved getPortPWM for ports 5 and 6 into connect too - when in openAllPports m_bLinked was false at that point so no values collected. Now called after m_bLlinked is true so that values are collected. * Merged Rodolphe's updates and mine Merged Rodolphe's updates and mine. m_bPortsOpen is tested before opening all ports, but getting PWM5 and 6 is now in connect. * Tidied up port numbers Replaced 5 and 6 by their ENUMS instead for consistency. * Changed logic when PWM percent is zero Previously, setting PWM to zero turned the port off. However, this prevented the status from being read so that if changed elsewhere, it would not be picked up. Now, the ports are left on though with power of zero (same as turned off from a physical perspective). Also, tidied up the return codes from setPortPWMDutyCyclePercent since this returns an integer rather than a bool,
- Loading branch information
Showing
15 changed files
with
2,700 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#pragma once | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <string.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
|
||
// C++ includes | ||
#include <string> | ||
#include <vector> | ||
#include <sstream> | ||
#include <iostream> | ||
#include <iomanip> | ||
#include <fstream> | ||
#include <chrono> | ||
#include <thread> | ||
#include <ctime> | ||
#include <cmath> | ||
|
||
#include "mcp3421.h" | ||
#include "PCA9685.h" | ||
#include "StopWatch.h" | ||
|
||
#define NB_PORTS 6 | ||
#define ON true | ||
#define OFF false | ||
|
||
#define PORT_1 0 | ||
#define PORT_2 1 | ||
#define PORT_3 2 | ||
#define PORT_4 3 | ||
#define PORT_PWM1 4 | ||
#define PORT_PWM2 5 | ||
|
||
#define POWER_1 1 | ||
#define POWER_2 2 | ||
#define POWER_3 3 | ||
#define POWER_4 4 | ||
#define PWM_1 5 | ||
#define PWM_2 6 | ||
|
||
|
||
enum portErrors {PLUGIN_OK, P_ERROR, P_UKNOWN, P_INVALID}; | ||
enum methodErrors {OK, PORT_OPEN_ERROR, ERR_PARSE, ERR_FILE}; | ||
|
||
// #define PLUGIN_DEBUG 3 | ||
#define PLUGIN_VERSION 1.01 | ||
|
||
#define INTER_COMMAND_WAIT_MS 500 // ms | ||
|
||
class CAStarBoxPowerPorts | ||
{ | ||
public: | ||
CAStarBoxPowerPorts(); | ||
~CAStarBoxPowerPorts(); | ||
|
||
|
||
virtual int connect(); | ||
virtual void disconnect(); | ||
|
||
virtual int openAllPorts(); | ||
virtual int getPortCount(); | ||
virtual int setPort(const int nPortID, const bool bOn); | ||
virtual int getPortStatus(const int nPortID, bool &bOn); | ||
|
||
virtual int setPortPWMDutyCyclePercent(const int nPortID, const int nDutyCiclePercent); | ||
virtual int getPortPWMDutyCyclePercent(const int nPortID, int &nDutyCiclePercent); | ||
|
||
virtual int loadBootStates(std::vector<int> &states); | ||
virtual int saveBootStates(std::vector<int> &states); | ||
|
||
virtual bool isMCP3421Present(); | ||
virtual int openMCP3421(); | ||
virtual int closeMCP3421(); | ||
virtual double getVoltage(); | ||
|
||
private: | ||
int setPortPWM(const int nPortID, const int nDutyCycle); | ||
int getPortPWM(const int nPortID, int &nDutyCycle); | ||
void cmdWait(); | ||
int parseFields(const std::string sResp, std::vector<std::string> &svFields, char cSeparator); | ||
std::string& trim(std::string &str, const std::string &filter ); | ||
std::string& ltrim(std::string &str, const std::string &filter); | ||
std::string& rtrim(std::string &str, const std::string &filter); | ||
|
||
CStopWatch pcaCommandTimer; | ||
bool m_bLinked; | ||
|
||
bool m_bPortsOpen; | ||
// pwm ports | ||
bool m_bPwm1On; | ||
int m_nPwm1DutyCycle; | ||
|
||
bool m_bPwm2On; | ||
int m_nPwm2DutyCycle; | ||
|
||
PCA9685 m_PortController; | ||
mcp3421 m_mcp3421; | ||
bool m_mcp3421Present; | ||
|
||
#ifdef PLUGIN_DEBUG | ||
// timestamp for logs | ||
const std::string getTimeStamp(); | ||
std::ofstream m_sLogFile; | ||
std::string m_sLogfilePath; | ||
#endif | ||
|
||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Colin McGill and Rodolphe Pineau ([email protected]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
PROJECT(indi-astarbox CXX C) | ||
|
||
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/") | ||
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake_modules/") | ||
include(GNUInstallDirs) | ||
|
||
set (VERSION_MAJOR 1) | ||
set (VERSION_MINOR 0) | ||
|
||
find_package(INDI REQUIRED) | ||
find_package(Threads REQUIRED) | ||
find_package(RT REQUIRED) | ||
|
||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) | ||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/indi_astarbox.xml.cmake ${CMAKE_CURRENT_BINARY_DIR}/indi_astarbox.xml) | ||
|
||
include_directories(${CMAKE_CURRENT_BINARY_DIR}) | ||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}) | ||
include_directories(${INDI_INCLUDE_DIR}) | ||
|
||
include(CMakeCommon) | ||
|
||
################ ASI Power ################ | ||
set(indi_astarbox_SRCS | ||
${CMAKE_CURRENT_SOURCE_DIR}/indi-astarbox.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/AStarBox.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/mcp3421.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/PCA9685.cpp | ||
) | ||
|
||
IF (UNITY_BUILD) | ||
ENABLE_UNITY_BUILD(indi_astarbox indi_astarbox_SRCS 6 cpp) | ||
ENDIF () | ||
|
||
add_compile_options(-Wall) | ||
|
||
add_executable(indi_astarbox ${indi_astarbox_SRCS}) | ||
target_link_libraries(indi_astarbox ${INDI_LIBRARIES}) | ||
|
||
# Install indi_astarbox | ||
install(TARGETS indi_astarbox RUNTIME DESTINATION bin ) | ||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/indi_astarbox.xml DESTINATION ${INDI_DATA_DIR}) |
Oops, something went wrong.