1 module nspire.device;
2 import nspire.c.devinfo;
3 
4 enum Battery {
5     NSPIRE_BATT_POWERED = 0,
6     NSPIRE_BATT_LOW = 241,
7     NSPIRE_BATT_OK = 127,
8     NSPIRE_BATT_UNKNOWN = 255
9 }
10 
11 enum HWType {
12     NSPIRE_CAS = 14,
13     NSPIRE_NONCAS = 30,
14     NSPIRE_CASCX = 15,
15     NSPIRE_NONCASCX = 31,
16     NSPIRE_CASCX_2 = 28,
17     NSPIRE_NONCASCX_2 = 44
18 }
19 
20 enum RunLevel
21 {
22     NSPIRE_RUNLEVEL_RECOVERY = 1,
23     NSPIRE_RUNLEVEL_OS = 2
24 }
25 
26 struct FlashStorage {
27     ulong free;
28     ulong total;
29 }
30 
31 struct Memory {
32     ulong free;
33     ulong total;
34 }
35 
36 struct Version {
37     ubyte major;
38     ubyte minor;
39     ushort build;
40 }
41 
42 struct Power {
43     Battery status;
44     byte isCharging;
45 }
46 
47 struct LCD {
48     ushort width;
49     ushort height;
50     ubyte bbp;
51     ubyte sampleMode;
52 }
53 
54 struct FileExtensions {
55     char[8] file;
56     char[8] os;
57 }
58 
59 struct DeviceInfo {
60     FlashStorage flashStorage;
61     Memory memory;  
62     Version versionOs;
63     Version versionBoot1;
64     Version versionBoot2;
65     HWType hwType;
66     bool isCharging;
67     Battery batteryStatus;
68     ubyte clockSpeed;
69     LCD lcd;
70     FileExtensions fileExtensions;
71     string deviceName;
72     string electronicId;
73     RunLevel runLevel;
74     
75     this(nspire_devinfo devinfo) {
76         this.flashStorage = cast(FlashStorage) devinfo.storage;
77         this.memory = cast(Memory) devinfo.ram;
78         this.versionOs = cast(Version) devinfo.versions[nspire_version_index.NSPIRE_VER_OS];
79         this.versionBoot1 = cast(Version) devinfo.versions[nspire_version_index.NSPIRE_VER_BOOT1];
80         this.versionBoot2 = cast(Version) devinfo.versions[nspire_version_index.NSPIRE_VER_BOOT2];
81         this.hwType = cast(HWType) devinfo.hw_type;
82         this.isCharging = devinfo.batt.is_charging != 0;
83         this.batteryStatus = cast(Battery) devinfo.batt.status;
84         this.clockSpeed = devinfo.clock_speed;
85         this.lcd = cast(LCD) devinfo.lcd;
86         this.fileExtensions = cast(FileExtensions) devinfo.extensions;
87         this.deviceName = devinfo.device_name.dup;
88         this.electronicId = devinfo.electronic_id.dup;
89         this.runLevel = cast(RunLevel) devinfo.runlevel;
90     }
91 }