--- a/Makefile Fri Nov 25 14:23:22 2016 +0000
+++ b/Makefile Wed Dec 14 15:51:59 2016 +0000
@@ -2,10 +2,18 @@
CFLAGS=-g -O0 -Wall -I../
LIBS= -lphidget21 -lpthread -ldl
+all: pbmd
+
dctest: dutycycle.c dutycycle.h
gcc -o dctest -DUNITTEST -g dutycycle.c
-all: pbmd
+ker-on: ker-on.c
+ gcc -o ker-on -DUNITTEST -g ker-on.c $(LIBS)
+
+ker-off: ker-on.c
+ gcc -o ker-off -DUNITTEST -g ker-off.c $(LIBS)
+
+
stateManager.o : handlers.h
pbmd.o : stateManager.h
@@ -17,4 +25,4 @@
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
clean:
- -rm -f *.o pbmd dctest
+ -rm -f *.o pbmd dctest ker-on
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ker-off.c Wed Dec 14 15:51:59 2016 +0000
@@ -0,0 +1,182 @@
+// - InterfaceKit simple -
+// This simple example simply creates an InterfaceKit handle, hooks the event handlers and opens it. It then waits
+// for an InterfaceKit to be attached and waits for events to be fired. We progress through three steps, 1. Normal settings,
+// 2. Setting analog sensor sensitivity to 100, 3. Toggling Ratiometric, waiting for user input to proceed to next step to allow
+// data to be read.
+//
+// Copyright 2008 Phidgets Inc. All rights reserved.
+// This work is licensed under the Creative Commons Attribution 2.5 Canada License.
+// view a copy of this license, visit http://creativecommons.org/licenses/by/2.5/ca/
+
+#include <stdio.h>
+#include <phidget21.h>
+
+int CCONV AttachHandler(CPhidgetHandle IFK, void *userptr)
+{
+ int serialNo;
+ const char *name;
+
+ CPhidget_getDeviceName(IFK, &name);
+ CPhidget_getSerialNumber(IFK, &serialNo);
+
+ printf("%s %10d attached!\n", name, serialNo);
+
+ return 0;
+}
+
+int CCONV DetachHandler(CPhidgetHandle IFK, void *userptr)
+{
+ int serialNo;
+ const char *name;
+
+ CPhidget_getDeviceName (IFK, &name);
+ CPhidget_getSerialNumber(IFK, &serialNo);
+
+ printf("%s %10d detached!\n", name, serialNo);
+
+ return 0;
+}
+
+int CCONV ErrorHandler(CPhidgetHandle IFK, void *userptr, int ErrorCode, const char *unknown)
+{
+ printf("Error handled. %d - %s", ErrorCode, unknown);
+ return 0;
+}
+
+//callback that will run if an input changes.
+//Index - Index of the input that generated the event, State - boolean (0 or 1) representing the input state (on or off)
+int CCONV InputChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int Index, int State)
+{
+ printf("Digital Input: %d > State: %d\n", Index, State);
+ return 0;
+}
+
+//callback that will run if an output changes.
+//Index - Index of the output that generated the event, State - boolean (0 or 1) representing the output state (on or off)
+int CCONV OutputChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int Index, int State)
+{
+ printf("Digital Output: %d > State: %d\n", Index, State);
+ return 0;
+}
+
+//callback that will run if the sensor value changes by more than the OnSensorChange trigger.
+//Index - Index of the sensor that generated the event, Value - the sensor read value
+int CCONV SensorChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int Index, int Value)
+{
+ printf("Sensor: %d > Value: %d\n", Index, Value);
+ return 0;
+}
+
+//Display the properties of the attached phidget to the screen. We will be displaying the name, serial number and version of the attached device.
+//Will also display the number of inputs, outputs, and analog inputs on the interface kit as well as the state of the ratiometric flag
+//and the current analog sensor sensitivity.
+int display_properties(CPhidgetInterfaceKitHandle phid)
+{
+ int serialNo, version, numInputs, numOutputs, numSensors, triggerVal, ratiometric, i;
+ const char* ptr;
+
+ CPhidget_getDeviceType((CPhidgetHandle)phid, &ptr);
+ CPhidget_getSerialNumber((CPhidgetHandle)phid, &serialNo);
+ CPhidget_getDeviceVersion((CPhidgetHandle)phid, &version);
+
+ CPhidgetInterfaceKit_getInputCount(phid, &numInputs);
+ CPhidgetInterfaceKit_getOutputCount(phid, &numOutputs);
+ CPhidgetInterfaceKit_getSensorCount(phid, &numSensors);
+ CPhidgetInterfaceKit_getRatiometric(phid, &ratiometric);
+
+ printf("%s\n", ptr);
+ printf("Serial Number: %10d\nVersion: %8d\n", serialNo, version);
+ printf("# Digital Inputs: %d\n# Digital Outputs: %d\n", numInputs, numOutputs);
+ printf("# Sensors: %d\n", numSensors);
+ printf("Ratiometric: %d\n", ratiometric);
+
+ for(i = 0; i < numSensors; i++)
+ {
+ CPhidgetInterfaceKit_getSensorChangeTrigger (phid, i, &triggerVal);
+
+ printf("Sensor#: %d > Sensitivity Trigger: %d\n", i, triggerVal);
+ }
+
+ return 0;
+}
+
+
+int interfacekit_simple()
+{
+ int result, numSensors, i;
+ const char *err;
+
+ //Declare an InterfaceKit handle
+ CPhidgetInterfaceKitHandle ifKit = 0;
+
+ //create the InterfaceKit object
+ CPhidgetInterfaceKit_create(&ifKit);
+
+ //Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
+ // CPhidget_set_OnAttach_Handler((CPhidgetHandle)ifKit, AttachHandler, NULL);
+ // CPhidget_set_OnDetach_Handler((CPhidgetHandle)ifKit, DetachHandler, NULL);
+ // CPhidget_set_OnError_Handler((CPhidgetHandle)ifKit, ErrorHandler, NULL);
+
+ //Registers a callback that will run if an output changes.
+ //Requires the handle for the Phidget, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
+ // CPhidgetInterfaceKit_set_OnOutputChange_Handler (ifKit, OutputChangeHandler, NULL);
+
+ //open the interfacekit for device connections
+ CPhidget_open((CPhidgetHandle)ifKit, -1);
+
+ //get the program to wait for an interface kit device to be attached
+ printf("Waiting for interface kit to be attached....");
+ if((result = CPhidget_waitForAttachment((CPhidgetHandle)ifKit, 10000)))
+ {
+ CPhidget_getErrorDescription(result, &err);
+ printf("Problem waiting for attachment: %s\n", err);
+ return 0;
+ }
+
+ //Display the properties of the attached interface kit device
+ // display_properties(ifKit);
+
+ //read interface kit event data
+ // printf("Reading.....\n");
+
+ //keep displaying interface kit data until user input is read
+ // printf("Press any key to go to next step\n");
+ // getchar();
+
+ int rv=-1;
+ int foo=-1;
+ int bar=-1;
+ int baz=-1;
+ printf("\n");
+
+ rv=CPhidgetInterfaceKit_getOutputState(ifKit,0,&foo);
+ printf("read = %d, rv=%d \n",foo,rv);
+
+ rv=CPhidgetInterfaceKit_setOutputState(ifKit,0,0);
+ printf("set to zero, rv=%d \n",rv);
+
+ rv=CPhidgetInterfaceKit_getOutputState(ifKit,0,&bar);
+ printf("read = %d, rv=%d \n",bar,rv);
+
+ rv=CPhidgetInterfaceKit_setOutputState(ifKit,0,0);
+ printf("set to zero, rv=%d \n",rv);
+
+ rv=CPhidgetInterfaceKit_getOutputState(ifKit,0,&baz);
+ printf("read = %d, rv=%d \n",baz,rv);
+
+
+ //since user input has been read, this is a signal to terminate the program so we will close the phidget and delete the object we created
+ printf("Closing...\n");
+ CPhidget_close((CPhidgetHandle)ifKit);
+ CPhidget_delete((CPhidgetHandle)ifKit);
+
+ //all done, exit
+ return 0;
+}
+
+int main(int argc, char* argv[])
+{
+ interfacekit_simple();
+ return 0;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ker-on.c Wed Dec 14 15:51:59 2016 +0000
@@ -0,0 +1,182 @@
+// - InterfaceKit simple -
+// This simple example simply creates an InterfaceKit handle, hooks the event handlers and opens it. It then waits
+// for an InterfaceKit to be attached and waits for events to be fired. We progress through three steps, 1. Normal settings,
+// 2. Setting analog sensor sensitivity to 100, 3. Toggling Ratiometric, waiting for user input to proceed to next step to allow
+// data to be read.
+//
+// Copyright 2008 Phidgets Inc. All rights reserved.
+// This work is licensed under the Creative Commons Attribution 2.5 Canada License.
+// view a copy of this license, visit http://creativecommons.org/licenses/by/2.5/ca/
+
+#include <stdio.h>
+#include <phidget21.h>
+
+int CCONV AttachHandler(CPhidgetHandle IFK, void *userptr)
+{
+ int serialNo;
+ const char *name;
+
+ CPhidget_getDeviceName(IFK, &name);
+ CPhidget_getSerialNumber(IFK, &serialNo);
+
+ printf("%s %10d attached!\n", name, serialNo);
+
+ return 0;
+}
+
+int CCONV DetachHandler(CPhidgetHandle IFK, void *userptr)
+{
+ int serialNo;
+ const char *name;
+
+ CPhidget_getDeviceName (IFK, &name);
+ CPhidget_getSerialNumber(IFK, &serialNo);
+
+ printf("%s %10d detached!\n", name, serialNo);
+
+ return 0;
+}
+
+int CCONV ErrorHandler(CPhidgetHandle IFK, void *userptr, int ErrorCode, const char *unknown)
+{
+ printf("Error handled. %d - %s", ErrorCode, unknown);
+ return 0;
+}
+
+//callback that will run if an input changes.
+//Index - Index of the input that generated the event, State - boolean (0 or 1) representing the input state (on or off)
+int CCONV InputChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int Index, int State)
+{
+ printf("Digital Input: %d > State: %d\n", Index, State);
+ return 0;
+}
+
+//callback that will run if an output changes.
+//Index - Index of the output that generated the event, State - boolean (0 or 1) representing the output state (on or off)
+int CCONV OutputChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int Index, int State)
+{
+ printf("Digital Output: %d > State: %d\n", Index, State);
+ return 0;
+}
+
+//callback that will run if the sensor value changes by more than the OnSensorChange trigger.
+//Index - Index of the sensor that generated the event, Value - the sensor read value
+int CCONV SensorChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int Index, int Value)
+{
+ printf("Sensor: %d > Value: %d\n", Index, Value);
+ return 0;
+}
+
+//Display the properties of the attached phidget to the screen. We will be displaying the name, serial number and version of the attached device.
+//Will also display the number of inputs, outputs, and analog inputs on the interface kit as well as the state of the ratiometric flag
+//and the current analog sensor sensitivity.
+int display_properties(CPhidgetInterfaceKitHandle phid)
+{
+ int serialNo, version, numInputs, numOutputs, numSensors, triggerVal, ratiometric, i;
+ const char* ptr;
+
+ CPhidget_getDeviceType((CPhidgetHandle)phid, &ptr);
+ CPhidget_getSerialNumber((CPhidgetHandle)phid, &serialNo);
+ CPhidget_getDeviceVersion((CPhidgetHandle)phid, &version);
+
+ CPhidgetInterfaceKit_getInputCount(phid, &numInputs);
+ CPhidgetInterfaceKit_getOutputCount(phid, &numOutputs);
+ CPhidgetInterfaceKit_getSensorCount(phid, &numSensors);
+ CPhidgetInterfaceKit_getRatiometric(phid, &ratiometric);
+
+ printf("%s\n", ptr);
+ printf("Serial Number: %10d\nVersion: %8d\n", serialNo, version);
+ printf("# Digital Inputs: %d\n# Digital Outputs: %d\n", numInputs, numOutputs);
+ printf("# Sensors: %d\n", numSensors);
+ printf("Ratiometric: %d\n", ratiometric);
+
+ for(i = 0; i < numSensors; i++)
+ {
+ CPhidgetInterfaceKit_getSensorChangeTrigger (phid, i, &triggerVal);
+
+ printf("Sensor#: %d > Sensitivity Trigger: %d\n", i, triggerVal);
+ }
+
+ return 0;
+}
+
+
+int interfacekit_simple()
+{
+ int result, numSensors, i;
+ const char *err;
+
+ //Declare an InterfaceKit handle
+ CPhidgetInterfaceKitHandle ifKit = 0;
+
+ //create the InterfaceKit object
+ CPhidgetInterfaceKit_create(&ifKit);
+
+ //Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
+ // CPhidget_set_OnAttach_Handler((CPhidgetHandle)ifKit, AttachHandler, NULL);
+ // CPhidget_set_OnDetach_Handler((CPhidgetHandle)ifKit, DetachHandler, NULL);
+ // CPhidget_set_OnError_Handler((CPhidgetHandle)ifKit, ErrorHandler, NULL);
+
+ //Registers a callback that will run if an output changes.
+ //Requires the handle for the Phidget, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
+ // CPhidgetInterfaceKit_set_OnOutputChange_Handler (ifKit, OutputChangeHandler, NULL);
+
+ //open the interfacekit for device connections
+ CPhidget_open((CPhidgetHandle)ifKit, -1);
+
+ //get the program to wait for an interface kit device to be attached
+ printf("Waiting for interface kit to be attached....");
+ if((result = CPhidget_waitForAttachment((CPhidgetHandle)ifKit, 10000)))
+ {
+ CPhidget_getErrorDescription(result, &err);
+ printf("Problem waiting for attachment: %s\n", err);
+ return 0;
+ }
+
+ //Display the properties of the attached interface kit device
+ // display_properties(ifKit);
+
+ //read interface kit event data
+ // printf("Reading.....\n");
+
+ //keep displaying interface kit data until user input is read
+ // printf("Press any key to go to next step\n");
+ // getchar();
+
+ int rv=-1;
+ int foo=-1;
+ int bar=-1;
+ int baz=-1;
+ printf("\n");
+
+ rv=CPhidgetInterfaceKit_getOutputState(ifKit,0,&foo);
+ printf("read = %d, rv=%d \n",foo,rv);
+
+ rv=CPhidgetInterfaceKit_setOutputState(ifKit,0,0);
+ printf("set to zero, rv=%d \n",rv);
+
+ rv=CPhidgetInterfaceKit_getOutputState(ifKit,0,&bar);
+ printf("read = %d, rv=%d \n",bar,rv);
+
+ rv=CPhidgetInterfaceKit_setOutputState(ifKit,0,1);
+ printf("set to one, rv=%d \n",rv);
+
+ rv=CPhidgetInterfaceKit_getOutputState(ifKit,0,&baz);
+ printf("read = %d, rv=%d \n",baz,rv);
+
+
+ //since user input has been read, this is a signal to terminate the program so we will close the phidget and delete the object we created
+ printf("Closing...\n");
+ CPhidget_close((CPhidgetHandle)ifKit);
+ CPhidget_delete((CPhidgetHandle)ifKit);
+
+ //all done, exit
+ return 0;
+}
+
+int main(int argc, char* argv[])
+{
+ interfacekit_simple();
+ return 0;
+}
+
--- a/stateManager.c Fri Nov 25 14:23:22 2016 +0000
+++ b/stateManager.c Wed Dec 14 15:51:59 2016 +0000
@@ -385,7 +385,7 @@
//display_LCD_properties(LCD); //Display the properties of the attached Text LCD device
//Set the LCD startup screen
- snprintf (buffer0, bufferSize, "Welcome to N4C");
+ snprintf (buffer0, bufferSize, "Welcome to loradtn");
snprintf (buffer1, bufferSize, "Loading...");
CPhidgetTextLCD_setDisplayString (LCD, 0, buffer0);