int main(int argc, char*argv[]) {
        _cleanup_bus_unref_ sd_bus *bus = NULL;
        int fd1, fd2;
        int r;

        r = sd_bus_open_system(&bus);
        assert_se(r >= 0);

        print_inhibitors(bus);

        fd1 = inhibit(bus, "sleep");
        assert_se(fd1 >= 0);
        print_inhibitors(bus);

        fd2 = inhibit(bus, "idle:shutdown");
        assert_se(fd2 >= 0);
        print_inhibitors(bus);

        safe_close(fd1);
        sleep(1);
        print_inhibitors(bus);

        safe_close(fd2);
        sleep(1);
        print_inhibitors(bus);

        return 0;
}
Example #2
0
int main(int argc, char*argv[]) {
        DBusConnection *bus;
        int fd1, fd2;

        bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, NULL);
        assert(bus);

        print_inhibitors(bus);

        fd1 = inhibit(bus, "sleep");
        assert(fd1 >= 0);
        print_inhibitors(bus);

        fd2 = inhibit(bus, "idle:shutdown");
        assert(fd2 >= 0);
        print_inhibitors(bus);

        close_nointr_nofail(fd1);
        sleep(1);
        print_inhibitors(bus);

        close_nointr_nofail(fd2);
        sleep(1);
        print_inhibitors(bus);

        return 0;
}
Example #3
0
// TODO: send using interrupt if available
uint8_t ps2_host_send(uint8_t data)
{
    uint8_t res = 0;
    bool parity = true;
    ps2_error = PS2_ERR_NONE;
#ifdef PS2_USE_INT
    PS2_INT_OFF();
#endif
    /* terminate a transmission if we have */
    inhibit();
    _delay_us(200); // at least 100us

    /* start bit [1] */
    data_lo();
    clock_hi();
    WAIT(clock_lo, 20000, 10);   // may take 15ms at most until device starts clocking
    /* data [2-9] */
    for (uint8_t i = 0; i < 8; i++) {
        _delay_us(15);
        if (data&(1<<i)) {
            parity = !parity;
            data_hi();
        } else {
            data_lo();
        }
        WAIT(clock_hi, 50, 2);
        WAIT(clock_lo, 50, 3);
    }
    /* parity [10] */
    _delay_us(15);
    if (parity) { data_hi(); } else { data_lo(); }
    WAIT(clock_hi, 50, 4);
    WAIT(clock_lo, 50, 5);
    /* stop bit [11] */
    _delay_us(15);
    data_hi();
    /* ack [12] */
    WAIT(data_lo, 50, 6);
    WAIT(clock_lo, 50, 7);

    /* wait for idle state */
    WAIT(clock_hi, 50, 8);
    WAIT(data_hi, 50, 9);

#ifdef PS2_USE_INT
    PS2_INT_ON();
#endif
    res = ps2_host_recv_response();
ERROR:
#ifdef PS2_USE_INT
    PS2_INT_ON();
    idle();
#else
    inhibit();
#endif
    return res;
}
Example #4
0
void ibm4704_init(void)
{
    inhibit();  // keep keyboard from sending
    IBM4704_INT_INIT();
    IBM4704_INT_ON();
    idle();     // allow keyboard sending
}
static void
impl_activate (RBPlugin *rbplugin,
	       RBShell *shell)
{
	RBGPMPlugin *plugin;
	GError *error = NULL;
	GObject *shell_player;
	gboolean playing;

	plugin = RB_GPM_PLUGIN (rbplugin);

	plugin->shell = g_object_ref (shell);
	plugin->bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
	if (plugin->bus == NULL) {
		g_warning ("Couldn't connect to system bus: %s", (error) ? error->message : "(null)");
		return;
	}

	g_object_get (shell, "shell-player", &shell_player, NULL);

	plugin->handler_id = g_signal_connect_object (shell_player,
						      "playing-changed",
						      (GCallback) playing_changed_cb,
						      plugin, 0);

	g_object_get (shell_player, "playing", &playing, NULL);
	if (playing) {
		inhibit (plugin);
	}

	g_object_unref (shell_player);
}
static void
impl_activate (PeasActivatable *bplugin)
{
	RBGPMPlugin *plugin;
	GObject *shell_player;
	gboolean playing;
	RBShell *shell;

	plugin = RB_GPM_PLUGIN (bplugin);

	g_object_get (plugin, "object", &shell, NULL);
	g_object_get (shell, "shell-player", &shell_player, NULL);

	plugin->handler_id = g_signal_connect_object (shell_player,
						      "playing-changed",
						      (GCallback) playing_changed_cb,
						      plugin, 0);

	g_object_get (shell_player, "playing", &playing, NULL);
	if (playing) {
		inhibit (plugin);
	}

	g_object_unref (shell_player);
	g_object_unref (shell);
}
Example #7
0
uint8_t ps2_host_send(uint8_t data)
{
    bool parity = true;
    ps2_error = PS2_ERR_NONE;

    PS2_USART_OFF();

    /* terminate a transmission if we have */
    inhibit();
    _delay_us(100); // [4]p.13

    /* 'Request to Send' and Start bit */
    data_lo();
    clock_hi();
    WAIT(clock_lo, 10000, 10);   // 10ms [5]p.50

    /* Data bit[2-9] */
    for (uint8_t i = 0; i < 8; i++) {
        _delay_us(15);
        if (data&(1<<i)) {
            parity = !parity;
            data_hi();
        } else {
            data_lo();
        }
        WAIT(clock_hi, 50, 2);
        WAIT(clock_lo, 50, 3);
    }

    /* Parity bit */
    _delay_us(15);
    if (parity) { data_hi(); } else { data_lo(); }
    WAIT(clock_hi, 50, 4);
    WAIT(clock_lo, 50, 5);

    /* Stop bit */
    _delay_us(15);
    data_hi();

    /* Ack */
    WAIT(data_lo, 50, 6);
    WAIT(clock_lo, 50, 7);

    /* wait for idle state */
    WAIT(clock_hi, 50, 8);
    WAIT(data_hi, 50, 9);

    idle();
    PS2_USART_INIT();
    PS2_USART_RX_INT_ON();
    return ps2_host_recv_response();
ERROR:
    idle();
    PS2_USART_INIT();
    PS2_USART_RX_INT_ON();
    return 0;
}
boolean Adafruit_PS2_Mouse::reset(void) {
  idle();
  if (!command(ADAFRUIT_PS2_RESET)) return false;
  if (read() != 0xAA) return false;
  if (read() != 0x00) return false;
  inhibit();

  return true;
}
Example #9
0
void ps2_host_init(void)
{
#ifdef PS2_USE_INT
    PS2_INT_INIT();
    PS2_INT_ON();
    idle();
#else
    inhibit();
#endif
}
boolean Adafruit_PS2_Mouse::begin(void) {

  if (! reset()) return false;

  idle();
  write(ADAFRUIT_PS2_SETPOLL); // we will poll the mouse
  read();
  delayMicroseconds(100);
  inhibit();
}
Example #11
0
/* receive data when host want else inhibit communication */
uint8_t ps2_host_recv_response(void)
{
    uint8_t data = 0;

#ifdef PS2_USE_INT
    PS2_INT_OFF();
#endif
    /* terminate a transmission if we have */
    inhibit();
    _delay_us(100);

    /* release lines(idle state) */
    idle();

    /* wait start bit */
    wait_clock_lo(25000);    // command response may take 20 ms at most
    data = recv_data();

    inhibit();
    return data;
}
Example #12
0
static rpmRC systemd_inhibit_tsm_pre(rpmPlugin plugin, rpmts ts)
{
    if (rpmtsFlags(ts) & (RPMTRANS_FLAG_TEST|RPMTRANS_FLAG_BUILD_PROBS))
        return RPMRC_OK;

    lock_fd = inhibit();

    if (lock_fd < 0) {
        rpmlog(RPMLOG_WARNING,
               "Unable to get systemd shutdown inhibition lock\n");
    } else {
        rpmlog(RPMLOG_DEBUG, "System shutdown blocked (fd %d)\n", lock_fd);
    }

    return RPMRC_OK;
}
void Adafruit_PS2::write(uint8_t x)  {
  uint16_t tosend = x;
  uint8_t parity = 1;
  
  for (uint8_t i=0; i<8; i++) {
    parity ^= (tosend >> i);
  }
  if (parity & 0x1)
    tosend |= 0x100;

  idle();
  delayMicroseconds(300);
  low(_clk);
  delayMicroseconds(100);
  low(_data);
  delayMicroseconds(10);

  // we pull the clock line up to indicate we're ready
  high(_clk);
  // wait for the device to acknowledge by pulling it down
  while (digitalRead(_clk));
  
  for (uint8_t i=0; i < 9; i++) {
    if (tosend & 0x1)
      high(_data);
    else
      low(_data);
    
    // the clock lines are driven by the -DEVICE- so we wait
    while (!digitalRead(_clk));
    while (digitalRead(_clk));

    tosend >>= 1;
  }  

  // send stop bit (high)
  high(_data);
  delayMicroseconds(50);
  while (digitalRead(_clk));
  // wait for mouse to switch modes
  while (!digitalRead(_clk) || !digitalRead(_data));

  // inhibit any more data (we will poll!)
  inhibit();
}
boolean Adafruit_PS2_Trackpad::begin(void) {
  if (! reset()) return false;


  // see http://www.win.tue.nl/~aeb/linux/kbd/scancodes-13.html sec 13.7
  uint32_t e6 = E6Report();
  uint8_t s1, s2, s3;
  s1 = e6 >> 16;
  s2 = e6 >> 8;
  s3 = e6;

  if (s3 != 0x64) return false; // not a trackpad?
  if (s2 == 0) return false; // not a trackpad?

  Serial.print("Trackpad found with ");
  Serial.print(s2, DEC); 
  Serial.println(" buttons");

  if (s1 & 0x80)  // supports the e7 command report
    E7Report();

  if (!tapMode(false)) return false;
  Serial.println("Tap mode set");
  
  getStatus();

  if (! absoluteMode()) return false;
  Serial.println("Absolute mode set");


  //if (!command(ADAFRUIT_PS2_SETPOLL)) return false;
  //delay(1);
  //if (!command(ADAFRUIT_PS2_SETSTREAMMODE)) return false;

  inhibit();

  return true;
}
uint8_t Adafruit_PS2::read(void) {
  uint16_t d = 0;
  
  idle();
  delayMicroseconds(50);
  // wait for clock line to drop

  // start bit + 8 bits data + parity + stop = 11 bits  
  for (uint8_t i=0; i<11; i++) {
    while (digitalRead(_clk));
    if (digitalRead(_data))
      d |= _BV(i);
    while (!digitalRead(_clk));
  }
  inhibit();
  // drop start bit
  d >>= 1;
  //Serial.print("d = 0x");
  //Serial.println(d, HEX);
  // check parity & stop bit later?
  return d & 0xFF;
  
}
Example #16
0
int main(int argc, char *argv[]) {
        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
        _cleanup_bus_close_unref_ sd_bus *bus = NULL;
        int r;

        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r < 0)
                return EXIT_FAILURE;
        if (r == 0)
                return EXIT_SUCCESS;

        r = sd_bus_default_system(&bus);
        if (r < 0) {
                log_error("Failed to connect to bus: %s", strerror(-r));
                return EXIT_FAILURE;
        }

        if (arg_action == ACTION_LIST) {

                r = print_inhibitors(bus, &error);
                if (r < 0) {
                        log_error("Failed to list inhibitors: %s", bus_error_message(&error, -r));
                        return EXIT_FAILURE;
                }

        } else {
                _cleanup_close_ int fd = -1;
                _cleanup_free_ char *w = NULL;
                pid_t pid;

                if (!arg_who)
                        arg_who = w = strv_join(argv + optind, " ");

                fd = inhibit(bus, &error);
                if (fd < 0) {
                        log_error("Failed to inhibit: %s", bus_error_message(&error, -r));
                        return EXIT_FAILURE;
                }

                pid = fork();
                if (pid < 0) {
                        log_error("Failed to fork: %m");
                        return EXIT_FAILURE;
                }

                if (pid == 0) {
                        /* Child */

                        close_all_fds(NULL, 0);

                        execvp(argv[optind], argv + optind);
                        log_error("Failed to execute %s: %m", argv[optind]);
                        _exit(EXIT_FAILURE);
                }

                r = wait_for_terminate_and_warn(argv[optind], pid);
                return r < 0 ? EXIT_FAILURE : r;
        }

        return 0;
}
int main (int argc, char *argv[])
{
  gchar *prgname;
  GsmInhibitorFlag inhibit_flags = 0;
  gboolean show_help = FALSE;
  gboolean show_version = FALSE;
  gboolean no_launch = FALSE;
  gint i;
  const gchar *app_id = "unknown";
  const gchar *reason = "not specified";

  prgname = g_path_get_basename (argv[0]);
  g_set_prgname (prgname);
  g_free (prgname);

  setlocale (LC_ALL, "");
  bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  for (i = 1; i < argc; i++)
    {
      if (strcmp (argv[i], "--help") == 0 ||
          strcmp (argv[i], "-h") == 0)
        show_help = TRUE;
      else if (strcmp (argv[i], "--version") == 0)
        show_version = TRUE;
      else if (strcmp (argv[i], "--inhibit-only") == 0)
        no_launch = TRUE;
      else if (strcmp (argv[i], "--app-id") == 0)
        {
          i++;
          if (i == argc)
            {
              g_print (_("%s requires an argument\n"), argv[i]);
              exit (1);
            }
          app_id = argv[i];
        }
      else if (strcmp (argv[i], "--reason") == 0)
        {
          i++;
          if (i == argc)
            {
              g_print (_("%s requires an argument\n"), argv[i]);
              exit (1);
            }
          reason = argv[i];
        }
      else if (strcmp (argv[i], "--inhibit") == 0)
        {
          i++;
          if (i == argc)
            {
              g_print (_("%s requires an argument\n"), argv[i]);
              exit (1);
            }
          inhibit_flags |= parse_flags (argv[i]);
        }
      else
        break;
    }

  if (show_version)
    {
      version ();
      return 0;
    }

  if (show_help || (i == argc && !no_launch))
    {
      usage ();
      return 0;
    }

  if (inhibit_flags == 0)
    inhibit_flags = GSM_INHIBITOR_FLAG_IDLE;

  if (inhibit (app_id, reason, inhibit_flags) == FALSE)
    return 1;

  if (!no_launch)
    wait_for_child_app (argv + i);
  else
    wait_forever ();

  return 0;
}
Example #18
0
int main(int argc, char* argv[])
{
	bool norelease = false;
	if (YARPParseParameters::parse(argc, argv, "-norelease"))
		norelease = true;
	YARPString cfgFile;
	if (!YARPParseParameters::parse(argc, argv, "-cfg", cfgFile))
		cfgFile = __defaultCfgFile;

	ReflexShared shared;
	GRBehavior behavior(&shared);
	GRBLoopTouch loopTouch;
	GRBWaitIdle waitClose1;
	GRBWaitIdle waitOpen1;
	GRBWaitIdle waitOpen2;
	GRBPickRndAction pickRnd;

	GRBWaitDeltaT waitT[] = {0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
							 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2 };
	GRBGrasp grasp;
	GRBCloseOutputCommand closeCmd;
	GRBOpenOutputCommand openCmd;
	GRBInhibitCommand inhibitOutput;
	GRBReleaseCommand enableOutput;
	GRBOutputSignal	sendClutching(YBVGraspRflxClutch);
	GRBOutputSignal inhibitReaching(YBVReachingInhibit);
	GRBOutputSignal enableReaching(YBVReachingEnable);
	
	GRBInit init;
	GRBSimpleInput motionDone(YBVHandDone);
	GRBSimpleInput inhibit(YBVGraspRflxInhibit);
	GRBSimpleInput release(YBVGraspRflxRelease);
	GRBSimpleInput forceOpen(YBVGraspRflxForceOpen);

	readConfigFile(cfgFile, shared);

	behavior.setInitialState(&loopTouch);
	behavior.add(&inhibit, &inhibitOutput);
	behavior.add(&release, &enableOutput);
	behavior.add(&init, &loopTouch, &pickRnd, &inhibitReaching);
	behavior.add(NULL, &loopTouch, &loopTouch);	// loopTouch is a blocking state
	behavior.add(NULL, &pickRnd, &waitOpen1, &openCmd);
	behavior.add(&motionDone, &waitOpen1, &grasp, &closeCmd);
	behavior.add(NULL, &grasp, &waitClose1);
	behavior.add(&motionDone, &waitClose1, &waitT[0], &sendClutching);
	for(int i = 0; i<(N-1); i++)
		behavior.add(NULL, &waitT[i], &waitT[i+1]);

	// check no automatic release
	if (norelease)
		behavior.add(&forceOpen, &waitT[N-1], &waitOpen2, &openCmd);
	else
		behavior.add(NULL, &waitT[N-1], &waitOpen2, &openCmd);

	behavior.add(&motionDone, &waitOpen2, &loopTouch, &enableReaching);
	
	behavior.Begin();
	behavior.loop();

	return 0;
}
Example #19
0
int main(int argc, char *argv[]) {
        int r, exit_code = 0;
        DBusConnection *bus = NULL;
        DBusError error;
        int fd = -1;

        dbus_error_init(&error);

        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r <= 0)
                goto finish;

        bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
        if (!bus) {
                log_error("Failed to connect to bus: %s", bus_error_message(&error));
                r = -EIO;
                goto finish;
        }

        if (arg_action == ACTION_LIST) {

                r = print_inhibitors(bus, &error);
                if (r < 0) {
                        log_error("Failed to list inhibitors: %s", bus_error_message_or_strerror(&error, -r));
                        goto finish;
                }

        } else {
                char *w = NULL;
                pid_t pid;

                if (!arg_who)
                        arg_who = w = strv_join(argv + optind, " ");

                fd = inhibit(bus, &error);
                free(w);

                if (fd < 0) {
                        log_error("Failed to inhibit: %s", bus_error_message_or_strerror(&error, -r));
                        r = fd;
                        goto finish;
                }

                pid = fork();
                if (pid < 0) {
                        log_error("Failed to fork: %m");
                        r = -errno;
                        goto finish;
                }

                if (pid == 0) {
                        /* Child */

                        close_nointr_nofail(fd);
                        execvp(argv[optind], argv + optind);
                        log_error("Failed to execute %s: %m", argv[optind]);
                        _exit(EXIT_FAILURE);
                }

                r = wait_for_terminate_and_warn(argv[optind], pid);
                if (r >= 0)
                        exit_code = r;
        }

finish:
        if (bus) {
                dbus_connection_close(bus);
                dbus_connection_unref(bus);
        }

        dbus_error_free(&error);

        if (fd >= 0)
                close_nointr_nofail(fd);

        return r < 0 ? EXIT_FAILURE : exit_code;
}