Example #1
0
File: main.c Project: wuwx/simba
static int cmd_at_cb(int argc,
                     const char *argv[],
                     void *out_p,
                     void *in_p,
                     void *arg_p,
                     void *call_arg_p)
{
    struct chan_list_t list;
    void *chan_p;
    char c;
    char buf[32];

    std_fprintf(out_p, OSTR("type ctrl-d to exit\r\n"));

    /* Wait for data from PC and HC-0X. */
    chan_list_init(&list, buf, sizeof(buf));
    chan_list_add(&list, &uart.chin);
    chan_list_add(&list, in_p);

    /* Pass data between PC and bluetooth device. */
    while (1) {
        chan_p = chan_list_poll(&list, NULL);

        if (chan_p == in_p) {
            chan_read(chan_p, &c, sizeof(c));

            /* break if EOT is found, otherwise write to HC-0X. */
            if (c == EOT) {
                break;
            }

            chan_write(&uart.chout, &c, sizeof(c));
        } else if (chan_p == &uart.chin) {
            /* Write all output from HC-0X to the PC. */
            chan_read(chan_p, &c, sizeof(c));
            chan_write(out_p, &c, sizeof(c));
        } else {
            std_printf(OSTR("bad input channel 0x%02x\r\n"),  (int)chan_p);
        }
    }

    chan_list_destroy(&list);

    return (0);
}
Example #2
0
File: main.c Project: wuwx/simba
static int test_scan(struct harness_t *harness_p)
{
    int number_of_slaves_found;
    int address;

    number_of_slaves_found = 0;

    for (address = 0; address < 128; address++) {
        if (i2c_scan(&i2c, address) == 1) {
            std_printf(OSTR("Found slave with address 0x%02x.\r\n"),
                       address);
            number_of_slaves_found++;
        }
    }

    std_printf(OSTR("Number of slaves found: %d\r\n"),
               number_of_slaves_found);

    return (0);
}
Example #3
0
File: lisp.c Project: qyqx/wisp
object_t *lisp_load (object_t * lst)
{
  DOC ("Evaluate contents of a file.");
  REQ (lst, 1, c_sym ("load"));
  object_t *str = CAR (lst);
  if (!STRINGP (str))
    THROW (wrong_type, UPREF (str));
  char *filename = OSTR (str);
  int r = load_file (NULL, filename, 0);
  if (!r)
    THROW (c_sym ("load-file-error"), UPREF (str));
  return T;
}
Example #4
0
File: lisp.c Project: qyqx/wisp
object_t *eql (object_t * lst)
{
  DOC ("Return t if both arguments are similar.");
  REQ (lst, 2, c_sym ("eql"));
  object_t *a = CAR (lst);
  object_t *b = CAR (CDR (lst));
  if (a->type != b->type)
    return NIL;
  switch (a->type)
    {
    case INT:
    case FLOAT:
      return num_eq (lst);
      break;
    case SYMBOL:
    case CONS:
      if (a == b)
	return T;
      break;
    case STRING:
      if (OSTRLEN (a) == OSTRLEN (b))
	if (memcmp (OSTR (a), OSTR (b), OSTRLEN (a)) == 0)
	  return T;
      break;
    case VECTOR:
      return NIL;
      break;
    case DETACH:
      if (a == b)
	return T;
      break;
    case CFUNC:
    case SPECIAL:
      if (FVAL (a) == FVAL (b))
	return T;
      break;
    }
  return NIL;
}
Example #5
0
File: lisp.c Project: qyqx/wisp
object_t *lisp_read_string (object_t * lst)
{
  DOC ("Parse a string into a sexp or list object.");
  REQ (lst, 1, c_sym ("eval-string"));
  object_t *stro = CAR (lst);
  if (!STRINGP (stro))
    THROW (wrong_type, UPREF (stro));
  char *str = OSTR (stro);
  reader_t *r = reader_create (NULL, str, "eval-string", 0);
  object_t *sexp = read_sexp (r);
  reader_destroy (r);
  if (sexp == err_symbol)
    THROW (c_sym ("parse-error"), UPREF (stro));
  return sexp;
}
Example #6
0
File: main.c Project: wuwx/simba
int main()
{
    struct hx711_driver_t hx711;
    float weight_a_128;
    float weight_a_64;
    float weight_b_32;
    int res;

    sys_start();

    /* Initialize the driver. */
    std_printf(OSTR("Initializing the HX711 driver... "));

    res = hx711_init(&hx711,
                     &pin_d2_dev,
                     &pin_d3_dev,
                     SCALE,
                     OFFSET);

    if (res == 0) {
        std_printf(OSTR("done.\r\n"));
    } else {
        std_printf(OSTR("failed with %d.\r\n"), res);
        return (res);
    }

    /* Start the driver. */
    std_printf(OSTR("Starting the HX711 driver... "));

    res = hx711_start(&hx711);

    if (res == 0) {
        std_printf(OSTR("done.\r\n"));
    } else {
        std_printf(OSTR("failed with %d.\r\n"), res);
        return (res);
    }

    /* Continiously read samples from the device and print them. */
    while (1) {
        res = hx711_read(&hx711, &weight_a_128, hx711_channel_gain_a_128_t);

        if (res != 0) {
            std_printf(OSTR("Read 128 failed with %d.\r\n"), res);
        }

        res = hx711_read(&hx711, &weight_a_64, hx711_channel_gain_a_64_t);

        if (res != 0) {
            std_printf(OSTR("Read 64 failed with %d.\r\n"), res);
        }

        res = hx711_read(&hx711, &weight_b_32, hx711_channel_gain_b_32_t);

        if (res != 0) {
            std_printf(OSTR("Read 32 failed with %d.\r\n"), res);
        }

        /* Print the samples. */
        std_printf(OSTR("Weight channel A gain 128: %f\r\n"
                        "Weight channel A gain 64:  %f\r\n"
                        "Weight channel B gain 32:  %f\r\n"
                        "\r\n"),
                   weight_a_128,
                   weight_a_64,
                   weight_b_32);
    }

    return (0);
}