int kickoff() { initVideo(); putStr("Hello World! - Team Virtua!!!\n"); installDescriptorTables(); installTimer(); installKeyboard(); initializePaging(); putStr("Hello, paging world! - Team Virtua !!!\n"); enableInterrupts(); // u32 end_addr = (u32)&end; // u32 *ptr = (u32 *)end_addr; // while(1) { // putStr("End Address : "); // putHex(end_addr); // putStr(" "); // putHex((u32)ptr); // putStr(" : "); // putNum(*ptr); // putStr("\n"); // ptr++; // } putStr("Gotcha!!!\n"); for (;;); return 0; }
void da_setupScale() { high(pinCh0); high(pinCh1); pause(5); float vA = ad_volts(0); float vB = ad_volts(1); //print("%f %f\n", vA, vB); if( (vA > 3.1 && vA < 3.5 && vB > 3.1 && vB < 3.5)) { for(int i = 0; i < 39; i++) { vA += ad_volts(0); vB += ad_volts(1); } vA /= 40; vB /= 40; vA = 3.3 / vA; vB = 3.3 / vB; int addr = _abvolts_EE_start_; ee_putStr("abvolts", 8, addr); addr += 8; ee_putFloat32(vA, addr); addr += 4; ee_putFloat32(vB, addr); addr += 4; low(pinCh0); low(pinCh1); input(pinCh0); input(pinCh1); putStr("Ch0 scalar = "); putFloat(vA); putStr("\nCh1 scalar = "); putFloat(vB); putChar('\n'); putChar('\n'); abvolts_scale[0] = vA; abvolts_scale[1] = vB; } else { putStr("Error! Something went wrong. Check your circuit and power source."); } }
// // Print the help menu // static void helpFn(uint8_t argc, char *argv[]) { const command_t *command = commands; while(command->commandStr != NULL) { putStr(command->commandStr); putStr(" - "); putStr(command->helpStr); putStr("\n"); command++; } }
int attr2str(spConfigAttribute *attr,str *string) { int i; char buffer[32]; ENTRY; //write name for(i=0;i<(int)strlen(attr->name);++i) { switch(attr->name[i]) { case '"':case '#': case ']': case '/':case '<': case '\\': putStr(string,'\\'); default: putStr(string,attr->name[i]); } } //write = and value if(attr->type&0xf) //an actual attr, not a child/created attr { putStr(string,'='); switch(attr->type&0xf) { case SP_CONFIG_VALUE_INT: snprintf(buffer,32,"%i",attr->value.i); for(i=0;i<(int)strlen(buffer);++i) putStr(string,buffer[i]); break; case SP_CONFIG_VALUE_FLOAT: snprintf(buffer,32,"%f",attr->value.d); for(i=0;i<(int)strlen(buffer);++i) putStr(string,buffer[i]); break; case SP_CONFIG_VALUE_STRING: putStr(string,'"'); for(i=0;i<(int)strlen(attr->value.string);++i) { switch(attr->value.string[i]) { case '"':case '[': case '\\': case '#':case '/': case '>': putStr(string,'\\'); default: putStr(string,buffer[i]); } } putStr(string,'"'); break; } } return(0); }
void printTempWithCh(uint8_t ch) { uint32_t adcVal = 0; enableADCWithCh(ch); for(uint16_t count = 0; count < ADC_COUNT; count++){ adcVal += readADC(); } adcVal /= ADC_COUNT; putStr("T = "); printTemp(adcVal); putStr(" C\n"); }
void INFwfile::putComment(char *str) { putEnd(); putChar(';'); putStr(str); }
int getNChars_4lua(lua_State *L) { int n = getNumber(L); putStr(L, getNChars(n)); return 1; }
void INFwfile::putKey(char *str) { putEnd(); putStr(str); putChar('='); }
int text2str(char*text,str*string) { int i; ENTRY; for(i=0;i<(int)strlen(text);++i) { switch(text[i]) { case '<':case '[': case '#': case '/':case '\\': putStr(string,'\\'); default: putStr(string,text[i]); } } return(0); }
void INFwfile::putSection(char *str) { putEnd(); putChar('['); putStr(str); putChar(']'); }
int main(void) { unsigned long tmr1; int retVal; hardwareInit(); systemInit(); pnetNodeNumber = readNodeSw(); if (pnetNodeNumber == 0x0F) { sysStat |= ST_DEBUG_MODE; rs485TransmitEna(); putStr("\n\r DB CCS Child\r\n Ver "); // DEB, not for PROD putStr(verStr); putStr(", MLA\n\r"); menuDisplay(); putPrompt(); } rs485TransmitDisa(); while (1) { pnetNodeNumber = readNodeSw(); if (pnetNodeNumber == 0xF) sysStat |= ST_DEBUG_MODE; else sysStat &= ~ST_DEBUG_MODE; serialParse(); adcRHumid(ADC_SILENT); serialParse(); adcTemper(ADC_SILENT); adcTemperSecondary(ADC_SILENT); retVal = adcFloodSensor(ADC_SILENT); if (retVal == 1) sysStat |= ST_LIQUID_DETECTED; else if (retVal == 0) sysStat &= ~ST_LIQUID_DETECTED; if (sysStat & ST_DEBUG_MODE) LED_GREEN = 1; if (tmr1++ > 5000) { tmr1 = 0; childStateMach(CANCEL); // This is a crude timeout. Not sure how to improve it. We will rs485TransmitDisa(); // occasionally lose valid messages. But we need to break out of junky ones. } } // EO while (1) }
int getNCharsPrompt_4lua(lua_State *L) { char *str = (char *)getStr(L); int n = getNumber(L); putStr(L, getNCharsPrompt(n, str)); return 1; }
/*--------------------------------------------------------------------------- This function reads the entire file pointed to by handle into buffer. int fatRead(FileHandle *handle, uint8_t *buffer, uint32_t bufferSize) Where: FileHandle *handle - Pointer to an open file handle uint8_t *buffer - Pointer to a buffer to store the file uint32_t bufferSize - The size of the buffer Returns: -1 for error or the file size for success ---------------------------------------------------------------------------*/ int fatRead(FileHandle *handle, uint8_t *buffer, uint32_t bufferSize) { if(bufferSize >= handle->FileSize){ uint32_t clusterId = handle->startingCluster; uint32_t read = 0; uint32_t i; while(clusterId < FAT32_LAST_CLUSTER){ putStr("file name = "); for(i =0; i < 11; i++){ uart_putc(handle->fileName[i]); } putStr(", cluster = "); hexstring(clusterId); uart_putc('\n'); read += readCluster(clusterId, buffer+read); clusterId = nextFatEntry(clusterId); } return handle->FileSize; } return -1; } // End fatRead()
static Int putStrEsc ( Int n, Int n_buf, Int count, Char* buf, Char* str ) { Char alt[2]; vg_assert(n_buf > 0); vg_assert(count >= 0 && count < n_buf); vg_assert(n >= 0 && n < n_buf); for (; *str != 0; str++) { vg_assert(count >= 0); if (count <= 0) goto done; switch (*str) { case '&': if (count < 5) goto done; n = putStr( n, n_buf, buf, "&"); count -= 5; break; case '<': if (count < 4) goto done; n = putStr( n, n_buf, buf, "<"); count -= 4; break; case '>': if (count < 4) goto done; n = putStr( n, n_buf, buf, ">"); count -= 4; break; default: if (count < 1) goto done; alt[0] = *str; alt[1] = 0; n = putStr( n, n_buf, buf, alt ); count -= 1; break; } } done: vg_assert(count >= 0); /* should not go -ve in loop */ vg_assert(n >= 0 && n < n_buf); return n; }
int main(int argc, char* argv[]) { SDL_Event e; // Un eveniment care s-a intamplat. Folosit pentru a detecta inchiderea programului char quit; Mix_Music *backgroundMusic; int option; if(!init()) { // Daca nu s-a petrecut nici o eroare la initializare quit = 0; hideCursor(); // Cursorul dispare //system("color 37"); // Seteaza culoarea de fundal fillBackgroundCollor(BG_CYAN + WHITE); if(!DEBUG) { putStr((getConsoleWidth() - 13) / 2, getConsoleHeight() / 2, "Se incarca..."); Sleep(2500); putStr((getConsoleWidth() - 10) / 2, getConsoleHeight() / 2 + 1, "Degeaba..."); Sleep(500); } clearScreen(); backgroundMusic = Mix_LoadMUS(BACKGROUND_MUSIC_PATH); if(backgroundMusic == NULL) error("Nu s-a putut accesa fisierul cu melodia de fundal."); else Mix_PlayMusic(backgroundMusic, -1); option = buildMenu(); if(option == 2) quit = 1; while(!quit) { while(SDL_PollEvent(&e) != 0) { if(e.type == SDL_QUIT) quit = 1; } if(getKey(VK_ESCAPE)) quit = 1; Sleep(SLEEPCONST); } freeData(); } return 0; }
/** * @example Hybrid_Demo.cpp * * Use PropWare's PropWare::Printer interface for easy formatting of text, but use Simple's serial driver. This * combination allows for easy object-oriented programming while still using the Parallax-authored serial driver. * * @include PropWare_Simple_Hybrid/CMakeLists.txt */ int main () { SimplePrinter mySimpleCompatiblePrinter; const PropWare::Printer myPrinter(&mySimpleCompatiblePrinter); putStr("Hello from the Simple function!\n"); myPrinter.puts("Hello from PropWare's Printer!\n"); myPrinter.print("Hello from yet another Printer function!\n"); myPrinter.printf("All methods have their own merits. Choose one that works well for you.\n"); myPrinter.println("Printer::println() can be handy if you just want to print a single string"); myPrinter << "For lovers of C++ streams, you can even use the << operator!\n"; return 0; }
void putHex(u32 hex) { u8 num[8]; int i = 0; putStr("0x"); if(hex == 0) putChar('0'); while(hex > 0) { u32 rem = hex % 16; if(rem < 10) num[i++] = '0' + rem; else num[i++] = 'A' + rem - 10; hex /= 16; } while(--i >= 0) { putChar(num[i]); } }
int main(void) { char test[16] = "Hello WorldC"; char pstr[100]; char ip[10] = "127.0.0.1"; char port[6] = "12345"; int command; initCon(ip,port); command = getSerAc(); printf("%d\n",command); getStr(pstr,100); printf("%s\n",pstr); command = getSerAc(); printf("%d\n",command); putStr(test); return 0; }
RTFwfile::RTFwfile(const char *fname) : DCwfile(fname, ftxt) { if (Ferr || (fname == NULL)) return; LinePos = 0; AutoCR = true; Meta = 'I'; // Internal is default metanamewid = 5; metanumwid = 3; metanum = 0; *metaname = '\0'; putStr("{\\rtf1 "); }
void consoleProcess() { uint32_t inBytes = fifoSize(&rxFifo); if(inBytes > 0) { uint32_t newLine = 0; for(int32_t index = 0; index < inBytes; index++){ if(fifoPeek(&rxFifo, index) == '\n') { newLine = index + 1; break; } } if(newLine > sizeof(cmdBuff)) { newLine = sizeof(cmdBuff) - 1; } if(newLine) { uint8_t *pBuf = (uint8_t *)cmdBuff; while(newLine--){ *pBuf++ = fifoPop(&rxFifo); } *(pBuf - 1) = 0; // String terminator const command_t *command = commands; while(command->commandStr != NULL) { if(strcmp(command->commandStr, cmdBuff) == 0) { command->fn(0, NULL); break; } command++; } if(command->commandStr == NULL) { putStr("Unknown command\n"); helpFn(1, NULL); } } } }
status_t BnNativeService::onTransact(uint32_t code,const Parcel & data,Parcel *reply,uint32_t flags) { switch(code) { case PUT: { CHECK_INTERFACE(INativeSerice,data,reply); const char *name=data.readCString(); putStr(name); return NO_ERROR; } case PUT_STR: { return NO_ERROR; } default: return BBinder::onTransact(code,data,reply,flags); } }
int main() { int rc; int firstx ; int firsty ; int x ; int y ; int state ; TimeLimit4D = 2000; Callback4D = errCallback; // abort on detected 4D Serial error Error_Abort4D = 1 ; comspeed = 9600; //WORD *x = 0x001A; //char *s = sys_GetModel(&x); //x = &0x001A; rc = OpenComm(SERIALPORT, comspeed); if (rc != 0) { printf("Error %d Opening: %s - %s\n", errno, SERIALPORT, strerror(errno)); exit(EXIT_FAILURE); } gfx_Cls() ; putStr("Touch Tests\n") ; printf("Touch Tests.\n") ; putStr("Please ensure Touch is only\ndetected in the Blue area") ; printf("Detecting touch in Region\n") ; touch_Set(TOUCH_ENABLE) ; touch_DetectRegion(100,100, 200, 200) ; gfx_RectangleFilled(100,100, 200, 200, BLUE) ; do {} while (touch_Get(TOUCH_STATUS) != TOUCH_PRESSED); touch_Set(TOUCH_REGIONDEFAULT) ; gfx_Cls() ; putStr("Draw.. Drawing stops\nwhen touch released\n") ; printf("Drawing\n") ; while(touch_Get(TOUCH_STATUS) != TOUCH_PRESSED) { // we"ll wait for a touch } firstx = touch_Get(TOUCH_GETX); // so we can get the first point firsty = touch_Get(TOUCH_GETY); while(state != TOUCH_RELEASED) { state = touch_Get(TOUCH_STATUS); // look for any touch activity x = touch_Get(TOUCH_GETX); // grab the x y = touch_Get(TOUCH_GETY); // and the y coordinates of the touch if (state == TOUCH_PRESSED) // if there"s a press { firstx = x; firsty = y; } if (state == TOUCH_MOVING) // if there"s movement { gfx_Line(firstx, firsty, x, y, BLUE); // but lines are much better firstx = x; firsty = y; } } putStr("Done!\n") ; touch_Set(TOUCH_DISABLE); return (EXIT_SUCCESS); }
void kernelMain(void) { putStr("\nstarting kernel\n"); initGdt(); initTss(); initIdt(); putStr("mapping the first 2M with va = pa\n"); for (uint32_t p = 0; p < 0x200000; p += 4096) { vmm_map(p,p); } CHECK((getcr0() & 0x80000000) == 0); putStr("about to enable paging\n"); vmm_on(); CHECK((getcr0() & 0x80000000) != 0); CHECK (vmm_pa(0xf0000000) == 0xffffffff); uint32_t pa = vmm_frame(); vmm_map(0xf0000000, pa); CHECK (vmm_pa(0xf0000000) != 0xffffffff); CHECK ((vmm_pa(0xf0000123) & 0xfff) == 0x123); CHECK(vmm_dirty(0xf0000000) == 0); CHECK(vmm_accessed(0xf0000000) == 0); CHECK(peek(0xf0000000) == 0); CHECK(vmm_dirty(0xf0000000) == 0); CHECK(vmm_accessed(0xf0000000) == 1); poke(0xf0000000, 0x12345678); CHECK(peek(0xf0000000) == 0x12345678); CHECK(vmm_dirty(0xf0000000) == 1); CHECK(vmm_accessed(0xf0000000) == 1); CHECK(vmm_dirty(0xe0000000) == 0); CHECK(vmm_accessed(0xe0000000) == 0); CHECK(vmm_pa(0x40000000) == 0xffffffff); vmm_map(0xe0000000, pa); CHECK(peek(0xe0000000) == 0x12345678); CHECK(vmm_dirty(0xe0000000) == 0); CHECK(vmm_accessed(0xe0000000) == 1); CHECK(peek(0x44444444) == 0); CHECK(vmm_dirty(0x44444000) == 0); CHECK(vmm_accessed(0x44443000) == 0); CHECK(vmm_accessed(0x44444000) == 1); CHECK(vmm_accessed(0x44445000) == 0); poke(0x88888888,0x88888888); CHECK(peek(0x88888888) == 0x88888888); vmm_map(0xccccc000, vmm_pa(0x88888000)); CHECK(peek(0xccccc888) == 0x88888888); CHECK (vmm_pa(0xccccc666) == vmm_pa(0x88888666)); vmm_unmap(0xccccc000); CHECK(peek(0xccccc888) == 0); CHECK(peek(0x88888888) == 0x88888888); shutdown(); }
namespace { std::string upcase(std::string s) { std::transform(begin(s), end(s), begin(s), [](char c) { return static_cast<char>(std::toupper(c)); }); return s; } } TEST_CASE("io_monad", "") { SECTION("bind") { IO<U> io = putStr("Tell me your name!\n") .bind(getLine) .bind([](std::string str) { return putStr("Hi " + str + "\n"); }); io.run(); } SECTION("fmap") { IO<U> io = putStr("Tell me your name!\n") .bind(getLine) .fmap(upcase) .bind([](std::string str) { return putStr("Hi " + str + "\n"); }); io.run(); } }
/*--------------------------------------------------------------------------- This only reads from the primary boot record, it assumes it has been loaded by boot.s uint32_t initHDD(void) Where: Returns: 0 for success, non-zero for failure ---------------------------------------------------------------------------*/ uint32_t initHDD(void) { // Get bootRecord and volume id and filled IO_INIT bootRecord* b = (bootRecord*)readLBA(0); FAT_VolID* v = (FAT_VolID*)readLBA(b->par[0].LBA_Begin); MediaDescriptorGlobal.fatBeginLBA = b->par[0].LBA_Begin + v->reservedSectors; MediaDescriptorGlobal.dirBeginLBA = MediaDescriptorGlobal.fatBeginLBA + (v->numFats*v->sectorsPerFat); MediaDescriptorGlobal.sectorsPerCluster = v->sectorsPerCluster; MediaDescriptorGlobal.bytesPerSector = v->bytesPerSector; //Print all the information putStr("Boot record size="); hexstring(sizeof(bootRecord)); putStr(", Partition description size "); hexstring(sizeof(partitionDescription)); putStr("\nFAT VOL ID size="); hexstring(sizeof(FAT_VolID)); putStr(", ROOT DIR size = "); hexstring(sizeof(FAT_DirSector)); putStr("\nnum Sectors = "); hexstring(b->par[0].numSectors); putStr(", size = "); hexstring(b->par[0].numSectors*v->bytesPerSector/1048576); putStr(" (MB)\nLBA starts at "); hexstring(b->par[0].LBA_Begin); putStr("\nbytes per sector="); hexstring(v->bytesPerSector); putStr(", sectors per cluster="); hexstring(v->sectorsPerCluster); putStr(", reserved sectors "); hexstring(v->reservedSectors); putStr("\nnumber of FATS "); hexstring(v->numFats); putStr(", sectors per fat "); hexstring(v->sectorsPerFat); putStr(", root cluster "); hexstring(v->rootCluster); putStr(", signature "); hexstring(v->signature); putStr("\nFAT Begin LBA = "); hexstring(MediaDescriptorGlobal.fatBeginLBA); putStr(", Cluster begin LBA = "); hexstring(MediaDescriptorGlobal.dirBeginLBA); uart_putc((uint32_t)'\n'); return(0); } // End initHDD
void RTFwfile::CloseFile() { putStr("\n}\n"); DCwfile::CloseFile(); }
// --------------------- void serialParse(void) { char charCh; byte hexRead, oldHexRead; charCh = getChar(); if (!charCh) return; if (sysStat & ST_DEBUG_MODE) // Super commands for Monitor { rs485TransmitEna(); putChar(charCh); switch(charCh) { case 'd': putStr("\tNode ID switch test.\n\r"); putStr("\tHit any key to quit.\n\r"); rs485TransmitDisa(); while(1) { charCh = getChar(); if (charCh) break; hexRead = readNodeSw(); if (hexRead != oldHexRead) { rs485TransmitEna(); sprintf(ioBfr, "\n\r Node ID: %02Xh", hexRead); putStr(ioBfr); oldHexRead = hexRead; rs485TransmitDisa(); } } break; case 'f': putStr("\tFlood sensor test: "); adcFloodSensor(ADC_LOQUACIOUS); break; case 'h': adcRHumid(ADC_LOQUACIOUS); break; case 'r': reportInfo(); break; case 't': adcTemper(ADC_LOQUACIOUS); break; case 'T': adcTemperSecondary(ADC_LOQUACIOUS); break; case '1': RELAY1 ^= 1; if (RELAY1) putStr("\tRelay 1 on"); else putStr("\tRelay 1 off"); break; case '2': RELAY2 ^= 1; if (RELAY2) putStr("\tRelay 2 on"); else putStr("\tRelay 2 off"); break; case '3': SwiPwr1 ^= 1; if (SwiPwr1) putStr("\tSwi Pwr1 on"); else putStr("\tSwi Pwr1 off"); break; case '4': SwiPwr2 ^= 1; if (SwiPwr2) putStr("\tSwi Pwr2 on"); else putStr("\tSwi Pwr2 off"); break; case '?': menuDisplay(); break; } // EO switch putPrompt(); rs485TransmitDisa(); } // EO if debug else { childStateMach(charCh); } }
void menuDisplay(void) { putStr("\n\r * Child / commands *\n\r"); putStr(" d - rd DIPSWs\n\r"); putStr(" f - flood sensor\n\r"); putStr(" h - rd rhumid sen\n\r"); putStr(" r - report info\n\r"); putStr(" R - smem Read test\n\r"); putStr(" t - rd T sen\n\r"); putStr(" T - rd secondary T sen\n\r"); //putStr(" W - smem destr. Wr test *\n\r"); putStr(" 1 - toggle rly 1\n\r"); putStr(" 2 - toggle rly 2\n\r"); putStr(" 3 - toggle swi pwr1\n\r"); putStr(" 4 - toggle swi pwr2\n\r"); putStr(" ? - this menu\n\r"); putStr("\n\r"); }
// -------------------------------- void reportInfo(void) { putPrompt(); putStr("\n\r CCS Child Monitor, MLA"); putStr("\n\r Ver: "); putStr(verStr); putStr("\n\r PNet ver: "); putChar(pnetVer); putStr("\n\r UID: "); putStr(uniqueID); sprintf(ioBfr, "\n\r Node: %02X", pnetNodeNumber); putStr(ioBfr); //putChar('0' + pnetNodeNumber); putStr("\n\r Sys st: "); putUns2Hex(sysStat); putStr("\n\r Relays: "); if (RELAY1) putChar('+'); else putChar('-'); if (RELAY2) putChar('+'); else putChar('-'); putStr("\n\r Switched Pwr: "); if (SwiPwr1) putChar('+'); else putChar('-'); if (SwiPwr2) putChar('+'); else putChar('-'); sprintf(ioBfr, "\n\r vRef: %4.03f V\r\n", vRef); putStr(ioBfr); adcTemper(ADC_SILENT); putStr("\n\r Temp now: "); sprintf(ioBfr, "%2.01foF [%4.03f]", temperNowF, temper1CalFactor); putStr(ioBfr); adcTemperSecondary(ADC_SILENT); putStr("\n\r Sec temp now: "); sprintf(ioBfr, "%2.01foF [%4.03f]", temperSecondaryF, temper2CalFactor); putStr(ioBfr); adcRHumid(ADC_SILENT); putStr("\n\r Humid now: "); sprintf(ioBfr, "%2.01f [%4.03f]",rhumidNow, rhumidCalFactor); putStr(ioBfr); putStr("\n\r"); }
int node2str(spConfigNode*node,str*string) { int i; ENTRY; if(node->text) text2str(node->text,string); putStr(string,'<'); for(i=0;i<(int)strlen(node->name);++i) { switch(node->name[i]) { case '[':case '>': case '\\': case '"':case '/': putStr(string,'\\'); default: putStr(string,node->name[i]); } } putStr(string,' '); for(i=0;i<node->numAttributes;++i) { attr2str(node->attributes[i],string); } if(node->numChildren) { putStr(string,'>'); for(i=0;i<node->numChildren;++i) { node2str(node->children[i],string); } putStr(string,'<'); putStr(string,'/'); for(i=0;i<(int)strlen(node->name);++i) { switch(node->name[i]) { case '[':case '>': case '\\': case '"':case '/': putStr(string,'\\'); default: putStr(string,node->name[i]); } } putStr(string,'>'); } else { putStr(string,'/'); putStr(string,'>'); } return(0); }