The field version of the solarnano grid on the ionQubes
Fork of SolarNanoGridv3 by
Hmi/Hmi.cpp@36:a5620262f296, 2016-09-06 (annotated)
- Committer:
- defrost
- Date:
- Tue Sep 06 06:08:56 2016 +0000
- Revision:
- 36:a5620262f296
- Parent:
- 13:de43f28c0365
Turned off the charge rate update from hub
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
defrost | 5:57b06b4b47c6 | 1 | /** |
defrost | 5:57b06b4b47c6 | 2 | *@section DESCRIPTION |
defrost | 5:57b06b4b47c6 | 3 | * mbed SolarNanogrid Library |
defrost | 5:57b06b4b47c6 | 4 | * Hmi extends SolarNanoGrid. |
defrost | 5:57b06b4b47c6 | 5 | * Hmi does the human interface and talks to the lockers. |
defrost | 5:57b06b4b47c6 | 6 | * The ID must be in FF 00. |
defrost | 5:57b06b4b47c6 | 7 | *@section LICENSE |
defrost | 5:57b06b4b47c6 | 8 | * Copyright (c) 2016, Malcolm McCulloch |
defrost | 5:57b06b4b47c6 | 9 | * |
defrost | 5:57b06b4b47c6 | 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
defrost | 5:57b06b4b47c6 | 11 | * of this software and associated documentation files (the "Software"), to deal |
defrost | 5:57b06b4b47c6 | 12 | * in the Software without restriction, including without limitation the rights |
defrost | 5:57b06b4b47c6 | 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
defrost | 5:57b06b4b47c6 | 14 | * copies of the Software, and to permit persons to whom the Software is |
defrost | 5:57b06b4b47c6 | 15 | * furnished to do so, subject to the following conditions: |
defrost | 5:57b06b4b47c6 | 16 | * |
defrost | 5:57b06b4b47c6 | 17 | * The above copyright notice and this permission notice shall be included in |
defrost | 5:57b06b4b47c6 | 18 | * all copies or substantial portions of the Software. |
defrost | 5:57b06b4b47c6 | 19 | * |
defrost | 5:57b06b4b47c6 | 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
defrost | 5:57b06b4b47c6 | 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
defrost | 5:57b06b4b47c6 | 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
defrost | 5:57b06b4b47c6 | 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
defrost | 5:57b06b4b47c6 | 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
defrost | 5:57b06b4b47c6 | 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
defrost | 5:57b06b4b47c6 | 26 | * THE SOFTWARE. |
defrost | 5:57b06b4b47c6 | 27 | * @file "Hmi.c" |
defrost | 5:57b06b4b47c6 | 28 | */ |
epgmdm | 11:87ab310924f0 | 29 | #include <Hmi/Hmi.h> |
defrost | 13:de43f28c0365 | 30 | #define FUNCNAME "HMI" |
defrost | 13:de43f28c0365 | 31 | #include "defs.h" |
defrost | 5:57b06b4b47c6 | 32 | |
epgmdm | 11:87ab310924f0 | 33 | Hmi::Hmi(FILE* fp, Serial *pc) : |
epgmdm | 11:87ab310924f0 | 34 | SolarNanoGrid(fp,pc) { |
defrost | 5:57b06b4b47c6 | 35 | DBG("Initialize class"); |
defrost | 5:57b06b4b47c6 | 36 | // No other information needed from the config file |
defrost | 5:57b06b4b47c6 | 37 | fclose(fp); |
defrost | 5:57b06b4b47c6 | 38 | |
epgmdm | 11:87ab310924f0 | 39 | DBG("Create hardware"); |
epgmdm | 11:87ab310924f0 | 40 | // |
epgmdm | 11:87ab310924f0 | 41 | // Create Hardware |
epgmdm | 11:87ab310924f0 | 42 | // |
epgmdm | 11:87ab310924f0 | 43 | // |
epgmdm | 11:87ab310924f0 | 44 | // Setup NRF |
epgmdm | 11:87ab310924f0 | 45 | // |
epgmdm | 11:87ab310924f0 | 46 | baseAddr = ((long long) communityID << 16) + (id & 0XFFFF); |
epgmdm | 11:87ab310924f0 | 47 | utilityAddr = baseAddr & 0XFFFFFF0000 | 0xFE00; |
epgmdm | 11:87ab310924f0 | 48 | //utilityAddr = 0x26c1e10100; |
defrost | 13:de43f28c0365 | 49 | DBG(" Channel:%x, Address %llx Utility Address %llx", chan, baseAddr, utilityAddr); |
epgmdm | 11:87ab310924f0 | 50 | |
epgmdm | 11:87ab310924f0 | 51 | spiNRF(); |
epgmdm | 11:87ab310924f0 | 52 | nrf->quickTxSetup(chan, utilityAddr); |
epgmdm | 11:87ab310924f0 | 53 | nrf->setRadio(0x01, 0x03); // 2MB/S 0dB |
epgmdm | 11:87ab310924f0 | 54 | nrf->setTxRetry(0x0F, 0x0F); |
epgmdm | 11:87ab310924f0 | 55 | nrfFlush(); |
epgmdm | 11:87ab310924f0 | 56 | DBG("Nrf Details:"); |
epgmdm | 11:87ab310924f0 | 57 | #ifdef DEBUG |
epgmdm | 11:87ab310924f0 | 58 | nrf->printDetails(); |
epgmdm | 11:87ab310924f0 | 59 | #endif |
epgmdm | 11:87ab310924f0 | 60 | // spiNRF(); |
epgmdm | 11:87ab310924f0 | 61 | // sprintf(dataTx,"Testing"); |
epgmdm | 11:87ab310924f0 | 62 | // DBG("Send :%s",dataTx); |
epgmdm | 11:87ab310924f0 | 63 | // nrf->transmitData(dataTx,strlen(dataTx)); |
epgmdm | 11:87ab310924f0 | 64 | |
epgmdm | 11:87ab310924f0 | 65 | DBG("Create hardware RFID"); |
epgmdm | 11:87ab310924f0 | 66 | // RFID |
epgmdm | 11:87ab310924f0 | 67 | BatteryRfChipH = new MFRC522(PTD2, PTD3, PTD1, PTB2, PTB3); |
epgmdm | 11:87ab310924f0 | 68 | PoshoRfChipH = new MFRC522 (PTD2, PTD3, PTD1, PTB10, PTB11); |
epgmdm | 11:87ab310924f0 | 69 | IncubatorRfChipH = new MFRC522 (PTD2, PTD3, PTD1, PTC11, PTC10); |
epgmdm | 11:87ab310924f0 | 70 | |
epgmdm | 11:87ab310924f0 | 71 | DBG("Create hardware TFT"); |
epgmdm | 11:87ab310924f0 | 72 | //Screen |
epgmdm | 11:87ab310924f0 | 73 | TFT_H = new SPI_TFT_ILI9341(PTD2, PTD3, PTD1, PTE25, PTB20, PTB18,"TFT"); /**< LCD Display */ |
epgmdm | 11:87ab310924f0 | 74 | |
epgmdm | 11:87ab310924f0 | 75 | DBG("Create hardware Buttons"); |
epgmdm | 11:87ab310924f0 | 76 | // Buttons |
epgmdm | 11:87ab310924f0 | 77 | buttonOneH= new InterruptIn(PTC3); // Button one interrupt |
epgmdm | 11:87ab310924f0 | 78 | buttonTwoH = new InterruptIn (PTC2); // Button two interrupt |
epgmdm | 11:87ab310924f0 | 79 | buttonThreeH = new InterruptIn (PTA2); // Button three interrupt |
epgmdm | 11:87ab310924f0 | 80 | buttonFourH = new InterruptIn (PTB23); // Button four interrupt |
epgmdm | 11:87ab310924f0 | 81 | |
epgmdm | 11:87ab310924f0 | 82 | DBG("Create hardware Tickers"); |
epgmdm | 11:87ab310924f0 | 83 | // Create Timers |
epgmdm | 11:87ab310924f0 | 84 | tick1sHub = new Ticker(); /**< Every second time check */ |
epgmdm | 11:87ab310924f0 | 85 | tickBatteryRfidH = new Ticker(); /**< Battery Rfid check */ |
epgmdm | 11:87ab310924f0 | 86 | tickIncubatorRfidH = new Ticker(); /**< Incubator Rfid check */ |
epgmdm | 11:87ab310924f0 | 87 | tickPoshoRfidH = new Ticker(); /**< Posho Rfid check */ |
epgmdm | 11:87ab310924f0 | 88 | tickTimeCheckH = new Ticker(); /**< Time check for terminal display */ |
epgmdm | 11:87ab310924f0 | 89 | tickerUpdateUserTableH = new Ticker(); /**< Update user table to SD card ticker (every 30 min) */ |
epgmdm | 11:87ab310924f0 | 90 | |
epgmdm | 11:87ab310924f0 | 91 | |
epgmdm | 11:87ab310924f0 | 92 | |
epgmdm | 11:87ab310924f0 | 93 | spiSD(); |
epgmdm | 11:87ab310924f0 | 94 | DBG("Initialise flags"); |
epgmdm | 11:87ab310924f0 | 95 | // |
epgmdm | 11:87ab310924f0 | 96 | // Initialise flags |
epgmdm | 11:87ab310924f0 | 97 | // |
epgmdm | 11:87ab310924f0 | 98 | |
epgmdm | 11:87ab310924f0 | 99 | flagBatteryRfidH =0 ; /**< Battery Rfid flag */ |
epgmdm | 11:87ab310924f0 | 100 | flagButtonOneH = 0; /**< Button one flag */ |
epgmdm | 11:87ab310924f0 | 101 | flagButtonTwoH = 0; /**< Button two flag */ |
epgmdm | 11:87ab310924f0 | 102 | flagButtonThreeH = 0; /**< Button three flag */ |
epgmdm | 11:87ab310924f0 | 103 | flagButtonFourH = 0; /**< Button four flag */ |
epgmdm | 11:87ab310924f0 | 104 | flagPoshoRfidH =0; /**< Posho Rfid flag */ |
epgmdm | 11:87ab310924f0 | 105 | flagIncubatorRfidH =0; /**< Incubator Rfid flag */ |
epgmdm | 11:87ab310924f0 | 106 | flagTimeCheckH = 0; |
epgmdm | 11:87ab310924f0 | 107 | flagUpdateUserTableH = 0; /**< Update user table to SD card ticker */ |
epgmdm | 11:87ab310924f0 | 108 | flag1sH = 0; /**< Every second flag */ |
epgmdm | 11:87ab310924f0 | 109 | |
epgmdm | 11:87ab310924f0 | 110 | |
epgmdm | 11:87ab310924f0 | 111 | DBG("Initialise variables"); |
epgmdm | 11:87ab310924f0 | 112 | // |
epgmdm | 11:87ab310924f0 | 113 | // Initialise variables |
epgmdm | 11:87ab310924f0 | 114 | // |
epgmdm | 11:87ab310924f0 | 115 | |
epgmdm | 11:87ab310924f0 | 116 | currentScreenH = initialScanRfid; |
epgmdm | 11:87ab310924f0 | 117 | currentMaxH = 1.5; |
epgmdm | 11:87ab310924f0 | 118 | userCountH = 0; /**< Number of active users on this hub mbed */ |
epgmdm | 11:87ab310924f0 | 119 | currentUserH=0; /**< Index of the current user */ |
epgmdm | 11:87ab310924f0 | 120 | |
epgmdm | 11:87ab310924f0 | 121 | DBG("Initialise variables Posho"); |
epgmdm | 11:87ab310924f0 | 122 | poshoPricePerKgH = -1; /**< price per kg of material to be used with the posho */ |
epgmdm | 11:87ab310924f0 | 123 | timeForOneKgH = 0; /**< time for one kg of material to be used with the posho */ |
epgmdm | 11:87ab310924f0 | 124 | timeForTwoKgH = 0; /**< time for two kg of material to be used with the posho */ |
epgmdm | 11:87ab310924f0 | 125 | timeForThreeKgH=0; /**< time for three kg of material to be used with the posho */ |
epgmdm | 11:87ab310924f0 | 126 | |
epgmdm | 11:87ab310924f0 | 127 | flagPoshoAlreadyInUseH = 0; |
epgmdm | 11:87ab310924f0 | 128 | |
epgmdm | 11:87ab310924f0 | 129 | allUsersH = (HubUser *)calloc(256, sizeof(HubUser)); |
epgmdm | 11:87ab310924f0 | 130 | |
epgmdm | 11:87ab310924f0 | 131 | |
epgmdm | 11:87ab310924f0 | 132 | |
epgmdm | 11:87ab310924f0 | 133 | // |
epgmdm | 11:87ab310924f0 | 134 | // Initialise Hardware |
epgmdm | 11:87ab310924f0 | 135 | // |
epgmdm | 11:87ab310924f0 | 136 | |
epgmdm | 11:87ab310924f0 | 137 | DBG("Initialise hardware RFID"); |
epgmdm | 11:87ab310924f0 | 138 | //RFID |
epgmdm | 11:87ab310924f0 | 139 | |
epgmdm | 11:87ab310924f0 | 140 | BatteryRfChipH->PCD_Init(); |
epgmdm | 11:87ab310924f0 | 141 | PoshoRfChipH->PCD_Init(); |
epgmdm | 11:87ab310924f0 | 142 | IncubatorRfChipH->PCD_Init(); |
epgmdm | 11:87ab310924f0 | 143 | |
epgmdm | 11:87ab310924f0 | 144 | |
epgmdm | 11:87ab310924f0 | 145 | uint8_t tempA = BatteryRfChipH->PCD_ReadRegister(MFRC522::VersionReg); |
epgmdm | 11:87ab310924f0 | 146 | DBG("Battery MFRC522 version: %d\n\r", tempA & 0x07); |
epgmdm | 11:87ab310924f0 | 147 | uint8_t tempB = PoshoRfChipH->PCD_ReadRegister(MFRC522::VersionReg); |
epgmdm | 11:87ab310924f0 | 148 | DBG("Posho MFRC522 version: %d\n\r", tempB & 0x07); |
epgmdm | 11:87ab310924f0 | 149 | uint8_t tempC = IncubatorRfChipH->PCD_ReadRegister(MFRC522::VersionReg); |
epgmdm | 11:87ab310924f0 | 150 | DBG("Incubator MFRC522 version: %d\n\r", tempC & 0x07); |
epgmdm | 11:87ab310924f0 | 151 | |
epgmdm | 11:87ab310924f0 | 152 | DBG("Initialise hardware TFT"); |
epgmdm | 11:87ab310924f0 | 153 | // TFT Screen |
epgmdm | 11:87ab310924f0 | 154 | TFT_H->background(Black); // set background to black |
epgmdm | 11:87ab310924f0 | 155 | TFT_H->foreground(White); // set chars to white |
epgmdm | 11:87ab310924f0 | 156 | TFT_H->cls(); // clear the screen |
epgmdm | 11:87ab310924f0 | 157 | TFT_H->set_font((unsigned char*) Arial24x23); |
epgmdm | 11:87ab310924f0 | 158 | TFT_H->set_orientation(3); //Portrait, wiring on left |
epgmdm | 11:87ab310924f0 | 159 | |
epgmdm | 11:87ab310924f0 | 160 | // |
epgmdm | 11:87ab310924f0 | 161 | // Attach interrupts |
epgmdm | 11:87ab310924f0 | 162 | // |
epgmdm | 11:87ab310924f0 | 163 | DBG("Attach interrupts Buttons"); |
epgmdm | 11:87ab310924f0 | 164 | // Buttons |
epgmdm | 11:87ab310924f0 | 165 | buttonOneH->rise(this, &Hmi::interruptButtonOneH); |
epgmdm | 11:87ab310924f0 | 166 | buttonTwoH->rise(this, &Hmi::interruptButtonTwoH); |
epgmdm | 11:87ab310924f0 | 167 | buttonThreeH->rise(this, &Hmi::interruptButtonThreeH); |
epgmdm | 11:87ab310924f0 | 168 | buttonFourH->rise(this, &Hmi::interruptButtonFourH); |
epgmdm | 11:87ab310924f0 | 169 | |
epgmdm | 11:87ab310924f0 | 170 | DBG("Attach interrupts Timers"); |
epgmdm | 11:87ab310924f0 | 171 | //Timers |
epgmdm | 11:87ab310924f0 | 172 | tick1sHub->attach(this, &Hmi::int1sH, 10.0); |
epgmdm | 11:87ab310924f0 | 173 | tickBatteryRfidH->attach(this, &Hmi::interruptBatteryRfidH, 1.0); |
epgmdm | 11:87ab310924f0 | 174 | tickIncubatorRfidH->attach(this, &Hmi::interruptIncubatorRfidH, 1.0); |
epgmdm | 11:87ab310924f0 | 175 | tickPoshoRfidH->attach(this, &Hmi::interruptPoshoRfidH, 1.0); |
epgmdm | 11:87ab310924f0 | 176 | tickTimeCheckH->attach(this, &Hmi::interruptTimeCheckH, 5.0); |
epgmdm | 11:87ab310924f0 | 177 | tickerUpdateUserTableH->attach(this, &Hmi::interruptUpdateUserTableH, 1800.0); |
epgmdm | 11:87ab310924f0 | 178 | |
epgmdm | 11:87ab310924f0 | 179 | |
epgmdm | 11:87ab310924f0 | 180 | DBG("Posho "); |
epgmdm | 11:87ab310924f0 | 181 | //while (poshoPricePerKgH == -1) |
epgmdm | 11:87ab310924f0 | 182 | initializePoshoFunctionalityH(); |
epgmdm | 11:87ab310924f0 | 183 | DBG("Users "); |
epgmdm | 11:87ab310924f0 | 184 | initializeUsersFromSD_H(); |
epgmdm | 11:87ab310924f0 | 185 | |
epgmdm | 11:87ab310924f0 | 186 | loopHub(); |
defrost | 5:57b06b4b47c6 | 187 | } |
epgmdm | 11:87ab310924f0 | 188 | |
epgmdm | 11:87ab310924f0 | 189 | /** |
epgmdm | 11:87ab310924f0 | 190 | * Creates a new user by defining user attributes. |
epgmdm | 11:87ab310924f0 | 191 | * @param rfid - uint32_t corresponding to unique id of the RFID tag |
epgmdm | 11:87ab310924f0 | 192 | * @param accountCredit - int32 for user account balance (can be negative) |
epgmdm | 11:87ab310924f0 | 193 | * @param locker - int32_t for which locker (originaly 1-4) user is assigned |
epgmdm | 11:87ab310924f0 | 194 | * @param batterySubscription - int32_t max batteries user can get (can be 0) |
epgmdm | 11:87ab310924f0 | 195 | * @param batteriesOut - int32_t number of batteries user has out (usually 0 initially) |
epgmdm | 11:87ab310924f0 | 196 | * @param pod - int32_t pod associated with the user (originally 0-15) *must be 0 indexed* |
epgmdm | 11:87ab310924f0 | 197 | */ |
epgmdm | 11:87ab310924f0 | 198 | void Hmi::createNewUserH(uint32_t rfid, int32_t accountCredit, int32_t locker, |
epgmdm | 11:87ab310924f0 | 199 | int32_t batterySubscription, int32_t batteriesOut, int32_t pod, char* name) |
epgmdm | 11:87ab310924f0 | 200 | { |
epgmdm | 11:87ab310924f0 | 201 | // uid: [community byte][community byte][locker byte][podID (1/2 byte) | 0000 (1/2 byte)] |
epgmdm | 11:87ab310924f0 | 202 | uint32_t actualUid = ((((uint32_t)communityID << 16) | ((uint32_t)locker << 8)) | |
epgmdm | 11:87ab310924f0 | 203 | ((uint32_t)pod << 4)); |
epgmdm | 11:87ab310924f0 | 204 | |
epgmdm | 11:87ab310924f0 | 205 | allUsersH[userCountH] = HubUser(actualUid, rfid, accountCredit, locker, |
epgmdm | 11:87ab310924f0 | 206 | pod, batteriesOut, batterySubscription, name); |
epgmdm | 11:87ab310924f0 | 207 | userCountH++; |
epgmdm | 11:87ab310924f0 | 208 | |
epgmdm | 11:87ab310924f0 | 209 | DBG("rfid: %u accountCredit: %d", rfid,accountCredit); |
epgmdm | 11:87ab310924f0 | 210 | DBG("UserID (hex):%x Name: %s", actualUid,name); |
epgmdm | 11:87ab310924f0 | 211 | DBG("locker: %d pod: %d ", locker,pod); |
epgmdm | 11:87ab310924f0 | 212 | DBG("batterySubscription: %d batteriesOut: %d", batterySubscription, batteriesOut); |
epgmdm | 11:87ab310924f0 | 213 | |
epgmdm | 11:87ab310924f0 | 214 | } |
epgmdm | 11:87ab310924f0 | 215 | |
epgmdm | 11:87ab310924f0 | 216 | /** |
epgmdm | 11:87ab310924f0 | 217 | * Initialize Global User Table Variable with malloc |
epgmdm | 11:87ab310924f0 | 218 | * @param users - int representing how many users you want the system to hold |
epgmdm | 11:87ab310924f0 | 219 | */ |
epgmdm | 11:87ab310924f0 | 220 | void Hmi::initializeGlobalUserTableH(int users) |
epgmdm | 11:87ab310924f0 | 221 | { |
epgmdm | 11:87ab310924f0 | 222 | allUsersH = (HubUser *)calloc(users, sizeof(HubUser)); |
epgmdm | 11:87ab310924f0 | 223 | } |
epgmdm | 11:87ab310924f0 | 224 | /** |
epgmdm | 11:87ab310924f0 | 225 | * Initialize posho functionality |
epgmdm | 11:87ab310924f0 | 226 | */ |
epgmdm | 11:87ab310924f0 | 227 | void Hmi::initializePoshoFunctionalityH() |
epgmdm | 11:87ab310924f0 | 228 | { |
epgmdm | 11:87ab310924f0 | 229 | spiSD(); |
epgmdm | 11:87ab310924f0 | 230 | FILE *fp = fopen("/sd/poshoInit.txt", "r"); |
epgmdm | 11:87ab310924f0 | 231 | |
epgmdm | 11:87ab310924f0 | 232 | if (fp == NULL) { |
epgmdm | 11:87ab310924f0 | 233 | WARN("Posho text file can't be opened"); |
epgmdm | 11:87ab310924f0 | 234 | return; |
epgmdm | 11:87ab310924f0 | 235 | } |
epgmdm | 11:87ab310924f0 | 236 | |
epgmdm | 11:87ab310924f0 | 237 | |
epgmdm | 11:87ab310924f0 | 238 | |
epgmdm | 11:87ab310924f0 | 239 | if (fscanf(fp,"%d %*c %*s",&poshoPricePerKgH)!= 1) ERR("Posho: cannot read price"); |
epgmdm | 11:87ab310924f0 | 240 | if (fscanf(fp,"%d %*c %*s",&timeForOneKgH)!= 1) ERR("Posho: cannot read time"); |
epgmdm | 11:87ab310924f0 | 241 | if (fscanf(fp,"%d %*c %*s",&timeForTwoKgH)!= 1) ERR("Posho: cannot read time"); |
epgmdm | 11:87ab310924f0 | 242 | if (fscanf(fp,"%d %*c %*s",&timeForThreeKgH)!= 1) ERR("Posho: cannot read time"); |
epgmdm | 11:87ab310924f0 | 243 | fclose(fp); |
epgmdm | 11:87ab310924f0 | 244 | |
epgmdm | 11:87ab310924f0 | 245 | DBG("Posho values initialized\n\r"); |
epgmdm | 11:87ab310924f0 | 246 | DBG("Price per kg: %d\n\r", poshoPricePerKgH); |
epgmdm | 11:87ab310924f0 | 247 | DBG("Time 1: %d, 2: %d, and 3: %d\n\r", timeForOneKgH, timeForTwoKgH, timeForThreeKgH); |
epgmdm | 11:87ab310924f0 | 248 | } |
epgmdm | 11:87ab310924f0 | 249 | |
epgmdm | 11:87ab310924f0 | 250 | /** |
epgmdm | 11:87ab310924f0 | 251 | * Initialize system with users from users.txt on SD card |
epgmdm | 11:87ab310924f0 | 252 | */ |
epgmdm | 11:87ab310924f0 | 253 | void Hmi::initializeUsersFromSD_H() |
epgmdm | 11:87ab310924f0 | 254 | { |
epgmdm | 11:87ab310924f0 | 255 | spiSD(); |
epgmdm | 11:87ab310924f0 | 256 | FILE *fp = fopen("/sd/users.txt", "r"); |
epgmdm | 11:87ab310924f0 | 257 | if (fp == NULL) { |
epgmdm | 11:87ab310924f0 | 258 | |
epgmdm | 11:87ab310924f0 | 259 | WARN("User text file can't be opened\n\r"); |
epgmdm | 11:87ab310924f0 | 260 | |
epgmdm | 11:87ab310924f0 | 261 | return; |
epgmdm | 11:87ab310924f0 | 262 | } |
epgmdm | 11:87ab310924f0 | 263 | |
epgmdm | 11:87ab310924f0 | 264 | // first line of the user file has the headers - get to the next line |
epgmdm | 11:87ab310924f0 | 265 | char line[180]; |
epgmdm | 11:87ab310924f0 | 266 | if (fgets(line, 100, fp) != NULL) { |
epgmdm | 11:87ab310924f0 | 267 | |
epgmdm | 11:87ab310924f0 | 268 | DBG("user.txt: Format of text file:|%s|", line); |
epgmdm | 11:87ab310924f0 | 269 | |
epgmdm | 11:87ab310924f0 | 270 | } |
epgmdm | 11:87ab310924f0 | 271 | |
epgmdm | 11:87ab310924f0 | 272 | // read a set of six values at a time, corresponding to a line, from the user text file |
epgmdm | 11:87ab310924f0 | 273 | uint32_t rfid; |
epgmdm | 11:87ab310924f0 | 274 | int32_t accountCredit; |
epgmdm | 11:87ab310924f0 | 275 | int32_t locker; |
epgmdm | 11:87ab310924f0 | 276 | int32_t batterySubscription; |
epgmdm | 11:87ab310924f0 | 277 | int32_t batteriesOut; |
epgmdm | 11:87ab310924f0 | 278 | int32_t pod; |
epgmdm | 11:87ab310924f0 | 279 | char* name; |
epgmdm | 11:87ab310924f0 | 280 | |
epgmdm | 11:87ab310924f0 | 281 | while(fgets(line, 100, fp) != NULL){ |
epgmdm | 11:87ab310924f0 | 282 | //DBG("Line = [%s]",line); |
epgmdm | 11:87ab310924f0 | 283 | name = (char *) calloc(32,1); |
epgmdm | 11:87ab310924f0 | 284 | // rfid Credit lckr pod maxBatt outBatt Name |
epgmdm | 11:87ab310924f0 | 285 | sscanf(line, "%u %d %d %d %d %d %s", &rfid, &accountCredit, &locker, &pod, |
epgmdm | 11:87ab310924f0 | 286 | &batterySubscription, &batteriesOut, name); |
epgmdm | 11:87ab310924f0 | 287 | createNewUserH(rfid, accountCredit, locker, batterySubscription, batteriesOut, pod,name); |
epgmdm | 11:87ab310924f0 | 288 | //| Rfid number (%d) | Community ID (%d) |Locker ID (%d) |Pod ID (%d)| Battery Subscriptton(%d)| Battery Out| Name |
epgmdm | 11:87ab310924f0 | 289 | } |
epgmdm | 11:87ab310924f0 | 290 | fclose(fp); |
epgmdm | 11:87ab310924f0 | 291 | } |
epgmdm | 11:87ab310924f0 | 292 | /*************************************************************************************************/ |
epgmdm | 11:87ab310924f0 | 293 | /* Set a flag when an interrupt is detected */ |
epgmdm | 11:87ab310924f0 | 294 | /*************************************************************************************************/ |
epgmdm | 11:87ab310924f0 | 295 | /** |
epgmdm | 11:87ab310924f0 | 296 | * Time check interrupt |
epgmdm | 11:87ab310924f0 | 297 | */ |
epgmdm | 11:87ab310924f0 | 298 | void Hmi::interruptTimeCheckH() |
epgmdm | 11:87ab310924f0 | 299 | { flagTimeCheckH = 1; } |
epgmdm | 11:87ab310924f0 | 300 | |
epgmdm | 11:87ab310924f0 | 301 | /** |
epgmdm | 11:87ab310924f0 | 302 | * Update user table interrupt |
epgmdm | 11:87ab310924f0 | 303 | */ |
epgmdm | 11:87ab310924f0 | 304 | void Hmi::interruptUpdateUserTableH() |
epgmdm | 11:87ab310924f0 | 305 | { flagUpdateUserTableH = 1; } |
epgmdm | 11:87ab310924f0 | 306 | |
epgmdm | 11:87ab310924f0 | 307 | /** |
epgmdm | 11:87ab310924f0 | 308 | * Battery RFID reader interrupt |
epgmdm | 11:87ab310924f0 | 309 | */ |
epgmdm | 11:87ab310924f0 | 310 | void Hmi::interruptBatteryRfidH() |
epgmdm | 11:87ab310924f0 | 311 | { flagBatteryRfidH = 1; } |
epgmdm | 11:87ab310924f0 | 312 | |
epgmdm | 11:87ab310924f0 | 313 | /** |
epgmdm | 11:87ab310924f0 | 314 | * Posho RFID reader interrupt |
epgmdm | 11:87ab310924f0 | 315 | */ |
epgmdm | 11:87ab310924f0 | 316 | void Hmi::interruptPoshoRfidH() |
epgmdm | 11:87ab310924f0 | 317 | { flagPoshoRfidH = 1; } |
epgmdm | 11:87ab310924f0 | 318 | |
epgmdm | 11:87ab310924f0 | 319 | /** |
epgmdm | 11:87ab310924f0 | 320 | * Incubator RFID reader interrupt |
epgmdm | 11:87ab310924f0 | 321 | */ |
epgmdm | 11:87ab310924f0 | 322 | void Hmi::interruptIncubatorRfidH() |
epgmdm | 11:87ab310924f0 | 323 | { flagIncubatorRfidH = 1; } |
epgmdm | 11:87ab310924f0 | 324 | |
epgmdm | 11:87ab310924f0 | 325 | /** |
epgmdm | 11:87ab310924f0 | 326 | * buttone one interrupt |
epgmdm | 11:87ab310924f0 | 327 | */ |
epgmdm | 11:87ab310924f0 | 328 | void Hmi::interruptButtonOneH() |
epgmdm | 11:87ab310924f0 | 329 | { flagButtonOneH = 1; } |
epgmdm | 11:87ab310924f0 | 330 | |
epgmdm | 11:87ab310924f0 | 331 | /** |
epgmdm | 11:87ab310924f0 | 332 | * buttone two interrupt |
epgmdm | 11:87ab310924f0 | 333 | */ |
epgmdm | 11:87ab310924f0 | 334 | void Hmi::interruptButtonTwoH() |
epgmdm | 11:87ab310924f0 | 335 | { flagButtonTwoH = 1; } |
epgmdm | 11:87ab310924f0 | 336 | |
epgmdm | 11:87ab310924f0 | 337 | /** |
epgmdm | 11:87ab310924f0 | 338 | * buttone three interrupt |
epgmdm | 11:87ab310924f0 | 339 | */ |
epgmdm | 11:87ab310924f0 | 340 | void Hmi::interruptButtonThreeH() |
epgmdm | 11:87ab310924f0 | 341 | { flagButtonThreeH = 1; } |
epgmdm | 11:87ab310924f0 | 342 | |
epgmdm | 11:87ab310924f0 | 343 | /** |
epgmdm | 11:87ab310924f0 | 344 | * buttone four interrupt |
epgmdm | 11:87ab310924f0 | 345 | */ |
epgmdm | 11:87ab310924f0 | 346 | void Hmi::interruptButtonFourH() |
epgmdm | 11:87ab310924f0 | 347 | { flagButtonFourH = 1; } |
epgmdm | 11:87ab310924f0 | 348 | |
epgmdm | 11:87ab310924f0 | 349 | /** |
epgmdm | 11:87ab310924f0 | 350 | * Fast interrupt routine for every 1 second |
epgmdm | 11:87ab310924f0 | 351 | */ |
epgmdm | 11:87ab310924f0 | 352 | void Hmi::int1sH() |
epgmdm | 11:87ab310924f0 | 353 | { flag1sH=1; } |
epgmdm | 11:87ab310924f0 | 354 | |
epgmdm | 11:87ab310924f0 | 355 | /** |
epgmdm | 11:87ab310924f0 | 356 | * interrupt to clear the posho is in use flag after a designated time |
epgmdm | 11:87ab310924f0 | 357 | */ |
epgmdm | 11:87ab310924f0 | 358 | void Hmi::interruptPoshoInUseClearH() |
epgmdm | 11:87ab310924f0 | 359 | { |
epgmdm | 11:87ab310924f0 | 360 | flagPoshoAlreadyInUseH = 0; |
epgmdm | 11:87ab310924f0 | 361 | tickPoshoInUseClearH.detach(); |
epgmdm | 11:87ab310924f0 | 362 | } |
epgmdm | 11:87ab310924f0 | 363 | |
epgmdm | 11:87ab310924f0 | 364 | /*************************************************************************************************/ |
epgmdm | 11:87ab310924f0 | 365 | /* |
epgmdm | 11:87ab310924f0 | 366 | * Reset all user initiated flags. Useful after sequences of events where flags may have |
epgmdm | 11:87ab310924f0 | 367 | * piled up from misc inputs and you don't want the system to act seemingly sporadically. |
epgmdm | 11:87ab310924f0 | 368 | */ |
epgmdm | 11:87ab310924f0 | 369 | void Hmi::clearAllUserInitiatedFlagsH() |
epgmdm | 11:87ab310924f0 | 370 | { |
epgmdm | 11:87ab310924f0 | 371 | flagButtonOneH = 0; |
epgmdm | 11:87ab310924f0 | 372 | flagButtonTwoH = 0; |
epgmdm | 11:87ab310924f0 | 373 | flagButtonThreeH = 0; |
epgmdm | 11:87ab310924f0 | 374 | flagButtonFourH = 0; |
epgmdm | 11:87ab310924f0 | 375 | flagBatteryRfidH = 0; |
epgmdm | 11:87ab310924f0 | 376 | flagPoshoRfidH = 0; |
epgmdm | 11:87ab310924f0 | 377 | flagIncubatorRfidH = 0; |
epgmdm | 11:87ab310924f0 | 378 | } |
epgmdm | 11:87ab310924f0 | 379 | |
epgmdm | 11:87ab310924f0 | 380 | /* |
epgmdm | 11:87ab310924f0 | 381 | * User presses the button corresponding to an exit. Returns to home screen |
epgmdm | 11:87ab310924f0 | 382 | * after logging the action. |
epgmdm | 11:87ab310924f0 | 383 | * @param userIndex - int representing index of user in user table |
epgmdm | 11:87ab310924f0 | 384 | */ |
epgmdm | 11:87ab310924f0 | 385 | void Hmi::cancelPressedH(int userIndex) |
epgmdm | 11:87ab310924f0 | 386 | { |
epgmdm | 11:87ab310924f0 | 387 | clearAllUserInitiatedFlagsH(); |
epgmdm | 11:87ab310924f0 | 388 | currentScreenH = initialScanRfid; |
epgmdm | 11:87ab310924f0 | 389 | logActionWithUserInfo(hubAction_Exit, &allUsersH[userIndex]); |
epgmdm | 11:87ab310924f0 | 390 | } |
epgmdm | 11:87ab310924f0 | 391 | |
epgmdm | 11:87ab310924f0 | 392 | /** |
epgmdm | 11:87ab310924f0 | 393 | * Do if time check flag is set |
epgmdm | 11:87ab310924f0 | 394 | * reads the unix time, converts into human readable format, and displays on PC |
epgmdm | 11:87ab310924f0 | 395 | */ |
epgmdm | 11:87ab310924f0 | 396 | void Hmi::doTimeCheckH() |
epgmdm | 11:87ab310924f0 | 397 | { |
epgmdm | 11:87ab310924f0 | 398 | flagTimeCheckH = 0; |
epgmdm | 11:87ab310924f0 | 399 | time_t seconds = time(NULL); |
epgmdm | 11:87ab310924f0 | 400 | INFO("%s\n\r", ctime(&seconds)); |
epgmdm | 11:87ab310924f0 | 401 | // spiNRF(); |
epgmdm | 11:87ab310924f0 | 402 | // sprintf(dataTx,"hello 1 1"); |
epgmdm | 11:87ab310924f0 | 403 | // DBG("Send :%s",dataTx); |
epgmdm | 11:87ab310924f0 | 404 | // nrf->transmitData(dataTx,strlen(dataTx)); |
epgmdm | 11:87ab310924f0 | 405 | } |
epgmdm | 11:87ab310924f0 | 406 | |
epgmdm | 11:87ab310924f0 | 407 | /** |
epgmdm | 11:87ab310924f0 | 408 | * Do if update user table flag is set |
epgmdm | 11:87ab310924f0 | 409 | */ |
epgmdm | 11:87ab310924f0 | 410 | void Hmi::doUpdateUserTableH() |
epgmdm | 11:87ab310924f0 | 411 | { |
epgmdm | 11:87ab310924f0 | 412 | DBG("doUpdateUserTableH"); |
epgmdm | 11:87ab310924f0 | 413 | |
epgmdm | 11:87ab310924f0 | 414 | flagUpdateUserTableH = 0; |
epgmdm | 11:87ab310924f0 | 415 | // Write to a users.txt file |
epgmdm | 11:87ab310924f0 | 416 | spiSD(); |
epgmdm | 11:87ab310924f0 | 417 | char * name = "/sd/users.txt"; |
epgmdm | 11:87ab310924f0 | 418 | FILE *fp; |
epgmdm | 11:87ab310924f0 | 419 | fp = fopen(name, "w"); |
epgmdm | 11:87ab310924f0 | 420 | // output the header for the users.txt file |
epgmdm | 11:87ab310924f0 | 421 | spiSD(); |
epgmdm | 11:87ab310924f0 | 422 | fputs("rfid Credit lckr pod maxBatt outBatt Name\n\r", fp); |
epgmdm | 11:87ab310924f0 | 423 | |
epgmdm | 11:87ab310924f0 | 424 | // output buffer |
epgmdm | 11:87ab310924f0 | 425 | char logLine[180]; |
epgmdm | 11:87ab310924f0 | 426 | |
epgmdm | 11:87ab310924f0 | 427 | for (int i = 0; i < userCountH; i++) { |
epgmdm | 11:87ab310924f0 | 428 | // get all the needed information in strings |
epgmdm | 11:87ab310924f0 | 429 | spiSD(); |
epgmdm | 11:87ab310924f0 | 430 | fprintf(fp, "%u %d %d %d %d %d %s\n\r", allUsersH[i].getRfid(), allUsersH[i].getCredit(), |
epgmdm | 11:87ab310924f0 | 431 | allUsersH[i].getLocker(), allUsersH[i].getPod(), |
epgmdm | 11:87ab310924f0 | 432 | allUsersH[i].getBatteriesMax(), allUsersH[i].getBatteriesOut(), |
epgmdm | 11:87ab310924f0 | 433 | allUsersH[i].getName()); |
epgmdm | 11:87ab310924f0 | 434 | } |
epgmdm | 11:87ab310924f0 | 435 | spiSD(); |
epgmdm | 11:87ab310924f0 | 436 | fclose(fp); |
epgmdm | 11:87ab310924f0 | 437 | } |
epgmdm | 11:87ab310924f0 | 438 | |
epgmdm | 11:87ab310924f0 | 439 | /*************************************************************************************************/ |
epgmdm | 11:87ab310924f0 | 440 | /* RFID support */ |
epgmdm | 11:87ab310924f0 | 441 | /*************************************************************************************************/ |
epgmdm | 11:87ab310924f0 | 442 | /** |
epgmdm | 11:87ab310924f0 | 443 | * Read Rfid card and parse out the tag id into a single integer. Log if tag is either known |
epgmdm | 11:87ab310924f0 | 444 | * or unknown. Sets the global variable for the current user if a user is found. |
epgmdm | 11:87ab310924f0 | 445 | * @param rfidReader - MFRC522* of the RFID reader |
epgmdm | 11:87ab310924f0 | 446 | * @param source - HubLoggingRfidSource enum for which RFID reader (battery, posho, incubator) |
epgmdm | 11:87ab310924f0 | 447 | * @return int representing the userIndex of the HubUser found by the RFID tag. If no user is |
epgmdm | 11:87ab310924f0 | 448 | found, returns a -1. |
epgmdm | 11:87ab310924f0 | 449 | */ |
epgmdm | 11:87ab310924f0 | 450 | int Hmi::rfidReadHelper(MFRC522 *rfidReader, enum HubLoggingRfidSource source) |
epgmdm | 11:87ab310924f0 | 451 | { |
epgmdm | 11:87ab310924f0 | 452 | if (!rfidReader->PICC_IsNewCardPresent()) { |
epgmdm | 11:87ab310924f0 | 453 | return -1; |
epgmdm | 11:87ab310924f0 | 454 | } |
epgmdm | 11:87ab310924f0 | 455 | |
epgmdm | 11:87ab310924f0 | 456 | if (!rfidReader->PICC_ReadCardSerial()) { |
epgmdm | 11:87ab310924f0 | 457 | #ifdef debug |
epgmdm | 11:87ab310924f0 | 458 | printf("Card not readable\n\r"); |
epgmdm | 11:87ab310924f0 | 459 | #endif |
epgmdm | 11:87ab310924f0 | 460 | return -1; |
epgmdm | 11:87ab310924f0 | 461 | } |
epgmdm | 11:87ab310924f0 | 462 | |
epgmdm | 11:87ab310924f0 | 463 | // if this is for the posho, is the posho already in use? |
epgmdm | 11:87ab310924f0 | 464 | |
epgmdm | 11:87ab310924f0 | 465 | if ((source == source_posho) && flagPoshoAlreadyInUseH) { |
epgmdm | 11:87ab310924f0 | 466 | TFT_H->cls(); |
epgmdm | 11:87ab310924f0 | 467 | TFT_H->locate(0,0); |
epgmdm | 11:87ab310924f0 | 468 | TFT_H->printf("Posho in use\n\r"); |
epgmdm | 11:87ab310924f0 | 469 | wait(1); |
epgmdm | 11:87ab310924f0 | 470 | currentScreenH = initialScanRfid; |
epgmdm | 11:87ab310924f0 | 471 | return -1; |
epgmdm | 11:87ab310924f0 | 472 | } |
epgmdm | 11:87ab310924f0 | 473 | |
epgmdm | 11:87ab310924f0 | 474 | // get the id of the scanned tag |
epgmdm | 11:87ab310924f0 | 475 | uint8_t tempReadingRfid[4]; |
epgmdm | 11:87ab310924f0 | 476 | for(uint8_t i = 0; i < rfidReader->uid.size; i++) { |
epgmdm | 11:87ab310924f0 | 477 | tempReadingRfid[i] = rfidReader->uid.uidByte[i]; |
epgmdm | 11:87ab310924f0 | 478 | } |
epgmdm | 11:87ab310924f0 | 479 | |
epgmdm | 11:87ab310924f0 | 480 | // concatenate the 4 bytes into a single integer via bit shifting |
epgmdm | 11:87ab310924f0 | 481 | uint32_t actualRfid = ((((uint32_t)tempReadingRfid[0] << 24) | |
epgmdm | 11:87ab310924f0 | 482 | ((uint32_t)tempReadingRfid[1] << 16)) | |
epgmdm | 11:87ab310924f0 | 483 | (((uint32_t)tempReadingRfid[2] << 8) | |
epgmdm | 11:87ab310924f0 | 484 | ((uint32_t)tempReadingRfid[3] << 0))); |
epgmdm | 11:87ab310924f0 | 485 | |
epgmdm | 11:87ab310924f0 | 486 | #ifdef debug |
epgmdm | 11:87ab310924f0 | 487 | printf("User:"); |
epgmdm | 11:87ab310924f0 | 488 | for(uint8_t i = 0; i < rfidReader->uid.size; i++) |
epgmdm | 11:87ab310924f0 | 489 | { |
epgmdm | 11:87ab310924f0 | 490 | uint8_t uidByte = rfidReader->uid.uidByte[i]; |
epgmdm | 11:87ab310924f0 | 491 | printf(" %d", uidByte); |
epgmdm | 11:87ab310924f0 | 492 | } |
epgmdm | 11:87ab310924f0 | 493 | printf("\n\rUserID: %u\n\r", actualRfid); |
epgmdm | 11:87ab310924f0 | 494 | #endif |
epgmdm | 11:87ab310924f0 | 495 | |
epgmdm | 11:87ab310924f0 | 496 | // find the user info |
epgmdm | 11:87ab310924f0 | 497 | char foundUserFlag = 0; |
epgmdm | 11:87ab310924f0 | 498 | int foundUserIndex; |
epgmdm | 11:87ab310924f0 | 499 | for (int i = 0; i < userCountH; i++) { |
epgmdm | 11:87ab310924f0 | 500 | if (allUsersH[i].getRfid() == actualRfid) { |
epgmdm | 11:87ab310924f0 | 501 | currentUserH = i; |
epgmdm | 11:87ab310924f0 | 502 | foundUserIndex = i; |
epgmdm | 11:87ab310924f0 | 503 | foundUserFlag = 1; |
epgmdm | 11:87ab310924f0 | 504 | break; |
epgmdm | 11:87ab310924f0 | 505 | } |
epgmdm | 11:87ab310924f0 | 506 | } |
epgmdm | 11:87ab310924f0 | 507 | |
epgmdm | 11:87ab310924f0 | 508 | // if the user isn't found, log that an rfid without a user was used and display home screen |
epgmdm | 11:87ab310924f0 | 509 | if (!foundUserFlag) { |
epgmdm | 11:87ab310924f0 | 510 | #ifdef debug |
epgmdm | 11:87ab310924f0 | 511 | printf("User not found\n\r"); |
epgmdm | 11:87ab310924f0 | 512 | printf("ID:%u\n\r", actualRfid); |
epgmdm | 11:87ab310924f0 | 513 | #endif |
epgmdm | 11:87ab310924f0 | 514 | // log the error interaction |
epgmdm | 11:87ab310924f0 | 515 | logErrorUnknownRfidScanned(actualRfid, source); |
epgmdm | 11:87ab310924f0 | 516 | |
epgmdm | 11:87ab310924f0 | 517 | // let user know tag wasn't found |
epgmdm | 11:87ab310924f0 | 518 | TFT_H->cls(); |
epgmdm | 11:87ab310924f0 | 519 | TFT_H->locate(0,0); |
epgmdm | 11:87ab310924f0 | 520 | TFT_H->printf("User not found\n\r"); |
epgmdm | 11:87ab310924f0 | 521 | TFT_H->printf("ID:%u\n\r", actualRfid); |
epgmdm | 11:87ab310924f0 | 522 | wait(1); |
epgmdm | 11:87ab310924f0 | 523 | currentScreenH = initialScanRfid; |
epgmdm | 11:87ab310924f0 | 524 | return -1; |
epgmdm | 11:87ab310924f0 | 525 | } |
epgmdm | 11:87ab310924f0 | 526 | |
epgmdm | 11:87ab310924f0 | 527 | // log user scan |
epgmdm | 11:87ab310924f0 | 528 | switch (source) { |
epgmdm | 11:87ab310924f0 | 529 | case source_battery: |
epgmdm | 11:87ab310924f0 | 530 | logActionWithUserInfo(hubAction_BatteryRfidScanned, &allUsersH[foundUserIndex]); |
epgmdm | 11:87ab310924f0 | 531 | break; |
epgmdm | 11:87ab310924f0 | 532 | case source_posho: |
epgmdm | 11:87ab310924f0 | 533 | logActionWithUserInfo(hubAction_PoshoRfidScanned, &allUsersH[foundUserIndex]); |
epgmdm | 11:87ab310924f0 | 534 | break; |
epgmdm | 11:87ab310924f0 | 535 | case source_incubator: |
epgmdm | 11:87ab310924f0 | 536 | logActionWithUserInfo(hubAction_IncubatorRfidScanned, &allUsersH[foundUserIndex]); |
epgmdm | 11:87ab310924f0 | 537 | break; |
epgmdm | 11:87ab310924f0 | 538 | } |
epgmdm | 11:87ab310924f0 | 539 | |
epgmdm | 11:87ab310924f0 | 540 | return foundUserIndex; |
epgmdm | 11:87ab310924f0 | 541 | } |
epgmdm | 11:87ab310924f0 | 542 | |
epgmdm | 11:87ab310924f0 | 543 | |
epgmdm | 11:87ab310924f0 | 544 | /*************************************************************************************************/ |
epgmdm | 11:87ab310924f0 | 545 | /* Battery Services */ |
epgmdm | 11:87ab310924f0 | 546 | /*************************************************************************************************/ |
epgmdm | 11:87ab310924f0 | 547 | /** |
epgmdm | 11:87ab310924f0 | 548 | * Do if Battery RFID flag is set. Read RFID tag and check user status. |
epgmdm | 11:87ab310924f0 | 549 | * If there's a valid battery subscription, display drop off and/or pick up. |
epgmdm | 11:87ab310924f0 | 550 | * Otherwise, returns to initial screen. |
epgmdm | 11:87ab310924f0 | 551 | */ |
epgmdm | 11:87ab310924f0 | 552 | void Hmi::doBatteryRfidH() |
epgmdm | 11:87ab310924f0 | 553 | { |
epgmdm | 11:87ab310924f0 | 554 | flagBatteryRfidH = 0; |
epgmdm | 11:87ab310924f0 | 555 | |
epgmdm | 11:87ab310924f0 | 556 | // let the RF reader get tag info |
epgmdm | 11:87ab310924f0 | 557 | int foundUserIndex = rfidReadHelper(BatteryRfChipH, source_battery); |
epgmdm | 11:87ab310924f0 | 558 | if (foundUserIndex == -1) return; |
epgmdm | 11:87ab310924f0 | 559 | |
epgmdm | 11:87ab310924f0 | 560 | // Display info about the user - authorized for batteries? |
epgmdm | 11:87ab310924f0 | 561 | char authorizationFlag = 0; |
epgmdm | 11:87ab310924f0 | 562 | TFT_H->cls(); |
epgmdm | 11:87ab310924f0 | 563 | TFT_H->locate(0,0); |
epgmdm | 11:87ab310924f0 | 564 | TFT_H->printf("UserID: %d\n\r", allUsersH[foundUserIndex].getRfid()); |
epgmdm | 11:87ab310924f0 | 565 | TFT_H->printf("Name: %s\n\r", allUsersH[foundUserIndex].getName()); |
epgmdm | 11:87ab310924f0 | 566 | |
epgmdm | 11:87ab310924f0 | 567 | if (allUsersH[foundUserIndex].getBatteriesMax() > 0) { |
epgmdm | 11:87ab310924f0 | 568 | authorizationFlag = 1; |
epgmdm | 11:87ab310924f0 | 569 | } |
epgmdm | 11:87ab310924f0 | 570 | if (authorizationFlag){ |
epgmdm | 11:87ab310924f0 | 571 | TFT_H->printf("Locker: %u\n\r", allUsersH[foundUserIndex].getLocker()); |
epgmdm | 11:87ab310924f0 | 572 | TFT_H->printf("Pod: %u\n\r\n\r", allUsersH[foundUserIndex].getPod()); |
epgmdm | 11:87ab310924f0 | 573 | TFT_H->printf("Balance:%d\n\r", allUsersH[foundUserIndex].getCredit()); |
epgmdm | 11:87ab310924f0 | 574 | }else{ |
epgmdm | 11:87ab310924f0 | 575 | TFT_H->printf("\n\rSorry, you do not \n\rhave any batteries\n\ron this system. \n\r"); |
epgmdm | 11:87ab310924f0 | 576 | } |
epgmdm | 11:87ab310924f0 | 577 | |
epgmdm | 11:87ab310924f0 | 578 | |
epgmdm | 11:87ab310924f0 | 579 | |
epgmdm | 11:87ab310924f0 | 580 | // if not authorized for batteries, return to main screen |
epgmdm | 11:87ab310924f0 | 581 | wait(1); |
epgmdm | 11:87ab310924f0 | 582 | if (!authorizationFlag) { |
epgmdm | 11:87ab310924f0 | 583 | wait(2.0); |
epgmdm | 11:87ab310924f0 | 584 | currentScreenH = initialScanRfid; |
epgmdm | 11:87ab310924f0 | 585 | return; |
epgmdm | 11:87ab310924f0 | 586 | } |
epgmdm | 11:87ab310924f0 | 587 | |
epgmdm | 11:87ab310924f0 | 588 | // otherwise, ask user if the user wants to pick up or drop off batteries? |
epgmdm | 11:87ab310924f0 | 589 | TFT_H->locate(0,160); |
epgmdm | 11:87ab310924f0 | 590 | TFT_H->printf("Battery Action?\n\r"); |
epgmdm | 11:87ab310924f0 | 591 | TFT_H->locate(0,200); |
epgmdm | 11:87ab310924f0 | 592 | |
epgmdm | 11:87ab310924f0 | 593 | uint8_t maxBatteries = allUsersH[foundUserIndex].getBatteriesMax(); |
epgmdm | 11:87ab310924f0 | 594 | uint8_t outBatteries = allUsersH[foundUserIndex].getBatteriesOut(); |
epgmdm | 11:87ab310924f0 | 595 | |
epgmdm | 11:87ab310924f0 | 596 | if ((maxBatteries - outBatteries) == 0) { // can only drop off |
epgmdm | 11:87ab310924f0 | 597 | TFT_H->printf(" drop exit"); |
epgmdm | 11:87ab310924f0 | 598 | } else if (outBatteries == 0) { // can only pick up |
epgmdm | 11:87ab310924f0 | 599 | TFT_H->printf(" pick exit"); |
epgmdm | 11:87ab310924f0 | 600 | } else { // can pickup or dropoff |
epgmdm | 11:87ab310924f0 | 601 | TFT_H->printf(" pick drop exit"); |
epgmdm | 11:87ab310924f0 | 602 | } |
epgmdm | 11:87ab310924f0 | 603 | |
epgmdm | 11:87ab310924f0 | 604 | // go to action selecting screen and clear buttons beforehand |
epgmdm | 11:87ab310924f0 | 605 | currentScreenH = batterySelectAction; |
epgmdm | 11:87ab310924f0 | 606 | clearAllUserInitiatedFlagsH(); |
epgmdm | 11:87ab310924f0 | 607 | return; |
epgmdm | 11:87ab310924f0 | 608 | } |
epgmdm | 11:87ab310924f0 | 609 | |
epgmdm | 11:87ab310924f0 | 610 | /** |
epgmdm | 11:87ab310924f0 | 611 | * Do if user selects to pickup a battery. Determines how many batteries |
epgmdm | 11:87ab310924f0 | 612 | * a user can pickup based off user info and displays corresponding text |
epgmdm | 11:87ab310924f0 | 613 | * @param userIndex - int representing index of user in user table |
epgmdm | 11:87ab310924f0 | 614 | */ |
epgmdm | 11:87ab310924f0 | 615 | void Hmi::batteryPickUpScreenH(int userIndex) { |
epgmdm | 11:87ab310924f0 | 616 | TFT_H->cls(); |
epgmdm | 11:87ab310924f0 | 617 | TFT_H->locate(0,0); |
epgmdm | 11:87ab310924f0 | 618 | TFT_H->printf("UserID: %u\n\r\n\r", allUsersH[userIndex].getRfid()); |
epgmdm | 11:87ab310924f0 | 619 | |
epgmdm | 11:87ab310924f0 | 620 | TFT_H->printf("Action: PICK UP\n\r"); |
epgmdm | 11:87ab310924f0 | 621 | TFT_H->locate(0,160); |
epgmdm | 11:87ab310924f0 | 622 | TFT_H->printf("How many batteries?\n\r"); |
epgmdm | 11:87ab310924f0 | 623 | TFT_H->locate(0,200); |
epgmdm | 11:87ab310924f0 | 624 | switch (allUsersH[userIndex].getBatteriesMax() - allUsersH[userIndex].getBatteriesOut()) { |
epgmdm | 11:87ab310924f0 | 625 | case 1: { |
epgmdm | 11:87ab310924f0 | 626 | TFT_H->printf(" 1 exit"); |
epgmdm | 11:87ab310924f0 | 627 | break; |
epgmdm | 11:87ab310924f0 | 628 | } |
epgmdm | 11:87ab310924f0 | 629 | case 2: { |
epgmdm | 11:87ab310924f0 | 630 | TFT_H->printf(" 1 2 exit"); |
epgmdm | 11:87ab310924f0 | 631 | break; |
epgmdm | 11:87ab310924f0 | 632 | } |
epgmdm | 11:87ab310924f0 | 633 | case 3: { |
epgmdm | 11:87ab310924f0 | 634 | TFT_H->printf(" 1 2 3 exit"); |
epgmdm | 11:87ab310924f0 | 635 | break; |
epgmdm | 11:87ab310924f0 | 636 | } |
epgmdm | 11:87ab310924f0 | 637 | } |
epgmdm | 11:87ab310924f0 | 638 | |
epgmdm | 11:87ab310924f0 | 639 | // go to wait for selection input and reset button flags |
epgmdm | 11:87ab310924f0 | 640 | currentScreenH = batterySelectNumberForPickup; |
epgmdm | 11:87ab310924f0 | 641 | clearAllUserInitiatedFlagsH(); |
epgmdm | 11:87ab310924f0 | 642 | return; |
epgmdm | 11:87ab310924f0 | 643 | } |
epgmdm | 11:87ab310924f0 | 644 | |
epgmdm | 11:87ab310924f0 | 645 | /** |
epgmdm | 11:87ab310924f0 | 646 | * Do if user selects to dropoff a battery. Determines how many batteries |
epgmdm | 11:87ab310924f0 | 647 | * a user can pickup based off user info and displays corresponding text |
epgmdm | 11:87ab310924f0 | 648 | * @param userIndex - int representing index of user in user table |
epgmdm | 11:87ab310924f0 | 649 | */ |
epgmdm | 11:87ab310924f0 | 650 | void Hmi::batteryDropOffScreenH(int userIndex) { |
epgmdm | 11:87ab310924f0 | 651 | TFT_H->cls(); |
epgmdm | 11:87ab310924f0 | 652 | TFT_H->locate(0,0); |
epgmdm | 11:87ab310924f0 | 653 | TFT_H->printf("UserID: %u\n\r\n\r", allUsersH[userIndex].getRfid()); |
epgmdm | 11:87ab310924f0 | 654 | |
epgmdm | 11:87ab310924f0 | 655 | TFT_H->printf("Action: DROP OFF\n\r"); |
epgmdm | 11:87ab310924f0 | 656 | TFT_H->locate(0,160); |
epgmdm | 11:87ab310924f0 | 657 | TFT_H->printf("How many batteries?\n\r"); |
epgmdm | 11:87ab310924f0 | 658 | TFT_H->locate(0,200); |
epgmdm | 11:87ab310924f0 | 659 | switch (allUsersH[userIndex].getBatteriesOut()) { |
epgmdm | 11:87ab310924f0 | 660 | case 1: { |
epgmdm | 11:87ab310924f0 | 661 | TFT_H->printf(" 1 exit"); |
epgmdm | 11:87ab310924f0 | 662 | break; |
epgmdm | 11:87ab310924f0 | 663 | } |
epgmdm | 11:87ab310924f0 | 664 | case 2: { |
epgmdm | 11:87ab310924f0 | 665 | TFT_H->printf(" 1 2 exit"); |
epgmdm | 11:87ab310924f0 | 666 | break; |
epgmdm | 11:87ab310924f0 | 667 | } |
epgmdm | 11:87ab310924f0 | 668 | case 3: { |
epgmdm | 11:87ab310924f0 | 669 | TFT_H->printf(" 1 2 3 exit"); |
epgmdm | 11:87ab310924f0 | 670 | break; |
epgmdm | 11:87ab310924f0 | 671 | } |
epgmdm | 11:87ab310924f0 | 672 | } |
epgmdm | 11:87ab310924f0 | 673 | |
epgmdm | 11:87ab310924f0 | 674 | // go to wait for selection input and reset button flags |
epgmdm | 11:87ab310924f0 | 675 | currentScreenH = batterySelectNumberForDropoff; |
epgmdm | 11:87ab310924f0 | 676 | clearAllUserInitiatedFlagsH(); |
epgmdm | 11:87ab310924f0 | 677 | return; |
epgmdm | 11:87ab310924f0 | 678 | } |
epgmdm | 11:87ab310924f0 | 679 | |
epgmdm | 11:87ab310924f0 | 680 | /** |
epgmdm | 11:87ab310924f0 | 681 | * Do after user selects number of batteries to drop off. |
epgmdm | 11:87ab310924f0 | 682 | * Logs the action, changes user info, transmits instructions to other systems |
epgmdm | 11:87ab310924f0 | 683 | * @param numBatteries - int for number of batteries selected to drop off |
epgmdm | 11:87ab310924f0 | 684 | * @param userIndex - int representing index of user in user table |
epgmdm | 11:87ab310924f0 | 685 | */ |
epgmdm | 11:87ab310924f0 | 686 | void Hmi::batteryDropOffH(int numBatteries, int userIndex) { |
epgmdm | 11:87ab310924f0 | 687 | switch(numBatteries) { |
epgmdm | 11:87ab310924f0 | 688 | case 1: |
epgmdm | 11:87ab310924f0 | 689 | logActionWithUserInfo(hubAction_OneBatteryDropped, &allUsersH[userIndex]); |
epgmdm | 11:87ab310924f0 | 690 | txBatteryDropOff(userIndex,1); |
epgmdm | 11:87ab310924f0 | 691 | allUsersH[userIndex].dropOffBattery(1); |
epgmdm | 11:87ab310924f0 | 692 | break; |
epgmdm | 11:87ab310924f0 | 693 | case 2: |
epgmdm | 11:87ab310924f0 | 694 | logActionWithUserInfo(hubAction_TwoBatteryDropped, &allUsersH[userIndex]); |
epgmdm | 11:87ab310924f0 | 695 | txBatteryDropOff(userIndex,2); |
epgmdm | 11:87ab310924f0 | 696 | allUsersH[userIndex].dropOffBattery(2); |
epgmdm | 11:87ab310924f0 | 697 | break; |
epgmdm | 11:87ab310924f0 | 698 | case 3: |
epgmdm | 11:87ab310924f0 | 699 | logActionWithUserInfo(hubAction_ThreeBatteryDropped, &allUsersH[userIndex]); |
epgmdm | 11:87ab310924f0 | 700 | txBatteryDropOff(userIndex,3); |
epgmdm | 11:87ab310924f0 | 701 | allUsersH[userIndex].dropOffBattery(3); |
epgmdm | 11:87ab310924f0 | 702 | break; |
epgmdm | 11:87ab310924f0 | 703 | } |
epgmdm | 11:87ab310924f0 | 704 | |
epgmdm | 11:87ab310924f0 | 705 | currentScreenH = initialScanRfid; |
epgmdm | 11:87ab310924f0 | 706 | return; |
epgmdm | 11:87ab310924f0 | 707 | } |
epgmdm | 11:87ab310924f0 | 708 | |
epgmdm | 11:87ab310924f0 | 709 | /** |
epgmdm | 11:87ab310924f0 | 710 | * Do after user selects number of batteries to pick up. |
epgmdm | 11:87ab310924f0 | 711 | * Logs the action, changes user info, transmits instructions to other systems |
epgmdm | 11:87ab310924f0 | 712 | * @param numBatteries - int for number of batteries selected to pick up |
epgmdm | 11:87ab310924f0 | 713 | * @param userIndex - int representing index of user in user table |
epgmdm | 11:87ab310924f0 | 714 | */ |
epgmdm | 11:87ab310924f0 | 715 | void Hmi::batteryPickUpH(int numBatteries, int userIndex) { |
epgmdm | 11:87ab310924f0 | 716 | switch(numBatteries) { |
epgmdm | 11:87ab310924f0 | 717 | case 1: |
epgmdm | 11:87ab310924f0 | 718 | logActionWithUserInfo(hubAction_OneBatteryPicked, &allUsersH[userIndex]); |
epgmdm | 11:87ab310924f0 | 719 | txBatteryPickUp(userIndex,1); |
epgmdm | 11:87ab310924f0 | 720 | allUsersH[userIndex].pickUpBattery(1); |
epgmdm | 11:87ab310924f0 | 721 | break; |
epgmdm | 11:87ab310924f0 | 722 | case 2: |
epgmdm | 11:87ab310924f0 | 723 | logActionWithUserInfo(hubAction_TwoBatteryPicked, &allUsersH[userIndex]); |
epgmdm | 11:87ab310924f0 | 724 | txBatteryPickUp(userIndex,2); |
epgmdm | 11:87ab310924f0 | 725 | allUsersH[userIndex].pickUpBattery(2); |
epgmdm | 11:87ab310924f0 | 726 | break; |
epgmdm | 11:87ab310924f0 | 727 | case 3: |
epgmdm | 11:87ab310924f0 | 728 | logActionWithUserInfo(hubAction_ThreeBatteryPicked, &allUsersH[userIndex]); |
epgmdm | 11:87ab310924f0 | 729 | txBatteryPickUp(userIndex,3); |
epgmdm | 11:87ab310924f0 | 730 | allUsersH[userIndex].pickUpBattery(3); |
epgmdm | 11:87ab310924f0 | 731 | break; |
epgmdm | 11:87ab310924f0 | 732 | } |
epgmdm | 11:87ab310924f0 | 733 | |
epgmdm | 11:87ab310924f0 | 734 | currentScreenH = initialScanRfid; |
epgmdm | 11:87ab310924f0 | 735 | return; |
epgmdm | 11:87ab310924f0 | 736 | } |
epgmdm | 11:87ab310924f0 | 737 | |
epgmdm | 11:87ab310924f0 | 738 | /*************************************************************************************************/ |
epgmdm | 11:87ab310924f0 | 739 | /* Misc Services */ |
epgmdm | 11:87ab310924f0 | 740 | /*************************************************************************************************/ |
epgmdm | 11:87ab310924f0 | 741 | /** |
epgmdm | 11:87ab310924f0 | 742 | * Do if Posho RFID flag is set. Reads rfid and checks user table for a positive balance |
epgmdm | 11:87ab310924f0 | 743 | * capable of paying for the posho. Displays screen info for selecting posho amount to process. |
epgmdm | 11:87ab310924f0 | 744 | */ |
epgmdm | 11:87ab310924f0 | 745 | void Hmi::doPoshoRfidH() |
epgmdm | 11:87ab310924f0 | 746 | { |
epgmdm | 11:87ab310924f0 | 747 | flagPoshoRfidH = 0; |
epgmdm | 11:87ab310924f0 | 748 | |
epgmdm | 11:87ab310924f0 | 749 | // let the RF reader get tag info |
epgmdm | 11:87ab310924f0 | 750 | int foundUserIndex = rfidReadHelper(PoshoRfChipH, source_posho); |
epgmdm | 11:87ab310924f0 | 751 | if (foundUserIndex == -1) return; |
epgmdm | 11:87ab310924f0 | 752 | |
epgmdm | 11:87ab310924f0 | 753 | // Display info about the user |
epgmdm | 11:87ab310924f0 | 754 | char authorizationFlag = 0; |
epgmdm | 11:87ab310924f0 | 755 | TFT_H->cls(); |
epgmdm | 11:87ab310924f0 | 756 | TFT_H->locate(0,0); |
epgmdm | 11:87ab310924f0 | 757 | TFT_H->printf("UserID: %u\n\r", allUsersH[foundUserIndex].getRfid()); |
epgmdm | 11:87ab310924f0 | 758 | int userAccountBalance = allUsersH[foundUserIndex].getCredit(); |
epgmdm | 11:87ab310924f0 | 759 | TFT_H->printf("Balance:%d\n\r", userAccountBalance); |
epgmdm | 11:87ab310924f0 | 760 | if (userAccountBalance > 1*poshoPricePerKgH) { |
epgmdm | 11:87ab310924f0 | 761 | authorizationFlag = 1; |
epgmdm | 11:87ab310924f0 | 762 | } |
epgmdm | 11:87ab310924f0 | 763 | TFT_H->printf("Authorization:%s\n\r", (authorizationFlag)? "YES":"NO"); |
epgmdm | 11:87ab310924f0 | 764 | |
epgmdm | 11:87ab310924f0 | 765 | |
epgmdm | 11:87ab310924f0 | 766 | // if not authorized for batteries, return to main screen |
epgmdm | 11:87ab310924f0 | 767 | wait(1); |
epgmdm | 11:87ab310924f0 | 768 | if (!authorizationFlag) { |
epgmdm | 11:87ab310924f0 | 769 | currentScreenH = initialScanRfid; |
epgmdm | 11:87ab310924f0 | 770 | return; |
epgmdm | 11:87ab310924f0 | 771 | } |
epgmdm | 11:87ab310924f0 | 772 | |
epgmdm | 11:87ab310924f0 | 773 | // otherwise, ask user how may kg of material to process? |
epgmdm | 11:87ab310924f0 | 774 | TFT_H->cls(); |
epgmdm | 11:87ab310924f0 | 775 | TFT_H->locate(0,0); |
epgmdm | 11:87ab310924f0 | 776 | TFT_H->printf("UserID: %u\n\r\n\r", allUsersH[foundUserIndex].getRfid()); |
epgmdm | 11:87ab310924f0 | 777 | |
epgmdm | 11:87ab310924f0 | 778 | TFT_H->printf("Action: Posho\n\r"); |
epgmdm | 11:87ab310924f0 | 779 | TFT_H->locate(0,160); |
epgmdm | 11:87ab310924f0 | 780 | TFT_H->printf("How many kilos?\n\r"); |
epgmdm | 11:87ab310924f0 | 781 | TFT_H->locate(0,200); |
epgmdm | 11:87ab310924f0 | 782 | if (userAccountBalance > 3*poshoPricePerKgH) { |
epgmdm | 11:87ab310924f0 | 783 | TFT_H->printf(" 1 2 3 exit"); |
epgmdm | 11:87ab310924f0 | 784 | } else if (userAccountBalance > 2*poshoPricePerKgH) { |
epgmdm | 11:87ab310924f0 | 785 | TFT_H->printf(" 1 2 exit"); |
epgmdm | 11:87ab310924f0 | 786 | } else { |
epgmdm | 11:87ab310924f0 | 787 | TFT_H->printf(" 1 exit"); |
epgmdm | 11:87ab310924f0 | 788 | } |
epgmdm | 11:87ab310924f0 | 789 | |
epgmdm | 11:87ab310924f0 | 790 | // go to wait for selection input and reset button flags |
epgmdm | 11:87ab310924f0 | 791 | currentScreenH = poshoSelectKilograms; |
epgmdm | 11:87ab310924f0 | 792 | clearAllUserInitiatedFlagsH(); |
epgmdm | 11:87ab310924f0 | 793 | return; |
epgmdm | 11:87ab310924f0 | 794 | } |
epgmdm | 11:87ab310924f0 | 795 | |
epgmdm | 11:87ab310924f0 | 796 | /** |
epgmdm | 11:87ab310924f0 | 797 | * Prepare to active the posho and husker for serial use. Change user balance as necessary |
epgmdm | 11:87ab310924f0 | 798 | * and send corresponding signal. Also sets posho flag to in use and sets an interrupt |
epgmdm | 11:87ab310924f0 | 799 | * to clear that flag after a specified time. |
epgmdm | 11:87ab310924f0 | 800 | * @param numKilograms - int for number of kilograms to be processed |
epgmdm | 11:87ab310924f0 | 801 | * @param userIndex - int representing index of user in user table |
epgmdm | 11:87ab310924f0 | 802 | */ |
epgmdm | 11:87ab310924f0 | 803 | void Hmi::poshoSerialUseH(int numKilograms, int userIndex) { |
epgmdm | 11:87ab310924f0 | 804 | flagPoshoAlreadyInUseH = 1; |
epgmdm | 11:87ab310924f0 | 805 | allUsersH[userIndex].decreaseCredit(numKilograms*poshoPricePerKgH); |
epgmdm | 11:87ab310924f0 | 806 | switch (numKilograms) { |
epgmdm | 11:87ab310924f0 | 807 | case 1: |
epgmdm | 11:87ab310924f0 | 808 | tickPoshoInUseClearH.attach(this, &Hmi::interruptPoshoInUseClearH, (float)timeForOneKgH); |
epgmdm | 11:87ab310924f0 | 809 | logActionWithUserInfo(hubAction_OneKiloPosho, &allUsersH[userIndex]); |
epgmdm | 11:87ab310924f0 | 810 | break; |
epgmdm | 11:87ab310924f0 | 811 | case 2: |
epgmdm | 11:87ab310924f0 | 812 | tickPoshoInUseClearH.attach(this, &Hmi::interruptPoshoInUseClearH, (float)timeForTwoKgH); |
epgmdm | 11:87ab310924f0 | 813 | logActionWithUserInfo(hubAction_TwoKiloPosho, &allUsersH[userIndex]); |
epgmdm | 11:87ab310924f0 | 814 | break; |
epgmdm | 11:87ab310924f0 | 815 | case 3: |
epgmdm | 11:87ab310924f0 | 816 | tickPoshoInUseClearH.attach(this, &Hmi::interruptPoshoInUseClearH, (float)timeForThreeKgH); |
epgmdm | 11:87ab310924f0 | 817 | logActionWithUserInfo(hubAction_ThreeKiloPosho, &allUsersH[userIndex]); |
epgmdm | 11:87ab310924f0 | 818 | break; |
epgmdm | 11:87ab310924f0 | 819 | } |
epgmdm | 11:87ab310924f0 | 820 | TFT_H->cls(); |
epgmdm | 11:87ab310924f0 | 821 | TFT_H->locate(0,0); |
epgmdm | 11:87ab310924f0 | 822 | TFT_H->printf("UserID: %u\n\r\n\r", allUsersH[userIndex].getRfid()); |
epgmdm | 11:87ab310924f0 | 823 | TFT_H->printf("New balance: %d\n\r", allUsersH[userIndex].getCredit()); |
epgmdm | 11:87ab310924f0 | 824 | txPoshoSerialUse(numKilograms); |
epgmdm | 11:87ab310924f0 | 825 | wait(1); |
epgmdm | 11:87ab310924f0 | 826 | currentScreenH = initialScanRfid; |
epgmdm | 11:87ab310924f0 | 827 | return; |
epgmdm | 11:87ab310924f0 | 828 | } |
epgmdm | 11:87ab310924f0 | 829 | |
epgmdm | 11:87ab310924f0 | 830 | /** |
epgmdm | 11:87ab310924f0 | 831 | * Do if Incubator RFID flag is set. Add incubator functionality later. |
epgmdm | 11:87ab310924f0 | 832 | */ |
epgmdm | 11:87ab310924f0 | 833 | void Hmi::doIncubatorRfidH() |
epgmdm | 11:87ab310924f0 | 834 | { |
epgmdm | 11:87ab310924f0 | 835 | flagIncubatorRfidH = 0; |
epgmdm | 11:87ab310924f0 | 836 | } |
epgmdm | 11:87ab310924f0 | 837 | |
epgmdm | 11:87ab310924f0 | 838 | /*************************************************************************************************/ |
epgmdm | 11:87ab310924f0 | 839 | /* Public Methods */ |
epgmdm | 11:87ab310924f0 | 840 | /*************************************************************************************************/ |
defrost | 13:de43f28c0365 | 841 | void Hmi::loop(){ |
defrost | 13:de43f28c0365 | 842 | loopHub(); |
defrost | 13:de43f28c0365 | 843 | } |
epgmdm | 11:87ab310924f0 | 844 | |
epgmdm | 11:87ab310924f0 | 845 | void Hmi::loopHub(){ |
epgmdm | 11:87ab310924f0 | 846 | while (true) { |
epgmdm | 11:87ab310924f0 | 847 | // put interrupts here that should supercede anything else |
epgmdm | 11:87ab310924f0 | 848 | //if (flag1sH) { do1sH(); } |
epgmdm | 11:87ab310924f0 | 849 | |
epgmdm | 11:87ab310924f0 | 850 | // put interrupts here that may be active depending on screen stage |
epgmdm | 11:87ab310924f0 | 851 | switch(currentScreenH) { |
epgmdm | 11:87ab310924f0 | 852 | case initialScanRfid: { |
epgmdm | 11:87ab310924f0 | 853 | TFT_H->cls(); |
epgmdm | 11:87ab310924f0 | 854 | TFT_H->locate(0,0); |
epgmdm | 11:87ab310924f0 | 855 | TFT_H->printf("Please scan your ID"); |
epgmdm | 11:87ab310924f0 | 856 | currentScreenH = waitForRfid; |
epgmdm | 11:87ab310924f0 | 857 | clearAllUserInitiatedFlagsH(); |
epgmdm | 11:87ab310924f0 | 858 | } |
epgmdm | 11:87ab310924f0 | 859 | case waitForRfid: { |
epgmdm | 11:87ab310924f0 | 860 | if (flagTimeCheckH) doTimeCheckH(); |
epgmdm | 11:87ab310924f0 | 861 | if (flagBatteryRfidH) doBatteryRfidH(); |
epgmdm | 11:87ab310924f0 | 862 | if (flagPoshoRfidH) doPoshoRfidH(); |
epgmdm | 11:87ab310924f0 | 863 | if (flagIncubatorRfidH) doIncubatorRfidH(); |
epgmdm | 11:87ab310924f0 | 864 | if (flagUpdateUserTableH) doUpdateUserTableH(); |
epgmdm | 11:87ab310924f0 | 865 | break; |
epgmdm | 11:87ab310924f0 | 866 | } |
epgmdm | 11:87ab310924f0 | 867 | case batterySelectAction: { |
epgmdm | 11:87ab310924f0 | 868 | uint8_t maxBatteries = allUsersH[currentUserH].getBatteriesMax(); |
epgmdm | 11:87ab310924f0 | 869 | uint8_t outBatteries = allUsersH[currentUserH].getBatteriesOut(); |
epgmdm | 11:87ab310924f0 | 870 | |
epgmdm | 11:87ab310924f0 | 871 | if ((maxBatteries - outBatteries) == 0) { |
epgmdm | 11:87ab310924f0 | 872 | if (flagButtonOneH) batteryDropOffScreenH(currentUserH); |
epgmdm | 11:87ab310924f0 | 873 | if (flagButtonFourH) cancelPressedH(currentUserH); |
epgmdm | 11:87ab310924f0 | 874 | } else if (outBatteries == 0) { |
epgmdm | 11:87ab310924f0 | 875 | if (flagButtonOneH) batteryPickUpScreenH(currentUserH); |
epgmdm | 11:87ab310924f0 | 876 | if (flagButtonFourH) cancelPressedH(currentUserH); |
epgmdm | 11:87ab310924f0 | 877 | } else { |
epgmdm | 11:87ab310924f0 | 878 | if (flagButtonOneH) batteryPickUpScreenH(currentUserH); |
epgmdm | 11:87ab310924f0 | 879 | if (flagButtonThreeH) batteryDropOffScreenH(currentUserH); |
epgmdm | 11:87ab310924f0 | 880 | if (flagButtonFourH) cancelPressedH(currentUserH); |
epgmdm | 11:87ab310924f0 | 881 | } |
epgmdm | 11:87ab310924f0 | 882 | |
epgmdm | 11:87ab310924f0 | 883 | break; |
epgmdm | 11:87ab310924f0 | 884 | } |
epgmdm | 11:87ab310924f0 | 885 | case batterySelectNumberForDropoff: { |
epgmdm | 11:87ab310924f0 | 886 | switch (allUsersH[currentUserH].getBatteriesOut()) { |
epgmdm | 11:87ab310924f0 | 887 | case 1: { |
epgmdm | 11:87ab310924f0 | 888 | if (flagButtonOneH) batteryDropOffH(1, currentUserH); |
epgmdm | 11:87ab310924f0 | 889 | if (flagButtonFourH) cancelPressedH(currentUserH); |
epgmdm | 11:87ab310924f0 | 890 | break; |
epgmdm | 11:87ab310924f0 | 891 | } |
epgmdm | 11:87ab310924f0 | 892 | case 2: { |
epgmdm | 11:87ab310924f0 | 893 | if (flagButtonOneH) batteryDropOffH(1, currentUserH); |
epgmdm | 11:87ab310924f0 | 894 | if (flagButtonTwoH) batteryDropOffH(2, currentUserH); |
epgmdm | 11:87ab310924f0 | 895 | if (flagButtonFourH) cancelPressedH(currentUserH); |
epgmdm | 11:87ab310924f0 | 896 | break; |
epgmdm | 11:87ab310924f0 | 897 | } |
epgmdm | 11:87ab310924f0 | 898 | case 3: { |
epgmdm | 11:87ab310924f0 | 899 | if (flagButtonOneH) batteryDropOffH(1, currentUserH); |
epgmdm | 11:87ab310924f0 | 900 | if (flagButtonTwoH) batteryDropOffH(2, currentUserH); |
epgmdm | 11:87ab310924f0 | 901 | if (flagButtonThreeH) batteryDropOffH(3, currentUserH); |
epgmdm | 11:87ab310924f0 | 902 | if (flagButtonFourH) cancelPressedH(currentUserH); |
epgmdm | 11:87ab310924f0 | 903 | break; |
epgmdm | 11:87ab310924f0 | 904 | } |
epgmdm | 11:87ab310924f0 | 905 | } |
epgmdm | 11:87ab310924f0 | 906 | break; |
epgmdm | 11:87ab310924f0 | 907 | } |
epgmdm | 11:87ab310924f0 | 908 | case batterySelectNumberForPickup: { |
epgmdm | 11:87ab310924f0 | 909 | uint8_t maxBatteries = allUsersH[currentUserH].getBatteriesMax(); |
epgmdm | 11:87ab310924f0 | 910 | uint8_t outBatteries = allUsersH[currentUserH].getBatteriesOut(); |
epgmdm | 11:87ab310924f0 | 911 | |
epgmdm | 11:87ab310924f0 | 912 | switch (maxBatteries - outBatteries) { |
epgmdm | 11:87ab310924f0 | 913 | case 1: { |
epgmdm | 11:87ab310924f0 | 914 | if (flagButtonOneH) batteryPickUpH(1, currentUserH); |
epgmdm | 11:87ab310924f0 | 915 | if (flagButtonFourH) cancelPressedH(currentUserH); |
epgmdm | 11:87ab310924f0 | 916 | break; |
epgmdm | 11:87ab310924f0 | 917 | } |
epgmdm | 11:87ab310924f0 | 918 | case 2: { |
epgmdm | 11:87ab310924f0 | 919 | if (flagButtonOneH) batteryPickUpH(1, currentUserH); |
epgmdm | 11:87ab310924f0 | 920 | if (flagButtonTwoH) batteryPickUpH(2, currentUserH); |
epgmdm | 11:87ab310924f0 | 921 | if (flagButtonFourH) cancelPressedH(currentUserH); |
epgmdm | 11:87ab310924f0 | 922 | break; |
epgmdm | 11:87ab310924f0 | 923 | } |
epgmdm | 11:87ab310924f0 | 924 | case 3: { |
epgmdm | 11:87ab310924f0 | 925 | if (flagButtonOneH) batteryPickUpH(1, currentUserH); |
epgmdm | 11:87ab310924f0 | 926 | if (flagButtonTwoH) batteryPickUpH(2, currentUserH); |
epgmdm | 11:87ab310924f0 | 927 | if (flagButtonThreeH) batteryPickUpH(3, currentUserH); |
epgmdm | 11:87ab310924f0 | 928 | if (flagButtonFourH) cancelPressedH(currentUserH); |
epgmdm | 11:87ab310924f0 | 929 | break; |
epgmdm | 11:87ab310924f0 | 930 | } |
epgmdm | 11:87ab310924f0 | 931 | } |
epgmdm | 11:87ab310924f0 | 932 | break; |
epgmdm | 11:87ab310924f0 | 933 | } |
epgmdm | 11:87ab310924f0 | 934 | case poshoSelectKilograms: { |
epgmdm | 11:87ab310924f0 | 935 | if (allUsersH[currentUserH].getCredit() > 3*poshoPricePerKgH) { |
epgmdm | 11:87ab310924f0 | 936 | if (flagButtonOneH) poshoSerialUseH(1, currentUserH); |
epgmdm | 11:87ab310924f0 | 937 | if (flagButtonTwoH) poshoSerialUseH(2, currentUserH); |
epgmdm | 11:87ab310924f0 | 938 | if (flagButtonThreeH) poshoSerialUseH(3, currentUserH); |
epgmdm | 11:87ab310924f0 | 939 | if (flagButtonFourH) cancelPressedH(currentUserH); |
epgmdm | 11:87ab310924f0 | 940 | } else if (allUsersH[currentUserH].getCredit() > 2*poshoPricePerKgH) { |
epgmdm | 11:87ab310924f0 | 941 | if (flagButtonOneH) poshoSerialUseH(1, currentUserH); |
epgmdm | 11:87ab310924f0 | 942 | if (flagButtonTwoH) poshoSerialUseH(2, currentUserH); |
epgmdm | 11:87ab310924f0 | 943 | if (flagButtonFourH) cancelPressedH(currentUserH); |
epgmdm | 11:87ab310924f0 | 944 | } else { |
epgmdm | 11:87ab310924f0 | 945 | if (flagButtonOneH) poshoSerialUseH(1, currentUserH); |
epgmdm | 11:87ab310924f0 | 946 | if (flagButtonFourH) cancelPressedH(currentUserH); |
epgmdm | 11:87ab310924f0 | 947 | } |
epgmdm | 11:87ab310924f0 | 948 | } |
epgmdm | 11:87ab310924f0 | 949 | } |
epgmdm | 11:87ab310924f0 | 950 | } |
epgmdm | 11:87ab310924f0 | 951 | } |
epgmdm | 11:87ab310924f0 | 952 | |
epgmdm | 11:87ab310924f0 | 953 | void Hmi::logActionWithUserInfo(enum HubActionForLogging action, HubUser *user) { |
epgmdm | 11:87ab310924f0 | 954 | // Append to a log text file |
epgmdm | 11:87ab310924f0 | 955 | spiSD(); |
epgmdm | 11:87ab310924f0 | 956 | char * name = "/sd/HubLog.txt"; |
epgmdm | 11:87ab310924f0 | 957 | FILE *fp; |
epgmdm | 11:87ab310924f0 | 958 | fp = fopen(name, "a"); |
epgmdm | 11:87ab310924f0 | 959 | if (fp == NULL) { |
epgmdm | 11:87ab310924f0 | 960 | #ifdef debug |
epgmdm | 11:87ab310924f0 | 961 | printf("Log text file can't be opened (Action log)\n\r"); |
epgmdm | 11:87ab310924f0 | 962 | #endif |
epgmdm | 11:87ab310924f0 | 963 | return; |
epgmdm | 11:87ab310924f0 | 964 | } |
epgmdm | 11:87ab310924f0 | 965 | |
epgmdm | 11:87ab310924f0 | 966 | // get the time and append it to an output buffer |
epgmdm | 11:87ab310924f0 | 967 | time_t seconds = time(NULL); |
epgmdm | 11:87ab310924f0 | 968 | char logLine[180]; |
epgmdm | 11:87ab310924f0 | 969 | sprintf(logLine, "%x", seconds); |
epgmdm | 11:87ab310924f0 | 970 | |
epgmdm | 11:87ab310924f0 | 971 | // append relevant information for action |
epgmdm | 11:87ab310924f0 | 972 | switch (action) { |
epgmdm | 11:87ab310924f0 | 973 | case hubAction_BatteryRfidScanned: |
epgmdm | 11:87ab310924f0 | 974 | strcat(logLine, " RB "); |
epgmdm | 11:87ab310924f0 | 975 | break; |
epgmdm | 11:87ab310924f0 | 976 | case hubAction_PoshoRfidScanned: |
epgmdm | 11:87ab310924f0 | 977 | strcat(logLine, " RP "); |
epgmdm | 11:87ab310924f0 | 978 | break; |
epgmdm | 11:87ab310924f0 | 979 | case hubAction_IncubatorRfidScanned: |
epgmdm | 11:87ab310924f0 | 980 | strcat(logLine, " RI "); |
epgmdm | 11:87ab310924f0 | 981 | break; |
epgmdm | 11:87ab310924f0 | 982 | case hubAction_Exit: |
epgmdm | 11:87ab310924f0 | 983 | strcat(logLine, " X "); |
epgmdm | 11:87ab310924f0 | 984 | break; |
epgmdm | 11:87ab310924f0 | 985 | case hubAction_OneBatteryDropped: |
epgmdm | 11:87ab310924f0 | 986 | strcat(logLine, " BD 1 "); |
epgmdm | 11:87ab310924f0 | 987 | break; |
epgmdm | 11:87ab310924f0 | 988 | case hubAction_TwoBatteryDropped: |
epgmdm | 11:87ab310924f0 | 989 | strcat(logLine, " BD 2 "); |
epgmdm | 11:87ab310924f0 | 990 | break; |
epgmdm | 11:87ab310924f0 | 991 | case hubAction_ThreeBatteryDropped: |
epgmdm | 11:87ab310924f0 | 992 | strcat(logLine, " BD 3 "); |
epgmdm | 11:87ab310924f0 | 993 | break; |
epgmdm | 11:87ab310924f0 | 994 | case hubAction_OneBatteryPicked: |
epgmdm | 11:87ab310924f0 | 995 | strcat(logLine, " BP 1 "); |
epgmdm | 11:87ab310924f0 | 996 | break; |
epgmdm | 11:87ab310924f0 | 997 | case hubAction_TwoBatteryPicked: |
epgmdm | 11:87ab310924f0 | 998 | strcat(logLine, " BP 2 "); |
epgmdm | 11:87ab310924f0 | 999 | break; |
epgmdm | 11:87ab310924f0 | 1000 | case hubAction_ThreeBatteryPicked: |
epgmdm | 11:87ab310924f0 | 1001 | strcat(logLine, " BP 3 "); |
epgmdm | 11:87ab310924f0 | 1002 | break; |
epgmdm | 11:87ab310924f0 | 1003 | case hubAction_OneKiloPosho: |
epgmdm | 11:87ab310924f0 | 1004 | strcat(logLine, " PO 1 "); |
epgmdm | 11:87ab310924f0 | 1005 | break; |
epgmdm | 11:87ab310924f0 | 1006 | case hubAction_TwoKiloPosho: |
epgmdm | 11:87ab310924f0 | 1007 | strcat(logLine, " PO 2 "); |
epgmdm | 11:87ab310924f0 | 1008 | break; |
epgmdm | 11:87ab310924f0 | 1009 | case hubAction_ThreeKiloPosho: |
epgmdm | 11:87ab310924f0 | 1010 | strcat(logLine, " PO 3 "); |
epgmdm | 11:87ab310924f0 | 1011 | break; |
epgmdm | 11:87ab310924f0 | 1012 | } |
epgmdm | 11:87ab310924f0 | 1013 | |
epgmdm | 11:87ab310924f0 | 1014 | // append general user information |
epgmdm | 11:87ab310924f0 | 1015 | char rfidBuffer[20]; |
epgmdm | 11:87ab310924f0 | 1016 | char uidBuffer[20]; |
epgmdm | 11:87ab310924f0 | 1017 | char acctBalanceBuffer[20]; |
epgmdm | 11:87ab310924f0 | 1018 | char maxBatteriesBuffer[20]; |
epgmdm | 11:87ab310924f0 | 1019 | |
epgmdm | 11:87ab310924f0 | 1020 | sprintf(rfidBuffer, "%u ", user->getRfid()); |
epgmdm | 11:87ab310924f0 | 1021 | sprintf(uidBuffer, "%u ", user->getUid()); |
epgmdm | 11:87ab310924f0 | 1022 | sprintf(acctBalanceBuffer, "%d ", user->getCredit()); |
epgmdm | 11:87ab310924f0 | 1023 | sprintf(maxBatteriesBuffer, "%d\n", user->getBatteriesMax()); |
epgmdm | 11:87ab310924f0 | 1024 | |
epgmdm | 11:87ab310924f0 | 1025 | strcat(logLine, rfidBuffer); |
epgmdm | 11:87ab310924f0 | 1026 | strcat(logLine, uidBuffer); |
epgmdm | 11:87ab310924f0 | 1027 | strcat(logLine, acctBalanceBuffer); |
epgmdm | 11:87ab310924f0 | 1028 | strcat(logLine, maxBatteriesBuffer); |
epgmdm | 11:87ab310924f0 | 1029 | |
epgmdm | 11:87ab310924f0 | 1030 | // write the line to the log file and close the file |
epgmdm | 11:87ab310924f0 | 1031 | fputs(logLine, fp); |
epgmdm | 11:87ab310924f0 | 1032 | fclose(fp); |
epgmdm | 11:87ab310924f0 | 1033 | |
epgmdm | 11:87ab310924f0 | 1034 | #ifdef debug |
epgmdm | 11:87ab310924f0 | 1035 | printf("%s\n\r", logLine); |
epgmdm | 11:87ab310924f0 | 1036 | #endif |
epgmdm | 11:87ab310924f0 | 1037 | |
epgmdm | 11:87ab310924f0 | 1038 | } |
epgmdm | 11:87ab310924f0 | 1039 | |
epgmdm | 11:87ab310924f0 | 1040 | void Hmi::logErrorUnknownRfidScanned(uint32_t unknownRfid, enum HubLoggingRfidSource source) { |
epgmdm | 11:87ab310924f0 | 1041 | // Append to a log text file |
epgmdm | 11:87ab310924f0 | 1042 | char * name = "/sd/HubLog.txt"; |
epgmdm | 11:87ab310924f0 | 1043 | spiSD(); |
epgmdm | 11:87ab310924f0 | 1044 | FILE *fp; |
epgmdm | 11:87ab310924f0 | 1045 | fp = fopen(name, "a"); |
epgmdm | 11:87ab310924f0 | 1046 | |
epgmdm | 11:87ab310924f0 | 1047 | if (fp == NULL) { |
epgmdm | 11:87ab310924f0 | 1048 | #ifdef debug |
epgmdm | 11:87ab310924f0 | 1049 | printf("Log text file can't be opened (Unknown rfid)\n\r"); |
epgmdm | 11:87ab310924f0 | 1050 | #endif |
epgmdm | 11:87ab310924f0 | 1051 | return; |
epgmdm | 11:87ab310924f0 | 1052 | } |
epgmdm | 11:87ab310924f0 | 1053 | |
epgmdm | 11:87ab310924f0 | 1054 | // get the time and append it to an output buffer |
epgmdm | 11:87ab310924f0 | 1055 | time_t seconds = time(NULL); |
epgmdm | 11:87ab310924f0 | 1056 | char logLine[180]; |
epgmdm | 11:87ab310924f0 | 1057 | sprintf(logLine, "%x", seconds); |
epgmdm | 11:87ab310924f0 | 1058 | |
epgmdm | 11:87ab310924f0 | 1059 | // RFID action |
epgmdm | 11:87ab310924f0 | 1060 | switch (source) { |
epgmdm | 11:87ab310924f0 | 1061 | case source_battery: |
epgmdm | 11:87ab310924f0 | 1062 | strcat(logLine, " R X B "); |
epgmdm | 11:87ab310924f0 | 1063 | break; |
epgmdm | 11:87ab310924f0 | 1064 | case source_posho: |
epgmdm | 11:87ab310924f0 | 1065 | strcat(logLine, " R X P "); |
epgmdm | 11:87ab310924f0 | 1066 | break; |
epgmdm | 11:87ab310924f0 | 1067 | case source_incubator: |
epgmdm | 11:87ab310924f0 | 1068 | strcat(logLine, " R X I "); |
epgmdm | 11:87ab310924f0 | 1069 | break; |
epgmdm | 11:87ab310924f0 | 1070 | } |
epgmdm | 11:87ab310924f0 | 1071 | |
epgmdm | 11:87ab310924f0 | 1072 | // include just the RFID (indicates that no known user was found) |
epgmdm | 11:87ab310924f0 | 1073 | char rfidBuffer[20]; |
epgmdm | 11:87ab310924f0 | 1074 | sprintf(rfidBuffer, "%u\n", unknownRfid); |
epgmdm | 11:87ab310924f0 | 1075 | strcat(logLine, rfidBuffer); |
epgmdm | 11:87ab310924f0 | 1076 | |
epgmdm | 11:87ab310924f0 | 1077 | // write the line to the log file and close the file |
epgmdm | 11:87ab310924f0 | 1078 | fputs(logLine, fp); |
epgmdm | 11:87ab310924f0 | 1079 | fclose(fp); |
epgmdm | 11:87ab310924f0 | 1080 | |
epgmdm | 11:87ab310924f0 | 1081 | #ifdef debug |
epgmdm | 11:87ab310924f0 | 1082 | printf("%s\n\r", logLine); |
epgmdm | 11:87ab310924f0 | 1083 | #endif |
epgmdm | 11:87ab310924f0 | 1084 | |
epgmdm | 11:87ab310924f0 | 1085 | } |
epgmdm | 11:87ab310924f0 | 1086 | |
epgmdm | 11:87ab310924f0 | 1087 | /** |
epgmdm | 11:87ab310924f0 | 1088 | * Sends a signal to a locker that the current user is picking up numBatteries batteries |
epgmdm | 11:87ab310924f0 | 1089 | * @param numBatteries - int representing number of batteries user is picking up |
epgmdm | 11:87ab310924f0 | 1090 | */ |
epgmdm | 11:87ab310924f0 | 1091 | void Hmi::txBatteryPickUp(int userIndex,int numBatteries) { |
epgmdm | 11:87ab310924f0 | 1092 | DBG("txBatteryPickup:"); |
epgmdm | 11:87ab310924f0 | 1093 | int locker = (allUsersH[userIndex].getUid())&0x0000ff00; |
epgmdm | 11:87ab310924f0 | 1094 | lockerAddr = (baseAddr &0xffffff0000)+locker; |
epgmdm | 11:87ab310924f0 | 1095 | DBG("txBatteryDropOff: %x base %x lock %x", allUsersH[userIndex].getUid(),(unsigned int) baseAddr,(unsigned int) lockerAddr); |
epgmdm | 11:87ab310924f0 | 1096 | spiNRF(); |
epgmdm | 11:87ab310924f0 | 1097 | nrf->flushRx(); |
epgmdm | 11:87ab310924f0 | 1098 | nrf->flushTx(); |
epgmdm | 11:87ab310924f0 | 1099 | nrf->setTxAddress(lockerAddr); |
epgmdm | 11:87ab310924f0 | 1100 | #ifdef DEBUG |
epgmdm | 11:87ab310924f0 | 1101 | nrf->printDetails(); |
epgmdm | 11:87ab310924f0 | 1102 | #endif |
epgmdm | 11:87ab310924f0 | 1103 | sprintf(dataTx,"bp %x %x",allUsersH[userIndex].getUid(), numBatteries); |
epgmdm | 11:87ab310924f0 | 1104 | DBG("\r\n txBatteryPickup: %s",dataTx); |
epgmdm | 11:87ab310924f0 | 1105 | nrf->transmitData(dataTx,strlen(dataTx)); |
epgmdm | 11:87ab310924f0 | 1106 | spiSD(); |
epgmdm | 11:87ab310924f0 | 1107 | |
epgmdm | 11:87ab310924f0 | 1108 | } |
epgmdm | 11:87ab310924f0 | 1109 | |
epgmdm | 11:87ab310924f0 | 1110 | /** |
epgmdm | 11:87ab310924f0 | 1111 | * Sends a signal to a locker that the current user is dropping off numBatteries batteries |
epgmdm | 11:87ab310924f0 | 1112 | * @param numBatteries - int representing number of batteries user is dropping off |
epgmdm | 11:87ab310924f0 | 1113 | */ |
epgmdm | 11:87ab310924f0 | 1114 | void Hmi::txBatteryDropOff(int userIndex,int numBatteries) { |
epgmdm | 11:87ab310924f0 | 1115 | DBG("txBatteryDropOff:"); |
epgmdm | 11:87ab310924f0 | 1116 | int locker = (allUsersH[userIndex].getUid())&0x0000ff00; |
epgmdm | 11:87ab310924f0 | 1117 | lockerAddr = (baseAddr &0xffffff0000)+locker; |
epgmdm | 11:87ab310924f0 | 1118 | DBG("txBatteryDropOff: %x base %x lock %x", allUsersH[userIndex].getUid(),(unsigned int) baseAddr,(unsigned int) lockerAddr); |
epgmdm | 11:87ab310924f0 | 1119 | spiNRF(); |
epgmdm | 11:87ab310924f0 | 1120 | nrf->flushRx(); |
epgmdm | 11:87ab310924f0 | 1121 | nrf->flushTx(); |
epgmdm | 11:87ab310924f0 | 1122 | nrf->setTxAddress(lockerAddr); |
epgmdm | 11:87ab310924f0 | 1123 | #ifdef DEBUG |
epgmdm | 11:87ab310924f0 | 1124 | nrf->printDetails(); |
epgmdm | 11:87ab310924f0 | 1125 | #endif |
epgmdm | 11:87ab310924f0 | 1126 | sprintf(dataTx,"bd %x %x",allUsersH[userIndex].getUid(), numBatteries); |
epgmdm | 11:87ab310924f0 | 1127 | DBG("\r\n txBatteryDropOff: %s",dataTx); |
epgmdm | 11:87ab310924f0 | 1128 | nrf->transmitData(dataTx,strlen(dataTx)); |
epgmdm | 11:87ab310924f0 | 1129 | spiSD(); |
epgmdm | 11:87ab310924f0 | 1130 | } |
epgmdm | 11:87ab310924f0 | 1131 | |
epgmdm | 11:87ab310924f0 | 1132 | /** |
epgmdm | 11:87ab310924f0 | 1133 | * Sends a signal to a services mbed to schedule the posho/husker for use for x kilograms |
epgmdm | 11:87ab310924f0 | 1134 | * @param numKilograms - int representing number of kilograms user is processing |
epgmdm | 11:87ab310924f0 | 1135 | */ |
epgmdm | 11:87ab310924f0 | 1136 | void Hmi::txPoshoSerialUse(int numKilograms) { |
epgmdm | 11:87ab310924f0 | 1137 | |
epgmdm | 11:87ab310924f0 | 1138 | } |