18 #include "../hubolib.h"
19 #include "../hubocfg.h"
39 #define FAMILY_CODE (31)
40 #define TEMP_CONTROLLER_SOCKET (1)
41 #define REED_CONTACT_SOCKET (2)
58 #define TEMP_ON (25.0)
59 #define TEMP_OFF (27.0)
64 #define PIR_DI_CHANNEL (7) // channel 7 is connected to the PIR.
65 #define SLAVE_INDEX (0) // We use the first slave (index 0) found.
69 #define REED_DI_CHANNEL (6) // channel 6 is connected to the reed contact closure.
70 #define MOTOR_DO_CHANNEL (1) // the motor is connected on (open collector) output channel 1
73 int main(
int argc,
char *argv[])
78 printf (
"Failed to initialize. Are you running the program as sudoer?\n");
105 bool bReedContactOpen =
true;
106 static bool bLastReedContactOpen =
true;
110 printf (
"Failed to retrieve DI channel.\n");
114 if (bLastReedContactOpen != bReedContactOpen)
115 printf (
"Set DO channel %d to %s.\n",
MOTOR_DO_CHANNEL, bReedContactOpen ?
"0" :
"1");
117 bLastReedContactOpen = bReedContactOpen;
122 static bool lastPirState =
false;
123 bool newPirState =
false;
127 printf (
"Failed to retrieve digital input.\n");
130 if (lastPirState==
false && newPirState==
true)
133 printf (
"PIR signal %d caught.\n",
g_Count);
136 lastPirState = newPirState;
141 double temperature = 0.0;
145 printf (
"Temperature = %lf deg. C ", temperature);
152 printf (
"-> heating on.\n");
159 printf (
"-> heating off.\n");
163 printf (
"-> no change.\n");
180 long t_duration_ms = 0;
189 if (temperature == 85.0)
193 if (t_duration_ms > 2000)
204 printf (
"Failed to save scheduling parameter. Are you running the program as sudoer?\n");
209 printf (
"Initializing GPIO.\n");
212 printf (
"GPIO not properly initialized. Are you running the program as sudoer?\n");
219 printf (
"A 1wire sensor could not be found.\n");
226 printf (
"Hubo hardware containing at least one cascaded slave could not be found.\n");
240 printf (
"Initializing Hubo hardware and detecting slaves.\n");
262 printf (
"Waiting for MCP3x08 buffered values... ");
264 printf (
"received.\n");
266 printf (
"Waiting for MCP23017 buffered values... ");
268 printf (
"received.\n");
270 printf (
"Waiting for MCP23017 (slaves) buffered values... ");
272 printf (
"received.\n");
279 printf (
"Initializing 1wire devices.\n");
302 printf (
"Result=%s ", bResult?
"true":
"false");
303 printf (
"bCRC=%s ", bCRC?
"true":
"false");
304 printf (
"temp=%lf duration=%ld index=%d\n", temperature, t_duration_ms, i);
317 printf (
"Saving thread parameters.\n");
335 param.sched_priority = sched_get_priority_max(SCHED_FIFO);
336 int ret = pthread_setschedparam(
g_threadHandle, SCHED_FIFO, ¶m);
350 if (sscanf(str,
"%lu", &v) != 1)
352 value = (
unsigned char)v;
353 if (value != (
unsigned long)v)
const char * m_sI2CDevice
bool Wait_For_MCP3x08_Buffered_Values()
Waits until the input buffer of the MCP3x08 are initialized from the hardware.
bool strToUChar(char *str, unsigned char &value)
void Delay_MicroSeconds(unsigned long delay_micros)
delays the execution of the calling thread for the given number of micro seconds. ...
#define MAX_MCP3x08_CHANNELS
bool IsGPIOInitialized()
Returns the status of the initialisation of the GPIO part of the library.
int main(int argc, char *argv[])
bool Set_DO_Channel(int channel, bool bValue)
Requests the background thread to set one of the digital outputs to the value specified.
bool Initialize()
Initializes the library.
bool InitializeHuboHardware()
bool SaveThreadPriority()
#define TEMP_CONTROLLER_SOCKET
bool Is_DS18x20_Devices(const char *pSensorID)
Check whether a 1wire device name refers to a DS18S20 or DS18B20 temperature sensor.
bool Set_Cycle_Time(long cycleTime)
Sets the backgrounds threads polling interval in ms.
bool InitializeApplication()
vector< string > g_1WireDeviceList
bool Wait_For_MCP23017_Slaves_Buffered_Values()
Waits until input and output buffers of the MCP23017 slaves are initialized from the hardware...
bool GetTemperature(double &temperature)
void Uninitialize()
Releases any resources bound to the library.
bool Get_DS18x20_Temperature(const char *pSensorID, double &temperature, bool &bCRC, long &t_duration_ms)
Retrieve temperature, CRC value and the time that was required to read the temperature.
vector< int > g_SlaveAddressList
bool Initialize1WireDevices()
bool Get_1w_Devices(std::vector< std::string > &deviceList)
Returns a list of 1wire devices found on the bus.
void RestoreThreadPriority()
bool Set_Slave_DO_Channels(int slaveNo, unsigned char value)
Requests the background thread to update all 8 bits of the digital output to the value specified for ...
bool Wait_For_MCP23017_Buffered_Values()
Waits until input and output buffers of the MCP23017 master are initialized from the hardware...
void BoostThreadPriority()
CSC5262 rcSwitch(350, 17, true)
bool GetSlaveDeviceList(std::vector< int > &slaveAddressList)
Returns the list of I2C addresses of the MCP23017 slaves.
bool SwitchSocket(unsigned char SystemCode, unsigned char Receiver, bool bTurnOn, int repeatedSuccess, int totalTransmittion)
void TemperatureControl()