Exemplo n.º 1
0
// python function cleanup(channel=None)
static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs)
{
	int i = 0;
	int found = 0,v = 0;
	int channel = -666;
	unsigned int gpio;
    	unsigned int sys_gpio;
	static char *kwlist[] = {"channel", NULL};
	v = get_lmk_revision();
	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwlist, &channel))
		return NULL;

	if (channel != -666 && get_gpio_number(channel, &gpio, &sys_gpio))
		return NULL;

   if (module_setup && !setup_error) {
      if (channel == -666) {
         // clean up any /sys/class exports
         event_cleanup_all();
         
         // set everything back to input
         for (i=0; i<256; i++) {
            if (gpio_direction[i] != -1) {
				debug("Clean %d \n",i);
				if(v == BANANAPRO){
					setup_gpio(*(pinTobcm_BP+i), INPUT, PUD_OFF);//take care
				} else if(v == LEMAKER_GUITAR){
					setup_gpio(*(pinTobcm_GT+i), INPUT, PUD_OFF);//take care
				}
				gpio_direction[i] = -1;
				found = 1;
            }
         }
      } else {
         // clean up any /sys/class exports
         event_cleanup(sys_gpio);

         // set everything back to input
         if (gpio_direction[sys_gpio] != -1) {
            setup_gpio(gpio, INPUT, PUD_OFF);
            gpio_direction[i] = -1;
            found = 1;
         }
      }
   }

	//printf("-->Before set warning\n");
	//printf("found %d \t gpio_warnings %d\n",found,gpio_warnings);
   // check if any channels set up - if not warn about misuse of GPIO.cleanup()
   if (!found && gpio_warnings) {
      PyErr_WarnEx(NULL, "No channels have been set up yet - nothing to clean up!  Try cleaning up at the end of your program instead!", 1);
   }
	//printf("-->After set warning\n");

   Py_RETURN_NONE;
}
// python function cleanup(channel=None)
static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs)
{
   int i;
   int found = 0;
   int channel = -666;
   unsigned int gpio;
   static char *kwlist[] = {"channel", NULL};

   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwlist, &channel))
      return NULL;

   if (channel != -666 && get_gpio_number(channel, &gpio))
      return NULL;

   if (module_setup && !setup_error) {
      if (channel == -666) {
         // clean up any /sys/class exports
         event_cleanup_all();

         // set everything back to input
         for (i=0; i<54; i++) {
            if (gpio_direction[i] != -1) {
               setup_gpio(i, INPUT, PUD_OFF);
               gpio_direction[i] = -1;
               found = 1;
            }
         }
      } else {
         // clean up any /sys/class exports
         event_cleanup(gpio);

         // set everything back to input
         if (gpio_direction[gpio] != -1) {
            setup_gpio(gpio, INPUT, PUD_OFF);
            gpio_direction[i] = -1;
            found = 1;
         }
      }
   }

   // check if any channels set up - if not warn about misuse of GPIO.cleanup()
   if (!found && gpio_warnings) {
      PyErr_WarnEx(NULL, "No channels have been set up yet - nothing to clean up!  Try cleaning up at the end of your program instead!", 1);
   }

   Py_RETURN_NONE;
}