Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem app epson mbed msp430 pl tests
main.cpp
00001 // 00002 // Filename: main.cpp 00003 // 00004 // Flexbook startup. 00005 // 00006 00007 #include "book.h" 00008 #include "bookmonitor.h" 00009 #include "eink.h" 00010 #include "hal.h" 00011 #include "log.h" 00012 #include "pagefactory.h" 00013 #include <string> 00014 00015 using namespace Flexbook; 00016 00017 #include "mbed.h" 00018 #include "SDFileSystem.h" 00019 00020 DigitalOut led1(LED1); 00021 DigitalOut led2(LED2); 00022 DigitalOut led3(LED3); 00023 DigitalOut led4(LED4); 00024 DigitalOut buzz(p21, 0); 00025 //define all pins connected to companion PCBs as DigitalIn (high impedence) 00026 DigitalIn pin9(p9); 00027 DigitalIn pin10(p10); 00028 DigitalIn pin11(p11); 00029 DigitalIn pin12(p12); 00030 DigitalIn pin13(p13); 00031 DigitalIn pin14(p14); 00032 DigitalIn pin15(p15); 00033 DigitalIn pin16(p16); 00034 DigitalIn pin17(p17); 00035 DigitalIn pin18(p18); 00036 DigitalIn pin23(p23); 00037 DigitalIn pin24(p24); 00038 DigitalIn pin25(p25); 00039 DigitalIn pin26(p26); 00040 DigitalIn pin27(p27); 00041 DigitalIn pin28(p28); 00042 DigitalIn pin29(p29); 00043 DigitalIn pin30(p30); 00044 00045 // MicroSD mbed 00046 // CS o-------------o 8 (DigitalOut cs) 00047 // DI o-------------o 5 (SPI mosi) 00048 // VCC o-------------o VOUT 00049 // SCK o-------------o 7 (SPI sclk) 00050 // GND o-------------o GND 00051 // DO o-------------o 6 (SPI miso) 00052 // CD o 00053 00054 00055 00056 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the Flexboard board 00057 00058 void SDtest() 00059 { 00060 printf("\nSD card: "); 00061 00062 FILE *fp1 = fopen("/sd/sdtest.txt", "w"); 00063 if(fp1 == NULL) { 00064 error("Could not open file for write\n"); 00065 } 00066 if(fprintf(fp1, "Hello SD Card\n") != 14) 00067 error("Could not write data\n"); 00068 fclose(fp1); 00069 00070 FILE *fp2 = fopen("/sd/sdtest.txt", "r"); 00071 if(fp2 == NULL) { 00072 error("Could not open file for read\n"); 00073 } 00074 char data[64]; 00075 data[0] = 0; 00076 if(fgets(data, sizeof(data), fp2) == NULL) 00077 error("Could not read data\n"); 00078 fclose(fp2); 00079 00080 printf("Ok\n"); 00081 } 00082 /* 00083 //function to count number of eligible words in the dictionary file 00084 int NumDictWords() 00085 { 00086 FILE *fp1 = fopen("/sd/hangdict.txt", "r"); 00087 if (fp1 == NULL) { 00088 printf("Could not open hangdict.txt\n"); 00089 } 00090 else { 00091 printf("hangdict.txt opened\n"); 00092 } 00093 int wordcount = 0; 00094 int wordlength = 0; 00095 int ch; 00096 while (EOF != (ch = getc(fp1))) { 00097 // check if character is an LF. It the word on that line is the right length, increment word counter 00098 if (ch == 10) { 00099 if ((wordlength > 7) && (wordlength < 15)) { 00100 wordcount = wordcount + 1; 00101 } 00102 wordlength = 0; 00103 } 00104 else { 00105 // if the character is not an LF, increment character count 00106 wordlength = wordlength + 1; 00107 } 00108 } 00109 fclose(fp1); 00110 printf("Word count: %u\n", wordcount); 00111 return wordcount; 00112 } 00113 00114 // ReturnWord is used to pick an indexed word from the hangdict.txt file 00115 int ReturnWord(int wordindex, char* word2guess) 00116 { 00117 FILE *fp1 = fopen("/sd/hangdict.txt", "r"); 00118 printf("Returning word %u: ", wordindex); 00119 for (int i = 0; i < wordindex; i++) { 00120 fgets(word2guess, 24, fp1); 00121 while ((strlen(word2guess) < 6) || (strlen(word2guess) > 12)) { 00122 fgets(word2guess, 24, fp1); 00123 } 00124 } 00125 printf("%s", word2guess); 00126 fclose(fp1); 00127 return (strlen(word2guess)-2); 00128 } 00129 */ 00130 00131 int main() 00132 { 00133 HAL::Initialise(); 00134 Flexbook::PageFactory factory; // Page creator 00135 Flexbook::Book book(factory); // Page container 00136 Flexbook::BookMonitor monitor(book); // Page turn monitor 00137 00138 //This section to test individual pages: 00139 book.PageChange(Flexbook::PageType_PageFlexEnable); 00140 //book.PageChange(Flexbook::PageType_PageSensor); 00141 //book.PageChange(Flexbook::PageType_PageTouch); 00142 //etc... 00143 00144 DisplayHardwareSettings(); 00145 00146 //Log("White screen in main"); 00147 //WriteColour(Get_epdc(), 0xff);//PL_WHITE); 00148 00149 wait(4); 00150 Log("Write partial image in main"); 00151 WritePartImage("/myfile.pgm", 60, 30, 60, 30, 100, 100); 00152 00153 wait(4); 00154 Log("Update display in main"); 00155 UpdateDisplay(); 00156 00157 Log("Write partial image 2"); 00158 WritePartImage("/myfile.pgm", 160, 100, 160, 100, 50, 200); 00159 00160 wait(4); 00161 UpdateDisplay(); 00162 00163 while(true) // Main loop 00164 { 00165 monitor.CheckForPageChange(); // Creates/destructs pages based on sensor touches 00166 // In this version only PageSensor or PageTouch can be active 00167 // Other pages are created as dependents 00168 book.HandleActions(); // Performs actions for the currently active page 00169 } 00170 }
Generated on Tue Jul 12 2022 21:14:35 by
