int main(int argc, char ** argv) { int i = 0; int x, y; x = y = 0; boardInit(); for (i=0; i<PS2_READ_TIMES; i++) { if (pcf8591Read(1, &x) != -1 && pcf8591Read(2, &y) != -1) { printf("x=%4d y=%4d\n", x, y); } } return 0; }
int main(int argc, char ** argv) { int i = 0; int value = 0; int channel = 0; if (boardInit() < 0) { printf("Fail to init board\n"); return -1; } if (argc == 2) channel = atoi(argv[1]); system("modprobe "DRIVER_MODULE); signal(SIGINT, intHandler); for (i=0; i<ADC_READ_TIMES; i++) { if (pcf8591Read(channel, &value) != -1) { printf("The channel%d value is %d\n", channel, value); } else { printf("Fail to get channel%d value\n", channel); } } system("rmmod "DRIVER_MODULE); return 0; }
static PyObject *py_pcf8591_read(PyObject *self, PyObject *args) { int data = -1; int channel = -1; PyObject *value = NULL; if (!PyArg_ParseTuple(args, "i", &channel)) return NULL; if (channel < 0 || channel > 3) { PyErr_SetString(PyExc_ValueError, "Pcf8591 only has channel 0 1 2 3"); return NULL; } if (pcf8591Read(channel, &data) == 0) { value = Py_BuildValue("i", data); return value; } else { return NULL; } }
int main(int argc, char ** argv) { int devFD; int data, channel, mode; if ((devFD = pcf8591Init()) == -1) { printf("Fail to init pcf8591\n"); return -1; } if (pcf8591SetCtrl(devFD, PCF8591_INIT_AD_CONTROL) == -1) { printf("Fail to Set pcf8591 control AD\n"); pcf8591DeInit(devFD); return -1; } mode = 0; printf("pcf8591 working as AD in mode%d\n",mode); for(channel = PCF8591_AIN_CHANNEL0;channel <= PCF8591_AIN_CHANNEL3; channel++) { data = pcf8591Read(devFD, mode, channel); printf("Channel%d's value: %d\n",channel,data); } pcf8591DeInit(devFD); return 0; }
int main(int argc, char ** argv) { int mode = 0x0; if ((devFD = pcf8591Init()) == -1) { printf("Fail to init pcf8591 AD\n"); return -1; } if (pcf8591SetCtrl(devFD, PCF8591_INIT_AD_CONTROL) == -1) { printf("Fail to Set pcf8591 control AD\n"); pcf8591DeInit(devFD); return -1; } int i = 0; int data; signal(SIGINT, smokeHandler); for (i=0; i<SOIL_READ_TIMES; i++) { data = pcf8591Read(devFD, mode, PCF8591_AIN_CHANNEL0); printf("smoke moisture:%3d\n", data); sleep(1); } pcf8591DeInit(devFD); return 0; }