~ubuntu-branches/ubuntu/trusty/libticalcs/trusty-proposed

« back to all changes in this revision

Viewing changes to src/probe.c

  • Committer: Package Import Robot
  • Author(s): Andreas B. Mundt
  • Date: 2013-08-27 19:58:21 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20130827195821-biurlicyqb65gj3g
Tags: 1.1.8+dfsg2-2
* Provide original upstream source, but patch away pre-compiled
  binaries to be policy-compliant.
* Remove unnecessary dependency on 'autopoint', use autoreconf.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Hey EMACS -*- linux-c -*- */
2
 
/* $Id: probe.c 4067 2007-12-10 17:50:39Z roms $ */
 
2
/* $Id$ */
3
3
 
4
4
/*  libticalcs - Ti Calculator library, a part of the TiLP project
5
5
 *  Copyright (C) 1999-2005  Romain Li�vin
15
15
 *  GNU General Public License for more details.
16
16
 *
17
17
 *  You should have received a copy of the GNU General Public License
18
 
 *  along with this program; if not, write to the Free Software
19
 
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 *  along with this program; if not, write to the Free Software Foundation,
 
19
 *  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
20
 */
21
21
 
22
22
/*
28
28
#include <string.h>
29
29
 
30
30
#include "ticalcs.h"
 
31
#include "internal.h"
31
32
#include "logging.h"
32
33
#include "dbus_pkt.h"
33
34
#include "error.h"
42
43
/* 
43
44
        Get the first byte sent by the calc (Machine ID)
44
45
*/
45
 
int tixx_recv_ACK(CalcHandle* handle, uint8_t* mid)
 
46
static int tixx_recv_ACK(CalcHandle* handle, uint8_t* mid)
46
47
{
47
48
        uint8_t host, cmd;
48
49
        uint16_t length;
189
190
                PAUSE(DEAD_TIME);
190
191
        }
191
192
 
 
193
        /* Test for a TI80 */
 
194
#if 0
 
195
#warning TI-80 DETECTION FAILS
 
196
        ticalcs_info(_("Check for TI80... "));
 
197
        ticalcs_info("%d\n", dbus_send(h, PC_TI80, CMD_SCR, 0, NULL));
 
198
        err = tixx_recv_ACK(h, &data);
 
199
 
 
200
        ticalcs_info("<%02X-%02X> ", PC_TI80, data);
 
201
 
 
202
        if (!err && (data == TI80_PC)) 
 
203
        {
 
204
                ticalcs_info("OK !\n");
 
205
                *model = CALC_TI80;
 
206
 
 
207
                return 0;
 
208
        } 
 
209
        else 
 
210
        {
 
211
                ticalcs_info("NOK.\n");
 
212
                ticables_cable_reset(handle->cable);
 
213
                PAUSE(DEAD_TIME);
 
214
        }
 
215
#endif
 
216
 
192
217
        return (*model == CALC_NONE) ? ERR_NO_CALC : 0;
193
218
}
194
219
 
317
342
 *
318
343
 * Return value: 0 if successful, an error code otherwise.
319
344
 **/
320
 
TIEXPORT3 int TICALL ticalcs_probe_calc  (CableHandle* cable, CalcModel* model)
 
345
TIEXPORT3 int TICALL ticalcs_probe_calc (CableHandle* cable, CalcModel* model)
321
346
{
322
347
        CalcHandle calc;
323
348
        int err = 0;
324
349
 
 
350
        if (cable == NULL)
 
351
        {
 
352
                return ERR_INVALID_HANDLE;
 
353
        }
 
354
        if (model == NULL)
 
355
        {
 
356
                ticalcs_critical("ticalcs_probe_calc: model is NULL");
 
357
                return -1;
 
358
        }
 
359
 
325
360
        // Hack: we construct the structure here because we don't really need it.
326
361
        // I want to use ticalcs functions with a non-fixed calculator
327
362
        memset(&calc, 0, sizeof(CalcHandle));
367
402
        int err = 0;
368
403
        int ret = ERR_NO_CALC;
369
404
 
 
405
        if (cable == NULL)
 
406
        {
 
407
                return ERR_INVALID_HANDLE;
 
408
        }
 
409
        if (model == NULL)
 
410
        {
 
411
                ticalcs_critical("ticalcs_probe_calc: model is NULL");
 
412
                return -1;
 
413
        }
 
414
 
370
415
        // Hack: we construct the structure here because we don't really need it.
371
416
        // I want to use ticalcs functions with a non-fixed calculator
372
417
        memset(&calc, 0, sizeof(CalcHandle));
388
433
                int i;
389
434
 
390
435
                ticables_get_usb_devices(&list, &n);
391
 
                i = cable->port-1 > n ? n-1 : cable->port-1;
 
436
                i = (int)cable->port-1 > n ? n-1 : (int)cable->port-1;
392
437
                switch(list[i])
393
438
                {
394
439
                case PID_TI89TM:   *model = CALC_TI89T_USB; ret = 0; break;
422
467
        int err = 0;
423
468
        CalcHandle calc;
424
469
 
 
470
        if (model == NULL)
 
471
        {
 
472
                ticalcs_critical("ticalcs_probe_calc: model is NULL");
 
473
                return -1;
 
474
        }
 
475
 
425
476
        // get handle
426
477
        handle = ticables_handle_new(c_model, c_port);
427
478
        ticables_options_set_timeout(handle, 10);
453
504
                else
454
505
                        err = ticalcs_probe_calc_1(&calc, model);
455
506
        }
456
 
                
 
507
 
457
508
        if(err)
458
509
        {
459
510
                ticables_cable_close(handle);