The field version of the solarnano grid on the ionQubes
Fork of SolarNanoGridv3 by
SolarNanoGrid.cpp
- Committer:
- defrost
- Date:
- 2016-05-09
- Revision:
- 2:929cf7fc6998
- Parent:
- 1:df924e0126d1
- Child:
- 3:350c167b9b2d
File content as of revision 2:929cf7fc6998:
#include "pinmap.h" #include "battery.h" #include "locker.h" #include "SolarNanoGrid.h" #define DEBUG #define INFOMESSAGES #define WARNMESSAGES #define ERRMESSAGES #ifdef DEBUG #define DBG(x, ...) printf("[SNG : DBG] "x"\r\n", ##__VA_ARGS__); #else #define DBG(x, ...) #endif #ifdef ERRMESSAGES #define ERR(x, ...) printf("[SNG : ERR] "x"\r\n", ##__VA_ARGS__); #else #define ERR(x, ...) #endif #ifdef WARNMESSAGES #define WARN(x, ...) printf("[SNG : WARN] "x"\r\n", ##__VA_ARGS__); #else #define WARN(x, ...) #endif #ifdef INFOMESSAGES #define INFO(x, ...) printf("[SNG : INFO] "x"\r\n", ##__VA_ARGS__); #else #define INFO(x, ...) #endif // Constructor: SolarNanoGrid::SolarNanoGrid(SDFileSystem* sd, DigitalOut* led_1, DigitalOut* led_2){ // Save the sd card pointer: _sd = sd; // initialize the SNG module: char * name = "/sd/config.ini"; FILE *fp; spiSD(); mkdir("/sd/binData",777); mkdir("/sd/data",777); mkdir("/sd/compress",777); //Configuration INFO("Reading config file..."); fp = fopen(name, "r"); if (fp == NULL) { ERR("Config file cannot be read"); return; } if (fscanf (fp,"%c %*c %*s",&role )!=1) WARN("Config: cannot read role"); if (fscanf (fp,"%d %*c %*s",&sdVersion )!=1) WARN("Config: cannot read version"); if (fscanf (fp,"%x %*c %*s",&id )!=1) WARN("Config: cannot read id"); id = 1; INFO(" Type:%c, Version %u, ID %d",role,sdVersion,id); switch (role) { case('B'): case('b'): SongBat = new battery(nrf1, nrf1Int, led_1, led_2); SongBat->initialiseBattery(fp); break; case('L'): case('l'): SongLock = new locker(nrf1, nrf1Int, led_1, led_2); SongLock->initialiseLocker(fp); break; } return; } void SolarNanoGrid::loop(void) { switch (role) { case('B'): { // Battery SongBat->loop(); break; } case('M'): { // Master // loopMaster(); break; } case('L'): { // Locker SongLock->loop(); break; } } } // Turns SPI on for SD card void SolarNanoGrid::spiSD(void) { //sd.select(); pin_function(PTE1 , 7); //Set SD_MISO as SPI, this is the same as the last number in those tables pin_function(PTD7, 1); //pin function 1 is GPIO return; } void SolarNanoGrid::spiNrf(void) { //sd.deselect(); pin_function(PTE1, 1); //pin function 1 is GPIO pin_function(PTD7, 7); //Set SD_MISO as SPI, this is the same as the last number in those tables return; }