int main (void) { uint8_t no = 0; // wait(10); setMU2PutFunc(uart0Put); setMU2GetFunc(uart0Get); initUART( UART0, StopBitIs1Bit|NonParity, ReceiverEnable|TransmiterEnable|ReceiveCompleteInteruptEnable, UARTBAUD(19200) ); initLED(); initSwitch(); initRCRx(); no = Switch() & 0x03; mu2Command("EI",EI[no]); mu2Command("DI",DI[no]); mu2Command("GI",GI[no]); mu2Command("CH",CH[no]); sei(); userMain(); return 0; }
bool Hal::initHal() { debugPrintLn("Start init"); // initialize all the hardware initLora(); initSwitch(); initLTC(); compass.init(); compass.enableDefault(); htu.begin(); // setAckOn(); debugPrintLn("Einde init"); }
int main(int argc, char *argv[]) { char c; BankAuthorizer user; Switch switchTrans; initUser(&user); initSwitch(&switchTrans); while ((c = getopt(argc, argv, "u:c:h:p:l:")) != -1) switch (c) { case 'u': user.id = atol(optarg); break; case 'c': strcpy(user.password, optarg); break; case 'h': printf("Host: %s\n", optarg); strcpy(switchTrans.host, optarg); break; case 'p': printf("Puerto: %s\n", optarg); switchTrans.port = atoi(optarg); break; case 'l': printf("Logfile: %s\n", optarg); break; case '?': default: printf("Uso: auth-trx bla bla"); break; } getAuthorizer(&user); connectToSwitch(&switchTrans, &user); close(switchTrans.fd); processTransactions(); return EXIT_SUCCESS; }
int main() { SYSTEMConfigPerformance(10000000); //Does something with assembly to set clock speed enableInterrupts(); //Make interrupt work initLEDs(); initTimer1(); initTimer2(); initTimer3(); initTimer4(); initSwitch(); porta = PORTA; portd = PORTD; initLCD(); delay(500); //printCharLCD(0); testLCD(); state = InitState; nextState = InitState; while (1) { switch (state) { case RUN: #ifdef _DEBUG_ LATDbits.LATD0=0; LATDbits.LATD1=0; LATDbits.LATD2=1; #endif LATGbits.LATG14=LedOFF; //TRD1 LATGbits.LATG12=LedON; //TRD2 moveCursorLCD(0,0); printStringLCD("Running..."); if(counterCN==1){ // If the counter changed... printTimeLCD(counter); counterCN = 0; } if(AllowChange == 0){ delay(5000); delay(5000); delay(5000); delay(5000); AllowChange = 1; } if((ReqChange==1) && (AllowChange==1)){ state=WAIT1; ReqChange=0; AllowChange=0; // CNCONAbits.ON = 1; } break; case STOP: #ifdef _DEBUG_ LATDbits.LATD0=1; LATDbits.LATD1=0; LATDbits.LATD2=0; #endif LATGbits.LATG14=LedON; LATGbits.LATG12=LedOFF; moveCursorLCD(0,0); printStringLCD("Stopped"); if(AllowChange == 0){ delay(5000); delay(5000); delay(5000); delay(5000); AllowChange = 1; } if(AllowReset == 0){ delay(5000); delay(5000); delay(5000); delay(5000); AllowReset = 1; } if((ReqReset==1) && (AllowReset==1)){ AllowReset = 0; ReqReset = 0; counter = 0; printTimeLCD(counter); } if((ReqChange==1) && (AllowChange==1)){ state=WAIT2; ReqChange=0; AllowChange=0; // CNCONAbits.ON = 1; } break; case WAIT1: #ifdef _DEBUG_ LATDbits.LATD0=0; LATDbits.LATD1=1; LATDbits.LATD2=1; #endif T1CONbits.ON = 0; // Turn off counter if(AllowChange == 0){ delay(5000); delay(5000); delay(5000); delay(5000); AllowChange = 1; } if((ReqChange==1) && (AllowChange==1)){ state=STOP; ReqChange=0; AllowChange=0; ReqReset = 0; // So we don't reset as soon as we stop... AllowReset = 0; // See previous line // CNCONAbits.ON = 1; } break; case WAIT2: #ifdef _DEBUG_ LATDbits.LATD0=1; LATDbits.LATD1=1; LATDbits.LATD2=0; #endif T1CONbits.ON = 1; // Turn on counter if(AllowChange == 0){ delay(5000);// The sad part is this didn't even work. delay(5000); delay(5000); delay(5000); AllowChange = 1; } if((ReqChange==1) && (AllowChange==1)){ // Button Changed and De-bouncing period is done state=RUN; ReqChange=0; AllowChange=0; //CNCONAbits.ON = 1; } break; case InitState:// Only happens once state=STOP; clearLCD(); counter = 0; printTimeLCD(counter); T1CONbits.ON = 0; TMR1 = 0; break; default:// Should never happen. How did you get here? state=InitState; ReqChange = 0; AllowChange=0; break; } } return 0; }
int main (int argc, char **argv) { char *inlist; /* input file name */ char *outlist; /* output blev file name */ /*int switch_on = 0;*/ /* was any switch specified? */ int printtime = NO; /* print time after each step? */ int verbose = NO; /* print additional info? */ int quiet = NO; /* print additional info? */ int too_many = 0; /* too many command-line arguments? */ int i, j; /* loop indexes */ int k; IRAFPointer i_imt, o_imt; /* imt list pointers */ char *input; /* name of input science file */ char *output; /* name of output file */ int n_in, n_out; /* number of files in each list */ int n; /* Input and output suffixes. */ char isuffix[] = "_raw"; char osuffix[] = "_blv_tmp"; /* A structure to pass the calibration switches to ACSCCD */ CalSwitch ccd_sw; /* reference file keywords and names */ RefFileInfo refnames; void InitRefFile (RefFileInfo *); void FreeRefFile (RefFileInfo *); void initSwitch (CalSwitch *); int ACSccd (char *, char *, CalSwitch *, RefFileInfo *, int, int); int DefSwitch (char *); int MkName (char *, char *, char *, char *, char *, int); void WhichError (int); int CompareNumbers (int, int, char *); /* For image header access */ Hdr phdr; int LoadHdr (char *, Hdr *); int GetSwitch (Hdr *, char *, int *); c_irafinit (argc, argv); /* Allocate space for file names. */ inlist = calloc (ACS_LINE+1, sizeof (char)); outlist = calloc (ACS_LINE+1, sizeof (char)); input = calloc (ACS_LINE+1, sizeof (char)); output = calloc (ACS_LINE+1, sizeof (char)); if (inlist == NULL || outlist == NULL || input == NULL || output == NULL) { printf ("Can't even begin; out of memory.\n"); exit (ERROR_RETURN); } inlist[0] = '\0'; outlist[0] = '\0'; input[0] = '\0'; output[0] = '\0'; /* Initialize the lists of reference file keywords and names. */ InitRefFile (&refnames); /* Initial values. */ initSwitch (&ccd_sw); for (i = 1; i < argc; i++) { /********** if (strcmp (argv[i], "-dqi") == 0) { ccd_sw.dqicorr = PERFORM; switch_on = 1; } else if (strcmp (argv[i], "-atod") == 0) { ccd_sw.atodcorr = PERFORM; switch_on = 1; } else if (strcmp (argv[i], "-blev") == 0) { ccd_sw.blevcorr = PERFORM; switch_on = 1; } else if (strcmp (argv[i], "-bias") == 0) { ccd_sw.biascorr = PERFORM; switch_on = 1; } else if (argv[i][0] == '-') { **********/ if (argv[i][0] == '-') { for (j = 1; argv[i][j] != '\0'; j++) { if (argv[i][j] == 't') { printtime = YES; } else if (argv[i][j] == 'v') { verbose = YES; } else if (argv[i][j] == 'q') { quiet = YES; } else { printf (MsgText, "Unrecognized option %s\n", argv[i]); FreeNames (inlist, outlist, input, output); exit (1); } } } else if (inlist[0] == '\0') { strcpy (inlist, argv[i]); } else if (outlist[0] == '\0') { strcpy (outlist, argv[i]); } else { too_many = 1; } } if (inlist[0] == '\0' || too_many) { printf ("syntax: acsccd [-t] [-v] [-q] input output\n"); /* printf (" command-line switches:\n"); printf (" -dqi -atod -blev -bias\n"); */ FreeNames (inlist, outlist, input, output); exit (ERROR_RETURN); } /* Initialize the structure for managing trailer file comments */ InitTrlBuf (); /* Copy command-line value for QUIET to structure */ SetTrlQuietMode(quiet); /* Was no calibration switch specified on command line? default values (mostly PERFORM) except ATODCORR if (!switch_on) {*/ ccd_sw.dqicorr = DefSwitch ("dqicorr"); ccd_sw.atodcorr = DefSwitch ("atodcorr"); ccd_sw.blevcorr = DefSwitch ("blevcorr"); ccd_sw.biascorr = DefSwitch ("biascorr"); /*}*/ /* Expand the templates. */ i_imt = c_imtopen (inlist); o_imt = c_imtopen (outlist); n_in = c_imtlen (i_imt); n_out = c_imtlen (o_imt); /* The number of input and output files must be the same. */ if (CompareNumbers (n_in, n_out, "output")) status = 1; if (status) { FreeNames (inlist, outlist, input, output); CloseTrlBuf(); exit (ERROR_RETURN); } /* Loop over the list of input files. */ for (n = 0; n < n_in; n++) { k = c_imtgetim (i_imt, input, ACS_LINE); if (n_out > 0) k = c_imtgetim (o_imt, output, ACS_LINE); else output[0] = '\0'; /* Open input image in order to read its primary header. */ if (LoadHdr (input, &phdr)) { WhichError (status); sprintf (MsgText, "Skipping %s", input); trlmessage (MsgText); continue; } /* Determine osuffix. */ strcpy(osuffix, "_blv_tmp"); if (MkName (input, isuffix, osuffix, "", output, ACS_LINE)) { WhichError (status); sprintf (MsgText, "Skipping %s", input); trlmessage (MsgText); continue; } /* Calibrate the current input file. */ if (ACSccd (input, output, &ccd_sw, &refnames, printtime, verbose)) { sprintf (MsgText, "Error processing %s.", input); trlerror (MsgText); WhichError (status); } } /* Close lists of file names, and free name buffers. */ c_imtclose (i_imt); c_imtclose (o_imt); CloseTrlBuf(); FreeRefFile (&refnames); FreeNames (inlist, outlist, input, output); if (status) exit (ERROR_RETURN); else exit (0); }
int main(void) { LPC_GPIO2->DIR |= (1<<10); /* PLL is already setup */ SystemCoreClockUpdate(); /* Blue LED Set as output */ /* Relay EN Set as output */ LPC_GPIO1->DIR |= (1<<5); uartInit(115200); puts("Sys Initted\n"); puts("uart Initted\n"); initSwitch(); puts("Switches Initted\n"); SysTick_Config(SystemCoreClock/1000); puts("SysTick Initted\n"); setup_pwm(1000,4092); puts("PWM Initted\n"); setup_GPIO_INT(); puts("GPIO INT Initted\n"); filt_adc_init(450); delay_ms(500); puts("Filt ADC Initted\n"); while(1) { while(next_run > msTicks) __WFI(); next_run= msTicks + 10; if ((msTicks - last_motion ) > (MAX(W_POWER_OFF_TIME_MS + RAMP_DOWN_TIME_MS, RGB_POWER_OFF_TIME_MS + RAMP_DOWN_TIME_MS ) + 2000)) { shut_off_supply(); transfer_to_sleep(); turn_on_supply(); /* Wait for the power to actually come on before starting the ramp up */ } // WW_SWITCH_HANDLER // debounce for 20ms, since we check for the absolute val if the user // holds the switch forever it will only trigger the service once if(getSwitch(WW_SWITCH) == 0) { if(ww_sw_asserted == 5) { puts("WW SWITCH PRESSED\n"); white_on = !white_on; white_scale = 0; } ww_sw_asserted += 1; } else ww_sw_asserted = 0; // OFF_SWITCH_HANDLER // debounce for 20ms, since we check for the absolute val if the user // holds the switch forever it will only trigger the service once if(getSwitch(OFF_SWITCH) == 0) { if(off_sw_asserted == 5) { puts("OFF SWITCH PRESSED\n"); white_on = 0; white_scale = 0; rgb_on = 0; rgb_scale = 0; } off_sw_asserted += 1; } else off_sw_asserted = 0; // RGB_SWITCH_HANDLER // debounce for 20ms, since we check for the absolute val if the user // holds the switch forever it will only trigger the service once if(getSwitch(RGB_SWITCH) == 0) { if(rgb_sw_asserted == 5) { puts("RGB SWITCH PRESSED\n"); rgb_on = !rgb_on; rgb_scale = 0; } if(rgb_sw_asserted == 100) { puts("RGB SWITCH HELD\n"); rgb_on = 2; } if(rgb_sw_asserted == 500) { puts("RGB SWITCH LONG HELD\n"); rgb_on = 3; } rgb_sw_asserted += 1; } else rgb_sw_asserted = 0; /* This handles the WW LEDs */ if (((msTicks - last_motion ) > W_POWER_OFF_TIME_MS) && white_on) { white_scale = RAMP_DOWN_TIME_MS - ((msTicks - last_motion) - W_POWER_OFF_TIME_MS); if ((msTicks - last_motion) > (W_POWER_OFF_TIME_MS + RAMP_DOWN_TIME_MS)) white_scale = 0; } if ( white_scale < RAMP_DOWN_TIME_MS && white_on && ((msTicks - last_motion ) < W_POWER_OFF_TIME_MS)) { white_scale = msTicks - last_motion; /* Check just in case we get held up and skip the 1000th ms after motion */ if ( white_scale > RAMP_DOWN_TIME_MS) white_scale = RAMP_DOWN_TIME_MS; } if (white_scale != RAMP_DOWN_TIME_MS) { setWW( (white_scale * getADCVal(WW_POT)) / RAMP_DOWN_TIME_MS ); setWW2( (white_scale * getADCVal(WW_POT)) / RAMP_DOWN_TIME_MS ); } else { setWW(getADCVal(WW_POT)); setWW2(getADCVal(WW_POT)); } /* This handles the RGB LEDs */ if (((msTicks - last_motion ) > RGB_POWER_OFF_TIME_MS) && rgb_on) { rgb_scale = RAMP_DOWN_TIME_MS - ((msTicks - last_motion) - RGB_POWER_OFF_TIME_MS); if ((msTicks - last_motion) > (RGB_POWER_OFF_TIME_MS + RAMP_DOWN_TIME_MS)) rgb_scale = 0; } if ( rgb_scale < RAMP_DOWN_TIME_MS && rgb_on && ((msTicks - last_motion ) < RGB_POWER_OFF_TIME_MS)) { rgb_scale = msTicks - last_motion; /* Check just in case we get held up and skip the 1000th ms after motion */ if ( rgb_scale > RAMP_DOWN_TIME_MS) rgb_scale = RAMP_DOWN_TIME_MS; } if (rgb_on == 1 || rgb_on == 0) { if (rgb_scale != RAMP_DOWN_TIME_MS) setRGB((rgb_scale * getADCVal(RED_POT)) / RAMP_DOWN_TIME_MS, (rgb_scale * getADCVal(GREEN_POT)) / RAMP_DOWN_TIME_MS, (rgb_scale * getADCVal(BLUE_POT)) / RAMP_DOWN_TIME_MS ); else setRGB(getADCVal(RED_POT), getADCVal(GREEN_POT), getADCVal(BLUE_POT)); } else if (rgb_on == 2) { uint32_t R,G,B; h2rgb((msTicks)%(H2RGB_OUT_RANGE*6), &R, &G, &B); if (rgb_scale != RAMP_DOWN_TIME_MS) setRGB((rgb_scale * R) / RAMP_DOWN_TIME_MS, (rgb_scale * G) / RAMP_DOWN_TIME_MS, (rgb_scale * B) / RAMP_DOWN_TIME_MS ); else setRGB(R, G, B); } else if (rgb_on == 3) { uint32_t R,G,B; if (rgb_mode_3_next_change < msTicks) { rgb_mode_3_next_change = msTicks + (getADCVal(RED_POT)/4); rgb_mode_3_color += 2; if(rgb_mode_3_color >=6) rgb_mode_3_color = 0; } h2rgb((H2RGB_OUT_RANGE * rgb_mode_3_color), &R, &G, &B); if (rgb_scale != RAMP_DOWN_TIME_MS) setRGB((rgb_scale * R) / RAMP_DOWN_TIME_MS, (rgb_scale * G) / RAMP_DOWN_TIME_MS, (rgb_scale * B) / RAMP_DOWN_TIME_MS ); else setRGB(R, G, B); } } }
int main() { cli(); disableWatchdog(); slowClock(); initBuzzer(); initSwitch(); initADC(); #ifdef DEBUG uint16_t v = getVoltage(); uint16_t i; for (i = 0x8000; i != 0; i >>= 1) { if (v & i) { dit(); } else { dah(); } _delay_ms(1000); } #endif // Retrieve the current warning timeout from eeprom uint8_t warn_min = eeprom_read_byte(&cfg_warn_min); if (switchPressed()) { number(warn_min); // pause between increments _delay_ms(3000); } // If switch is depressed (at power up), begin increasing // warning time, in 5-minute increments, max 30 minutes // SOS time is 2 x warning time. // while (switchPressed()) { if (switchPressed()) { // Increment warning time by 5 minutes warn_min += 5; // Maximum warning time is 30 minutes if (warn_min > 30) warn_min = 5; // Save the new warning time eeprom_update_byte(&cfg_warn_min, warn_min); } number(warn_min); // pause between increments _delay_ms(3000); } // Compute the number of seconds for warning and SOS warn_sec = warn_min * 60; sos_sec = warn_sec * 2; if (checkVoltage()) { ok(); } else { sos(); } enableWatchdog(); sei(); while (1) { set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_mode(); } }
// main int main(void) { // stop watchdog timer WDTCTL = WDTPW + WDTHOLD; //Initialize clock and peripherals halBoardInit(); halBoardStartXT1(); halBoardSetSystemClock(SYSCLK_16MHZ); // init debug UART halUsbInit(); // init LEDs P1OUT |= LED_1 | LED_2; P1DIR |= LED_1 | LED_2; /*//init linkLED P1OUT &= ~BIT0; P1DIR |= BIT0;*/ //Setup Input Port 2 initSwitch(2, BIT0); initSwitch(2, BIT1); initSwitch(2, BIT2); initSwitch(2, BIT3); //tie port3 and unused pins of port 2 /*P3OUT = 0; P3DIR = 0xFF; P3SEL = 0; P2OUT &= 0x0F; P2DIR |= 0xF0; P2SEL &= 0x0F;*/ /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_EMBEDDED); // add gpio port 2 to run loop // default values port2_status = P2IN & 0x0F; data_source_t data_src_port2; data_src_port2.process = port2_poll; data_src_port2.fd = 0; run_loop_add_data_source(&data_src_port2); // init HCI hci_transport_t * transport = hci_transport_h4_dma_instance(); bt_control_t * control = bt_control_cc256x_instance(); hci_uart_config_t * config = hci_uart_config_cc256x_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; hci_init(transport, config, control, remote_db); // use eHCILL bt_control_cc256x_enable_ehcill(1); // init L2CAP l2cap_init(); l2cap_register_packet_handler(bt_packet_handler); l2cap_register_service_internal(NULL, l2cap_packet_handler, 0x1001, L2CAP_MINIMAL_MTU); // ready - enable irq used in h4 task __enable_interrupt(); // turn on! if(hci_power_control(HCI_POWER_ON)) printf("power on failed"); //init i2c initi2c(); // go! run_loop_execute(); // happy compiler! return 0; }