![](/media/cache/profiles/2e92962c0b6996add9517e4242ea9bdc.50x50_q85.jpg)
This short program illustrates how to use the DS130x_I2C library. My objective is to share the same RTC with Microchip 18F MCU.
Dependencies: mbed DebugLibrary
main.cpp@1:995212d326ca, 2011-02-11 (annotated)
- Committer:
- Yann
- Date:
- Fri Feb 11 10:17:20 2011 +0000
- Revision:
- 1:995212d326ca
- Parent:
- 0:f30e2135b0db
V0.0.0.2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yann | 0:f30e2135b0db | 1 | #include <string> |
Yann | 0:f30e2135b0db | 2 | #include <iostream> |
Yann | 0:f30e2135b0db | 3 | #include <iomanip> |
Yann | 0:f30e2135b0db | 4 | |
Yann | 0:f30e2135b0db | 5 | #include "DS130x_I2C.h" |
Yann | 0:f30e2135b0db | 6 | #include "EthernetNetIf.h" |
Yann | 0:f30e2135b0db | 7 | #include "NTPClient.h" |
Yann | 0:f30e2135b0db | 8 | |
Yann | 0:f30e2135b0db | 9 | /* |
Yann | 0:f30e2135b0db | 10 | * Declare functions |
Yann | 0:f30e2135b0db | 11 | */ |
Yann | 0:f30e2135b0db | 12 | void AvailableIndicator(); // LED1 flashing for program while program is alive |
Yann | 0:f30e2135b0db | 13 | void TimeUpdate(); // Update time from SNTP server |
Yann | 0:f30e2135b0db | 14 | void RtcClockEvent(); // Event rise on each RTC.SQW/OUT change |
Yann | 0:f30e2135b0db | 15 | char DisplayMenuAndGetChoice(); // Display and get the user choice |
Yann | 1:995212d326ca | 16 | // Time functions |
Yann | 0:f30e2135b0db | 17 | void SetTimeFromSNTP(); |
Yann | 0:f30e2135b0db | 18 | void ForceTime(); |
Yann | 0:f30e2135b0db | 19 | void GetTime(); |
Yann | 0:f30e2135b0db | 20 | void GetTimeFieldByFiled(); |
Yann | 1:995212d326ca | 21 | // Memory functions |
Yann | 0:f30e2135b0db | 22 | void WriteStdStringValue(const unsigned char p_address, const std::string & p_string); // Write a string |
Yann | 0:f30e2135b0db | 23 | void ReadStdStringValue(const unsigned char p_address); // Read a string |
Yann | 1:995212d326ca | 24 | void WriteShortValue(const unsigned char p_address, const short p_short, CDS130X_I2C::Mode p_mode); // Write a short value |
Yann | 1:995212d326ca | 25 | void ReadShortValue(const unsigned char p_address, CDS130X_I2C::Mode p_mode); // Read a short value |
Yann | 1:995212d326ca | 26 | void WriteIntegerValue(const unsigned char p_address, const int p_int, CDS130X_I2C::Mode p_mode); // Write an integer value |
Yann | 1:995212d326ca | 27 | void ReadIntegerValue(const unsigned char p_address, CDS130X_I2C::Mode p_mode); // Read an integer value |
Yann | 0:f30e2135b0db | 28 | |
Yann | 0:f30e2135b0db | 29 | /* |
Yann | 0:f30e2135b0db | 30 | * Declare statics |
Yann | 0:f30e2135b0db | 31 | */ |
Yann | 0:f30e2135b0db | 32 | EthernetNetIf g_eth; |
Yann | 0:f30e2135b0db | 33 | Host g_ntpServer(IpAddr(), 123, "ntp.unice.fr"); |
Yann | 0:f30e2135b0db | 34 | NTPClient g_ntp; |
Yann | 0:f30e2135b0db | 35 | |
Yann | 0:f30e2135b0db | 36 | DigitalOut g_availableLed(LED1); // To verify if program in running |
Yann | 0:f30e2135b0db | 37 | InterruptIn g_rtcClock(p5); // Used to trigger event from RTC.SQW/OUT |
Yann | 0:f30e2135b0db | 38 | Ticker g_available; // LED1 will flash with a period of 2s |
Yann | 0:f30e2135b0db | 39 | Ticker g_timeUpdate; // Update time from SNTP server |
Yann | 0:f30e2135b0db | 40 | |
Yann | 0:f30e2135b0db | 41 | CDS130X_I2C g_myRTC(0xd0, p28, p27, CDS130X_I2C::One_Hz); // Create an instance of the class C24LCXX_I2C, p28: SDA, p29:SDL, Oscillator mode: 1Hz, on 5V I2C bus |
Yann | 0:f30e2135b0db | 42 | |
Yann | 0:f30e2135b0db | 43 | int main() { |
Yann | 0:f30e2135b0db | 44 | |
Yann | 0:f30e2135b0db | 45 | // Launch available indicator |
Yann | 0:f30e2135b0db | 46 | g_available.attach(&AvailableIndicator, 2.0); |
Yann | 0:f30e2135b0db | 47 | // Initialize the module |
Yann | 0:f30e2135b0db | 48 | if (!g_myRTC.Initialize()) { |
Yann | 0:f30e2135b0db | 49 | error("Module initialization failed"); |
Yann | 0:f30e2135b0db | 50 | } |
Yann | 0:f30e2135b0db | 51 | // Initialize Ethernet |
Yann | 1:995212d326ca | 52 | std::cout << "Getting IP address..." << "\r" << std::endl; |
Yann | 0:f30e2135b0db | 53 | g_eth.setup(); |
Yann | 0:f30e2135b0db | 54 | wait(1); // Needed after Ethernet startup |
Yann | 0:f30e2135b0db | 55 | IpAddr ip = g_eth.getIp(); |
Yann | 0:f30e2135b0db | 56 | std::cout << "IP address: " << (int)ip[0] << "." << (int)ip[1] << "." << (int)ip[2] << "." << (int)ip[3] << "\r" << std::endl; |
Yann | 0:f30e2135b0db | 57 | // Update current time |
Yann | 0:f30e2135b0db | 58 | g_ntp.setTime(g_ntpServer); |
Yann | 0:f30e2135b0db | 59 | time_t ctTime = time(NULL); |
Yann | 0:f30e2135b0db | 60 | std::cout << "Time is now: " << ctime(&ctTime) << " UTC\r" << std::endl; |
Yann | 0:f30e2135b0db | 61 | // Start ticker |
Yann | 0:f30e2135b0db | 62 | g_timeUpdate.attach(&TimeUpdate, 60.0); |
Yann | 0:f30e2135b0db | 63 | |
Yann | 0:f30e2135b0db | 64 | // Start RTC.SQW/OUT trigger |
Yann | 0:f30e2135b0db | 65 | g_rtcClock.rise(&RtcClockEvent); |
Yann | 0:f30e2135b0db | 66 | |
Yann | 0:f30e2135b0db | 67 | while (true) { |
Yann | 0:f30e2135b0db | 68 | switch (DisplayMenuAndGetChoice()) { |
Yann | 0:f30e2135b0db | 69 | case 'a': |
Yann | 0:f30e2135b0db | 70 | SetTimeFromSNTP(); |
Yann | 0:f30e2135b0db | 71 | break; |
Yann | 0:f30e2135b0db | 72 | case 'b': |
Yann | 0:f30e2135b0db | 73 | GetTime(); |
Yann | 0:f30e2135b0db | 74 | break; |
Yann | 0:f30e2135b0db | 75 | case 'c': |
Yann | 0:f30e2135b0db | 76 | ForceTime(); |
Yann | 0:f30e2135b0db | 77 | break; |
Yann | 0:f30e2135b0db | 78 | case 'd': |
Yann | 0:f30e2135b0db | 79 | GetTimeFieldByFiled(); |
Yann | 0:f30e2135b0db | 80 | break; |
Yann | 0:f30e2135b0db | 81 | |
Yann | 1:995212d326ca | 82 | case 'j': { |
Yann | 0:f30e2135b0db | 83 | std::string str("Wellcome to Evil..."); |
Yann | 0:f30e2135b0db | 84 | WriteStdStringValue(0x04, str); |
Yann | 1:995212d326ca | 85 | #if defined(__DEBUG) |
Yann | 1:995212d326ca | 86 | g_myRTC.DumpMemoryArea(0x04, str.length() + 4); |
Yann | 1:995212d326ca | 87 | #else // __DEBUG |
Yann | 1:995212d326ca | 88 | std::cout << "DEBUG mode is not set, nothing to do!\r" << std::endl; |
Yann | 1:995212d326ca | 89 | #endif // __DEBUG |
Yann | 0:f30e2135b0db | 90 | } |
Yann | 0:f30e2135b0db | 91 | break; |
Yann | 1:995212d326ca | 92 | case 'k': |
Yann | 1:995212d326ca | 93 | ReadStdStringValue(0x04); |
Yann | 1:995212d326ca | 94 | break; |
Yann | 1:995212d326ca | 95 | case 'l': |
Yann | 1:995212d326ca | 96 | WriteShortValue(0x21, (short)0xbeef, CDS130X_I2C::BigEndian); |
Yann | 1:995212d326ca | 97 | break; |
Yann | 0:f30e2135b0db | 98 | case 'm': |
Yann | 1:995212d326ca | 99 | ReadShortValue(0x21, CDS130X_I2C::BigEndian); |
Yann | 1:995212d326ca | 100 | break; |
Yann | 1:995212d326ca | 101 | case 'n': |
Yann | 1:995212d326ca | 102 | WriteIntegerValue(0x23, (int)0xcafedeca, CDS130X_I2C::BigEndian); |
Yann | 1:995212d326ca | 103 | break; |
Yann | 1:995212d326ca | 104 | case 'o': |
Yann | 1:995212d326ca | 105 | ReadIntegerValue(0x23, CDS130X_I2C::BigEndian); |
Yann | 1:995212d326ca | 106 | break; |
Yann | 1:995212d326ca | 107 | case 'p': |
Yann | 0:f30e2135b0db | 108 | #if defined(__DEBUG) |
Yann | 1:995212d326ca | 109 | std::cout << "Enter the addess to dump: " << std::flush; |
Yann | 1:995212d326ca | 110 | int address; |
Yann | 1:995212d326ca | 111 | scanf("%d", &address); |
Yann | 1:995212d326ca | 112 | std::cout << "\r\r" << std::endl; |
Yann | 1:995212d326ca | 113 | g_myRTC.DumpMemoryArea((unsigned char)address, 16); |
Yann | 0:f30e2135b0db | 114 | #else // __DEBUG |
Yann | 0:f30e2135b0db | 115 | std::cout << "DEBUG mode is not set, nothing to do!\r" << std::endl; |
Yann | 0:f30e2135b0db | 116 | #endif // __DEBUG |
Yann | 0:f30e2135b0db | 117 | break; |
Yann | 1:995212d326ca | 118 | case 'q': |
Yann | 1:995212d326ca | 119 | g_myRTC.EraseMemoryArea(0x21, 16); |
Yann | 0:f30e2135b0db | 120 | break; |
Yann | 0:f30e2135b0db | 121 | default: |
Yann | 0:f30e2135b0db | 122 | std::cout << "Invalid user choice\r" << std::endl; |
Yann | 0:f30e2135b0db | 123 | break; |
Yann | 0:f30e2135b0db | 124 | } // End of 'switch' statement |
Yann | 0:f30e2135b0db | 125 | } // End of 'while' statement |
Yann | 0:f30e2135b0db | 126 | } // End of program - nerver reached |
Yann | 0:f30e2135b0db | 127 | |
Yann | 0:f30e2135b0db | 128 | void AvailableIndicator() |
Yann | 0:f30e2135b0db | 129 | { |
Yann | 0:f30e2135b0db | 130 | g_availableLed = !g_availableLed; |
Yann | 0:f30e2135b0db | 131 | } // End of AvailableIndicator |
Yann | 0:f30e2135b0db | 132 | |
Yann | 0:f30e2135b0db | 133 | void TimeUpdate() |
Yann | 0:f30e2135b0db | 134 | { |
Yann | 0:f30e2135b0db | 135 | // Update current time |
Yann | 0:f30e2135b0db | 136 | g_ntp.setTime(g_ntpServer); |
Yann | 0:f30e2135b0db | 137 | } // End of TimeUpdate funtion |
Yann | 0:f30e2135b0db | 138 | |
Yann | 0:f30e2135b0db | 139 | void RtcClockEvent() { /* Www Mmm dd hh:mm:ss yyyy */ |
Yann | 0:f30e2135b0db | 140 | struct tm t = g_myRTC.GetTime(); |
Yann | 0:f30e2135b0db | 141 | char buffer[32]; |
Yann | 0:f30e2135b0db | 142 | strftime(buffer, 32, "%a %m %d %H:%M:%S %Y", &t); |
Yann | 0:f30e2135b0db | 143 | DEBUG("RtcClockEvent: '%s'", buffer) |
Yann | 0:f30e2135b0db | 144 | } // End of RtcClockEvent() funtion |
Yann | 0:f30e2135b0db | 145 | |
Yann | 0:f30e2135b0db | 146 | char DisplayMenuAndGetChoice() |
Yann | 0:f30e2135b0db | 147 | { |
Yann | 1:995212d326ca | 148 | char value; |
Yann | 1:995212d326ca | 149 | std::cout << "\r" << std::endl << "\r" << std::endl << "DS13X_I2C v0.2\r" << std::endl; |
Yann | 1:995212d326ca | 150 | std::cout << "\tSet time from SNTP server:\t\ta\r" << std::endl; |
Yann | 1:995212d326ca | 151 | std::cout << "\tRead time from RTC:\t\t\tb\r" << std::endl; |
Yann | 1:995212d326ca | 152 | std::cout << "\tForce time:\t\t\t\tc\r" << std::endl; |
Yann | 1:995212d326ca | 153 | std::cout << "\tRead time field:\t\t\td\r" << std::endl; |
Yann | 1:995212d326ca | 154 | std::cout << "\tSet second:\t\t\t\te\r" << std::endl; |
Yann | 1:995212d326ca | 155 | std::cout << "\tInc hour:\t\t\t\tf\r" << std::endl; |
Yann | 1:995212d326ca | 156 | std::cout << "\tDec hour:\t\t\t\tg\r" << std::endl; |
Yann | 1:995212d326ca | 157 | std::cout << "\tInc month:\t\t\t\th\r" << std::endl; |
Yann | 1:995212d326ca | 158 | std::cout << "\tDec month:\t\t\t\ti\r" << std::endl; |
Yann | 1:995212d326ca | 159 | std::cout << "\tWrite a string at address 0x04:\t\tj\r" << std::endl; |
Yann | 1:995212d326ca | 160 | std::cout << "\tRead a string at address 0x04:\t\tk\r" << std::endl; |
Yann | 1:995212d326ca | 161 | std::cout << "\tWrite a short value at address 0x21:\tl\r" << std::endl; |
Yann | 1:995212d326ca | 162 | std::cout << "\tRead a short value at address 0x21:\tm\r" << std::endl; |
Yann | 1:995212d326ca | 163 | std::cout << "\tWrite an int value at address 0x23:\tn\r" << std::endl; |
Yann | 1:995212d326ca | 164 | std::cout << "\tRead an int value at address 0x23:\to\r" << std::endl; |
Yann | 1:995212d326ca | 165 | std::cout << "\tHexadump from address 0x21:\t\tp\r" << std::endl; |
Yann | 1:995212d326ca | 166 | std::cout << "\tErase from address 0x21:\t\tq\r" << std::endl; |
Yann | 0:f30e2135b0db | 167 | std::cout << "Enter your choice: " << std::flush; |
Yann | 1:995212d326ca | 168 | value = getchar(); |
Yann | 1:995212d326ca | 169 | std::cout << "\r" << std::endl; |
Yann | 1:995212d326ca | 170 | return value; |
Yann | 0:f30e2135b0db | 171 | } |
Yann | 0:f30e2135b0db | 172 | |
Yann | 0:f30e2135b0db | 173 | void SetTimeFromSNTP() { |
Yann | 0:f30e2135b0db | 174 | DEBUG_ENTER("SetTimeFromSNTP") |
Yann | 0:f30e2135b0db | 175 | |
Yann | 0:f30e2135b0db | 176 | char buffer[32]; |
Yann | 0:f30e2135b0db | 177 | time_t seconds = time(NULL); |
Yann | 0:f30e2135b0db | 178 | strftime(buffer, 32, "%a %m %d %H:%M:%S %Y", localtime(&seconds)); /* Www Mmm dd hh:mm:ss yyyy */ |
Yann | 0:f30e2135b0db | 179 | DEBUG("GetTime: Current date is '%s'", buffer) |
Yann | 0:f30e2135b0db | 180 | |
Yann | 0:f30e2135b0db | 181 | std::string str(buffer); |
Yann | 0:f30e2135b0db | 182 | g_myRTC.SetTime(str); |
Yann | 0:f30e2135b0db | 183 | |
Yann | 0:f30e2135b0db | 184 | DEBUG_LEAVE("SetTimeFromSNTP") |
Yann | 0:f30e2135b0db | 185 | } |
Yann | 0:f30e2135b0db | 186 | |
Yann | 0:f30e2135b0db | 187 | void ForceTime() { |
Yann | 0:f30e2135b0db | 188 | DEBUG_ENTER("ForceTime") |
Yann | 0:f30e2135b0db | 189 | |
Yann | 0:f30e2135b0db | 190 | // Get time frome user |
Yann | 0:f30e2135b0db | 191 | std::cout << "Enter the new date using the format 'Www Mmm dd hh:mm:ss yyyy': "; |
Yann | 0:f30e2135b0db | 192 | std::string line; |
Yann | 0:f30e2135b0db | 193 | std::cin >> line; |
Yann | 0:f30e2135b0db | 194 | int removeCR; |
Yann | 0:f30e2135b0db | 195 | if ((removeCR = line.rfind("\r")) != -1) { |
Yann | 0:f30e2135b0db | 196 | line.erase(removeCR); |
Yann | 0:f30e2135b0db | 197 | } |
Yann | 0:f30e2135b0db | 198 | // Set it |
Yann | 0:f30e2135b0db | 199 | g_myRTC.SetTime(line); |
Yann | 0:f30e2135b0db | 200 | |
Yann | 0:f30e2135b0db | 201 | DEBUG_LEAVE("ForceTime") |
Yann | 0:f30e2135b0db | 202 | } |
Yann | 0:f30e2135b0db | 203 | |
Yann | 0:f30e2135b0db | 204 | void GetTime() { |
Yann | 0:f30e2135b0db | 205 | struct tm t = g_myRTC.GetTime(); |
Yann | 1:995212d326ca | 206 | DEBUG("GetTime: %d %d %d %d:%d:%d %d", /* ww mm dd hh:mm:ss yyyy */ |
Yann | 1:995212d326ca | 207 | t.tm_wday, |
Yann | 1:995212d326ca | 208 | t.tm_mon, |
Yann | 1:995212d326ca | 209 | t.tm_mday, |
Yann | 1:995212d326ca | 210 | t.tm_hour, |
Yann | 1:995212d326ca | 211 | t.tm_min, |
Yann | 1:995212d326ca | 212 | t.tm_sec, |
Yann | 1:995212d326ca | 213 | t.tm_year); |
Yann | 0:f30e2135b0db | 214 | char buffer[32]; |
Yann | 0:f30e2135b0db | 215 | strftime(buffer, 32, "%a %m %d %H:%M:%S %Y", &t); |
Yann | 0:f30e2135b0db | 216 | DEBUG("GetTime: Current date is '%s'", buffer) |
Yann | 0:f30e2135b0db | 217 | } |
Yann | 0:f30e2135b0db | 218 | |
Yann | 0:f30e2135b0db | 219 | void GetTimeFieldByFiled() { |
Yann | 0:f30e2135b0db | 220 | unsigned char value = 0xff; |
Yann | 0:f30e2135b0db | 221 | |
Yann | 0:f30e2135b0db | 222 | // Get seconds in BCD format |
Yann | 0:f30e2135b0db | 223 | g_myRTC.Read(CDS130X_I2C::SecondsAddress, &value); |
Yann | 1:995212d326ca | 224 | DEBUG("\tSeconds in BCD: 0x%02x", value) |
Yann | 1:995212d326ca | 225 | std::cout << "\tSeconds in BCD: 0x" << std::setw(2) << std::setfill('0') << std::ios::hex << (unsigned char)value << "\r" << std::endl; |
Yann | 0:f30e2135b0db | 226 | // Get seconds in BCD format |
Yann | 0:f30e2135b0db | 227 | g_myRTC.Read(CDS130X_I2C::MinutesAddress, &value); |
Yann | 1:995212d326ca | 228 | DEBUG("\tMinutes in BCD: 0x%02x", value) |
Yann | 1:995212d326ca | 229 | std::cout << "\tMinutes in BCD: 0x" << std::setw(2) << std::setfill('0') << std::ios::hex << (unsigned char)value << "\r" << std::endl; |
Yann | 0:f30e2135b0db | 230 | // Get seconds in BCD format |
Yann | 0:f30e2135b0db | 231 | g_myRTC.Read(CDS130X_I2C::HoursAddress, &value); |
Yann | 1:995212d326ca | 232 | DEBUG("\tHours in BCD: 0x%02x", value) |
Yann | 1:995212d326ca | 233 | std::cout << "\tHours in BCD: 0x" << std::setw(2) << std::setfill('0') << std::ios::hex << (unsigned char)value << "\r" << std::endl; |
Yann | 0:f30e2135b0db | 234 | // Get seconds in BCD format |
Yann | 0:f30e2135b0db | 235 | g_myRTC.Read(CDS130X_I2C::DayAddress, &value); |
Yann | 1:995212d326ca | 236 | DEBUG("\tDay in BCD: 0x%02x", value) |
Yann | 1:995212d326ca | 237 | std::cout << "\tDay in BCD: 0x" << std::setw(2) << std::setfill('0') << std::ios::hex << (unsigned char)value << "\r" << std::endl; |
Yann | 0:f30e2135b0db | 238 | } |
Yann | 0:f30e2135b0db | 239 | |
Yann | 0:f30e2135b0db | 240 | void WriteStdStringValue(const unsigned char p_address, const std::string & p_string) { |
Yann | 1:995212d326ca | 241 | std::cout << "Write string '" << p_string << "' at address 0x" << std::setw(2) << std::setfill('0') << std::ios::hex << p_address << "\r" << std::endl; |
Yann | 0:f30e2135b0db | 242 | g_myRTC.WriteMemory(p_address, p_string); |
Yann | 0:f30e2135b0db | 243 | } |
Yann | 0:f30e2135b0db | 244 | |
Yann | 0:f30e2135b0db | 245 | void ReadStdStringValue(const unsigned char p_address) { |
Yann | 1:995212d326ca | 246 | std::string str; |
Yann | 1:995212d326ca | 247 | g_myRTC.ReadMemory(p_address, str); |
Yann | 1:995212d326ca | 248 | std::cout << "String at address 0x" << std::setw(2) << std::setfill('0') << std::ios::hex << p_address << " is: " << str << "\r" << std::endl; |
Yann | 0:f30e2135b0db | 249 | } |
Yann | 1:995212d326ca | 250 | |
Yann | 1:995212d326ca | 251 | void WriteShortValue(const unsigned char p_address, const short p_short, CDS130X_I2C::Mode p_mode) { |
Yann | 1:995212d326ca | 252 | std::cout << "Write short '" << p_short << "' at address 0x" << std::setw(2) << std::setfill('0') << std::ios::hex << p_address << "\r" << std::endl; |
Yann | 1:995212d326ca | 253 | if (p_mode == CDS130X_I2C::BigEndian) { |
Yann | 1:995212d326ca | 254 | g_myRTC.WriteMemory(p_address, p_short); |
Yann | 1:995212d326ca | 255 | } else { |
Yann | 1:995212d326ca | 256 | g_myRTC.WriteMemory(p_address, p_short, p_mode); |
Yann | 1:995212d326ca | 257 | } |
Yann | 1:995212d326ca | 258 | } |
Yann | 1:995212d326ca | 259 | |
Yann | 1:995212d326ca | 260 | void ReadShortValue(const unsigned char p_address, CDS130X_I2C::Mode p_mode) { |
Yann | 1:995212d326ca | 261 | short value; |
Yann | 1:995212d326ca | 262 | if (p_mode == CDS130X_I2C::BigEndian) { |
Yann | 1:995212d326ca | 263 | g_myRTC.ReadMemory(p_address, (short *)&value); |
Yann | 1:995212d326ca | 264 | } else { |
Yann | 1:995212d326ca | 265 | g_myRTC.ReadMemory(p_address, (short *)&value, p_mode); |
Yann | 1:995212d326ca | 266 | } |
Yann | 1:995212d326ca | 267 | std::cout << "Short at address 0x" << std::setw(2) << std::setfill('0') << std::ios::hex << p_address << " is: " << std::setw(4) << value << "\r" << std::endl; |
Yann | 1:995212d326ca | 268 | } |
Yann | 1:995212d326ca | 269 | |
Yann | 1:995212d326ca | 270 | void WriteIntegerValue(const unsigned char p_address, const int p_int, CDS130X_I2C::Mode p_mode) { |
Yann | 1:995212d326ca | 271 | std::cout << "Write integer '" << p_int << "' at address 0x" << std::setw(2) << std::setfill('0') << std::ios::hex << p_address << "\r" << std::endl; |
Yann | 1:995212d326ca | 272 | g_myRTC.WriteMemory(p_address, p_int, p_mode); |
Yann | 1:995212d326ca | 273 | } |
Yann | 1:995212d326ca | 274 | |
Yann | 1:995212d326ca | 275 | void ReadIntegerValue(const unsigned char p_address, CDS130X_I2C::Mode p_mode) { |
Yann | 1:995212d326ca | 276 | int value; |
Yann | 1:995212d326ca | 277 | if (p_mode == CDS130X_I2C::BigEndian) { |
Yann | 1:995212d326ca | 278 | g_myRTC.ReadMemory(p_address, (int *)&value); |
Yann | 1:995212d326ca | 279 | } else { |
Yann | 1:995212d326ca | 280 | g_myRTC.ReadMemory(p_address, (int *)&value, p_mode); |
Yann | 1:995212d326ca | 281 | } |
Yann | 1:995212d326ca | 282 | std::cout << "Integer at address 0x" << std::setw(2) << std::setfill('0') << std::ios::hex << p_address << " is: " << std::setw(8) << value << "\r" << std::endl; |
Yann | 1:995212d326ca | 283 | } |
Yann | 1:995212d326ca | 284 |