The field version of the solarnano grid on the ionQubes
Fork of SolarNanoGridv3 by
SolarNanoGrid.cpp@2:929cf7fc6998, 2016-05-09 (annotated)
- Committer:
- defrost
- Date:
- Mon May 09 14:08:59 2016 +0000
- Revision:
- 2:929cf7fc6998
- Parent:
- 1:df924e0126d1
- Child:
- 3:350c167b9b2d
- battery, locker, and SNG class created; - can't communicate yet;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
defrost | 1:df924e0126d1 | 1 | #include "pinmap.h" |
defrost | 0:dc8a45ec969a | 2 | #include "battery.h" |
defrost | 0:dc8a45ec969a | 3 | #include "locker.h" |
defrost | 1:df924e0126d1 | 4 | #include "SolarNanoGrid.h" |
defrost | 1:df924e0126d1 | 5 | |
defrost | 1:df924e0126d1 | 6 | #define DEBUG |
defrost | 1:df924e0126d1 | 7 | #define INFOMESSAGES |
defrost | 1:df924e0126d1 | 8 | #define WARNMESSAGES |
defrost | 1:df924e0126d1 | 9 | #define ERRMESSAGES |
defrost | 1:df924e0126d1 | 10 | |
defrost | 1:df924e0126d1 | 11 | #ifdef DEBUG |
defrost | 1:df924e0126d1 | 12 | #define DBG(x, ...) printf("[SNG : DBG] "x"\r\n", ##__VA_ARGS__); |
defrost | 1:df924e0126d1 | 13 | #else |
defrost | 1:df924e0126d1 | 14 | #define DBG(x, ...) |
defrost | 1:df924e0126d1 | 15 | #endif |
defrost | 1:df924e0126d1 | 16 | |
defrost | 1:df924e0126d1 | 17 | #ifdef ERRMESSAGES |
defrost | 1:df924e0126d1 | 18 | #define ERR(x, ...) printf("[SNG : ERR] "x"\r\n", ##__VA_ARGS__); |
defrost | 1:df924e0126d1 | 19 | #else |
defrost | 1:df924e0126d1 | 20 | #define ERR(x, ...) |
defrost | 1:df924e0126d1 | 21 | #endif |
defrost | 1:df924e0126d1 | 22 | |
defrost | 1:df924e0126d1 | 23 | #ifdef WARNMESSAGES |
defrost | 1:df924e0126d1 | 24 | #define WARN(x, ...) printf("[SNG : WARN] "x"\r\n", ##__VA_ARGS__); |
defrost | 1:df924e0126d1 | 25 | #else |
defrost | 1:df924e0126d1 | 26 | #define WARN(x, ...) |
defrost | 1:df924e0126d1 | 27 | #endif |
defrost | 1:df924e0126d1 | 28 | |
defrost | 1:df924e0126d1 | 29 | #ifdef INFOMESSAGES |
defrost | 1:df924e0126d1 | 30 | #define INFO(x, ...) printf("[SNG : INFO] "x"\r\n", ##__VA_ARGS__); |
defrost | 1:df924e0126d1 | 31 | #else |
defrost | 1:df924e0126d1 | 32 | #define INFO(x, ...) |
defrost | 1:df924e0126d1 | 33 | #endif |
defrost | 1:df924e0126d1 | 34 | |
defrost | 1:df924e0126d1 | 35 | // Constructor: |
defrost | 2:929cf7fc6998 | 36 | SolarNanoGrid::SolarNanoGrid(SDFileSystem* sd, DigitalOut* led_1, DigitalOut* led_2){ |
defrost | 1:df924e0126d1 | 37 | // Save the sd card pointer: |
defrost | 1:df924e0126d1 | 38 | _sd = sd; |
defrost | 1:df924e0126d1 | 39 | |
defrost | 1:df924e0126d1 | 40 | // initialize the SNG module: |
defrost | 1:df924e0126d1 | 41 | char * name = "/sd/config.ini"; |
defrost | 1:df924e0126d1 | 42 | FILE *fp; |
defrost | 1:df924e0126d1 | 43 | spiSD(); |
defrost | 1:df924e0126d1 | 44 | mkdir("/sd/binData",777); |
defrost | 1:df924e0126d1 | 45 | mkdir("/sd/data",777); |
defrost | 1:df924e0126d1 | 46 | mkdir("/sd/compress",777); |
defrost | 1:df924e0126d1 | 47 | |
defrost | 1:df924e0126d1 | 48 | //Configuration |
defrost | 1:df924e0126d1 | 49 | |
defrost | 1:df924e0126d1 | 50 | INFO("Reading config file..."); |
defrost | 1:df924e0126d1 | 51 | |
defrost | 1:df924e0126d1 | 52 | fp = fopen(name, "r"); |
defrost | 1:df924e0126d1 | 53 | if (fp == NULL) { |
defrost | 1:df924e0126d1 | 54 | ERR("Config file cannot be read"); |
defrost | 1:df924e0126d1 | 55 | return; |
defrost | 1:df924e0126d1 | 56 | } |
defrost | 1:df924e0126d1 | 57 | if (fscanf (fp,"%c %*c %*s",&role )!=1) WARN("Config: cannot read role"); |
defrost | 1:df924e0126d1 | 58 | if (fscanf (fp,"%d %*c %*s",&sdVersion )!=1) WARN("Config: cannot read version"); |
defrost | 1:df924e0126d1 | 59 | if (fscanf (fp,"%x %*c %*s",&id )!=1) WARN("Config: cannot read id"); |
defrost | 1:df924e0126d1 | 60 | id = 1; |
defrost | 1:df924e0126d1 | 61 | |
defrost | 1:df924e0126d1 | 62 | INFO(" Type:%c, Version %u, ID %d",role,sdVersion,id); |
defrost | 1:df924e0126d1 | 63 | |
defrost | 1:df924e0126d1 | 64 | |
defrost | 1:df924e0126d1 | 65 | switch (role) { |
defrost | 1:df924e0126d1 | 66 | case('B'): |
defrost | 1:df924e0126d1 | 67 | case('b'): |
defrost | 2:929cf7fc6998 | 68 | SongBat = new battery(nrf1, nrf1Int, led_1, led_2); |
defrost | 2:929cf7fc6998 | 69 | SongBat->initialiseBattery(fp); |
defrost | 1:df924e0126d1 | 70 | break; |
defrost | 1:df924e0126d1 | 71 | case('L'): |
defrost | 1:df924e0126d1 | 72 | case('l'): |
defrost | 2:929cf7fc6998 | 73 | SongLock = new locker(nrf1, nrf1Int, led_1, led_2); |
defrost | 2:929cf7fc6998 | 74 | SongLock->initialiseLocker(fp); |
defrost | 1:df924e0126d1 | 75 | break; |
defrost | 1:df924e0126d1 | 76 | } |
defrost | 1:df924e0126d1 | 77 | |
defrost | 1:df924e0126d1 | 78 | return; |
defrost | 1:df924e0126d1 | 79 | } |
defrost | 1:df924e0126d1 | 80 | |
defrost | 1:df924e0126d1 | 81 | void SolarNanoGrid::loop(void) |
defrost | 1:df924e0126d1 | 82 | { |
defrost | 1:df924e0126d1 | 83 | switch (role) { |
defrost | 1:df924e0126d1 | 84 | case('B'): { // Battery |
defrost | 2:929cf7fc6998 | 85 | SongBat->loop(); |
defrost | 1:df924e0126d1 | 86 | break; |
defrost | 1:df924e0126d1 | 87 | } |
defrost | 1:df924e0126d1 | 88 | case('M'): { // Master |
defrost | 1:df924e0126d1 | 89 | // loopMaster(); |
defrost | 1:df924e0126d1 | 90 | break; |
defrost | 1:df924e0126d1 | 91 | } |
defrost | 1:df924e0126d1 | 92 | case('L'): { // Locker |
defrost | 2:929cf7fc6998 | 93 | SongLock->loop(); |
defrost | 1:df924e0126d1 | 94 | break; |
defrost | 1:df924e0126d1 | 95 | } |
defrost | 1:df924e0126d1 | 96 | } |
defrost | 1:df924e0126d1 | 97 | } |
defrost | 1:df924e0126d1 | 98 | |
defrost | 2:929cf7fc6998 | 99 | // Turns SPI on for SD card |
defrost | 2:929cf7fc6998 | 100 | void SolarNanoGrid::spiSD(void) |
defrost | 2:929cf7fc6998 | 101 | { |
defrost | 2:929cf7fc6998 | 102 | //sd.select(); |
defrost | 2:929cf7fc6998 | 103 | pin_function(PTE1 , 7); //Set SD_MISO as SPI, this is the same as the last number in those tables |
defrost | 2:929cf7fc6998 | 104 | pin_function(PTD7, 1); //pin function 1 is GPIO |
defrost | 2:929cf7fc6998 | 105 | return; |
defrost | 2:929cf7fc6998 | 106 | } |
defrost | 2:929cf7fc6998 | 107 | |
defrost | 2:929cf7fc6998 | 108 | void SolarNanoGrid::spiNrf(void) |
defrost | 2:929cf7fc6998 | 109 | { |
defrost | 2:929cf7fc6998 | 110 | //sd.deselect(); |
defrost | 2:929cf7fc6998 | 111 | pin_function(PTE1, 1); //pin function 1 is GPIO |
defrost | 2:929cf7fc6998 | 112 | pin_function(PTD7, 7); //Set SD_MISO as SPI, this is the same as the last number in those tables |
defrost | 2:929cf7fc6998 | 113 | return; |
defrost | 2:929cf7fc6998 | 114 | } |
defrost | 2:929cf7fc6998 | 115 |