Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <math.h>
- #include <unistd.h>
- void writePage(uint16_t address, char *data, uint8_t const len)
- {
- uint8_t pageBuffer[32];
- uint8_t pages = (uint8_t)ceil(len / (float)32);
- uint8_t onPage = 1;
- uint8_t max = 0;
- uint8_t min = 0;
- uint8_t dataIndex = 0;
- std::cout << "First address: " << address << std::endl;
- std::cout << "Length: " << (int)len << std::endl;
- std::cout << "Pages: " << (int)pages << std::endl;
- std::cout << "-------------" << std::endl << std::endl;
- std::cout << "..." << std::endl;
- do
- {
- max = 32 * onPage;
- min = 0 + ((onPage - 1) * 32);
- if (max > len) max = len;
- std::cout << " -> Start: " << (int)min << std::endl;
- std::cout << " -> End: " << (int)max << std::endl;
- std::cout << " -> Page: " << (int)onPage << std::endl << std::endl;
- do
- {
- pageBuffer[dataIndex] = data[dataIndex];
- std::cout << " -> Byte " << (int)dataIndex << ": " << (int)pageBuffer[dataIndex] << " Min: " << (int)min << " | Max: " << (int)max << std::endl;
- dataIndex++;
- usleep(500000);
- }
- while (dataIndex < max);
- onPage++;
- std::cout << " " << std::endl << " " << std::endl;
- }
- while (onPage <= pages);
- }
- int main()
- {
- uint64_t testBytes[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- writePage(0, reinterpret_cast<char*>(&testBytes[0]), sizeof(testBytes));
- getch();
- return (false);
- }
Advertisement
Add Comment
Please, Sign In to add comment