source: thomson/elec/CrO2/software/cro2.cpp@ c7b4218

main
Last change on this file since c7b4218 was c7b4218, checked in by Adrien Destugues <pulkomandy@…>, 12 years ago
  • Move GUI in its own class
  • Design C++ callbacksystem for IUP
  • Load file from menu

git-svn-id: svn://localhost/thomson@13 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/* CrO2 datassette emulator
2 * Copyright 2012, Adrien Destugues <pulkomandy@pulkomandy.ath.cx>
3 *
4 * Distributed under the terms of the MIT licence.
5 */
6
7#include <iostream>
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <stdint.h>
12#include <unistd.h>
13
14
15#include "device.h"
16#include "k5.h"
17#include "gui.h"
18
19int main(int argc, char **argv)
20{
21 int nBytes = 0;
22
23 if(argc < 2){
24 Gui gui(&argc, &argv);
25 exit(0);
26 }
27
28 try {
29 Device& dev = Device::getDevice(); // Constructor inits communication.
30
31 if(strcmp(argv[1], "get") == 0){
32 unsigned char buffer[275];
33 memset(buffer, 0, 275);
34 nBytes = dev.read(buffer, sizeof(buffer));
35 }else if(strcmp(argv[1], "put") == 0){
36
37 // load file
38 K5 file(argv[2]);
39
40 for (int k = 0; k < file.getBlockCount(); k++)
41 {
42 // wait for motor on
43 while (dev.getStatus() & 8)
44 Sleep(1000);
45
46 K5::Block block = file.getBlock(k);
47
48 nBytes = dev.write(block.data, block.length - 1, block.type);
49
50 // TODO wait for correct time (read status from usb OR compute from size+type)
51 Sleep(1400);
52 }
53 }else{
54 // TODO print usage
55 exit(2);
56 }
57
58 if (nBytes < 0) fprintf(stderr, "USB error %s\n", usb_strerror());
59 return 0;
60 }
61 catch(const char* error)
62 {
63 std::cerr << error << std::endl;
64 }
65
66 exit(0);
67}
68
Note: See TracBrowser for help on using the repository browser.