static int symbol_import0(void *Ignore, const char *Name, int *IsRef, void **Data) { module_t *LangSymbol = module_load(0, "Lang/Symbol"); int IsRef0; module_import(LangSymbol, "_new_string", &IsRef0, (void **)&make_symbol); module_import(LangSymbol, "_add_methods", &IsRef0, (void **)&add_methods); module_setup(Symbol, 0, symbol_import); return symbol_import(0, Name, IsRef, Data); };
static int directory_load(module_t *Module, const char *FileName) { struct stat Stat; stat(FileName, &Stat); if (S_ISDIR(Stat.st_mode)) { module_setup(Module, canonicalize_file_name(FileName), (module_importer)directory_import); } else { return 0; }; };
static int directory_load(module_t *Module, const char *FileName) { DWORD FileAttributes = GetFileAttributes(FileName); if (FileAttributes & FILE_ATTRIBUTE_DIRECTORY) { int Length = strlen(FileName); char *Path = GC_malloc_atomic(Length + 2); strcpy(Path, FileName); Path[Length] = '\\'; Path[Length + 1] = 0; module_setup(Module, Path, (module_importer)directory_import); } else { return 0; }; };
int main() { io_pins_setup(); module_setup(); adc_setup(); timer1_setup(); // enable global interrupts sei(); while (1) { comms_update(); if (adc_z_want_update) adc_buffer_update(); } return (0); }
PyMODINIT_FUNC initGPIO(void) #endif { PyObject *module = NULL; #if PY_MAJOR_VERSION > 2 if ((module = PyModule_Create(&rpigpiomodule)) == NULL) goto exit; #else if ((module = Py_InitModule("RPi.GPIO", rpi_gpio_methods)) == NULL) goto exit; #endif WrongDirectionException = PyErr_NewException("RPi.GPIO.WrongDirectionException", NULL, NULL); PyModule_AddObject(module, "WrongDirectionException", WrongDirectionException); InvalidModeException = PyErr_NewException("RPi.GPIO.InvalidModeException", NULL, NULL); PyModule_AddObject(module, "InvalidModeException", InvalidModeException); InvalidDirectionException = PyErr_NewException("RPi.GPIO.InvalidDirectionException", NULL, NULL); PyModule_AddObject(module, "InvalidDirectionException", InvalidDirectionException); InvalidChannelException = PyErr_NewException("RPi.GPIO.InvalidChannelException", NULL, NULL); PyModule_AddObject(module, "InvalidChannelException", InvalidChannelException); InvalidPullException = PyErr_NewException("RPi.GPIO.InvalidPullException", NULL, NULL); PyModule_AddObject(module, "InvalidPullException", InvalidPullException); ModeNotSetException = PyErr_NewException("RPi.GPIO.ModeNotSetException", NULL, NULL); PyModule_AddObject(module, "ModeNotSetException", ModeNotSetException); SetupException = PyErr_NewException("RPi.GPIO.SetupException", NULL, NULL); PyModule_AddObject(module, "SetupException", SetupException); high = Py_BuildValue("i", HIGH); PyModule_AddObject(module, "HIGH", high); low = Py_BuildValue("i", LOW); PyModule_AddObject(module, "LOW", low); output = Py_BuildValue("i", OUTPUT); PyModule_AddObject(module, "OUT", output); input = Py_BuildValue("i", INPUT); PyModule_AddObject(module, "IN", input); board = Py_BuildValue("i", BOARD); PyModule_AddObject(module, "BOARD", board); bcm = Py_BuildValue("i", BCM); PyModule_AddObject(module, "BCM", bcm); pud_off = Py_BuildValue("i", PUD_OFF); PyModule_AddObject(module, "PUD_OFF", pud_off); pud_up = Py_BuildValue("i", PUD_UP); PyModule_AddObject(module, "PUD_UP", pud_up); pud_down = Py_BuildValue("i", PUD_DOWN); PyModule_AddObject(module, "PUD_DOWN", pud_down); if (module_setup() != SETUP_OK) { #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif } if (Py_AtExit(gpio_cleanup) != 0) gpio_cleanup(); goto exit; exit: #if PY_MAJOR_VERSION > 2 return module; #else return; #endif }
int main(int argc, char *argv[]) { FILE *fp; Recog *recog; Jconf *jconf; /* inihibit system log output (default: stdout) */ //jlog_set_output(NULL); /* output system log to a file */ // FILE *fp = fopen(logfile, "w"); jlog_set_output(fp); /* if no option argument, output julius usage and exit */ if (argc == 1) { fprintf(stderr, "Julius rev.%s - based on ", JULIUS_VERSION); j_put_version(stderr); fprintf(stderr, "Try '-setting' for built-in engine configuration.\n"); fprintf(stderr, "Try '-help' for run time options.\n"); return -1; } /* add application options */ record_add_option(); module_add_option(); charconv_add_option(); j_add_option("-separatescore", 0, 0, "output AM and LM scores separately", opt_separatescore); j_add_option("-logfile", 1, 1, "output log to file", opt_logfile); j_add_option("-nolog", 0, 0, "not output any log", opt_nolog); j_add_option("-outfile", 0, 0, "save result in separate .out file", opt_outfile); j_add_option("-help", 0, 0, "display this help", opt_help); j_add_option("--help", 0, 0, "display this help", opt_help); /* create a configuration variables container */ jconf = j_jconf_new(); // j_config_load_file(jconf, jconffile); if (j_config_load_args(jconf, argc, argv) == -1) { fprintf(stderr, "Try `-help' for more information.\n"); return -1; } /* output system log to a file */ if (nolog) { jlog_set_output(NULL); } else if (logfile) { fp = fopen(logfile, "w"); jlog_set_output(fp); } /* here you can set/modify any parameter in the jconf before setup */ // jconf->input.input_speech = SP_MIC; /* Fixate jconf parameters: it checks whether the jconf parameters are suitable for recognition or not, and set some internal parameters according to the values for recognition. Modifying a value in jconf after this function may be errorous. */ if (j_jconf_finalize(jconf) == FALSE) { if (logfile) fclose(fp); return -1; } /* create a recognition instance */ recog = j_recog_new(); /* assign configuration to the instance */ recog->jconf = jconf; /* load all files according to the configurations */ if (j_load_all(recog, jconf) == FALSE) { fprintf(stderr, "ERROR: Error in loading model\n"); if (logfile) fclose(fp); return -1; } #ifdef USER_LM_TEST { PROCESS_LM *lm; for(lm=recog->lmlist;lm;lm=lm->next) { if (lm->lmtype == LM_PROB) { j_regist_user_lm_func(lm, my_uni, my_bi, my_lm); } } #endif /* checkout for recognition: build lexicon tree, allocate cache */ if (j_final_fusion(recog) == FALSE) { fprintf(stderr, "ERROR: Error while setup work area for recognition\n"); j_recog_free(recog); if (logfile) fclose(fp); return -1; } /* Set up some application functions */ /* set character conversion mode */ if (charconv_setup() == FALSE) { if (logfile) fclose(fp); return -1; } if (is_module_mode()) { /* set up for module mode */ /* register result output callback functions to network module */ module_setup(recog, NULL); } else { /* register result output callback functions to stdout */ setup_output_tty(recog, NULL); } /* if -outfile option specified, callbacks for file output will be regitered */ if (outfile_enabled) { if (jconf->input.speech_input == SP_MFCFILE || jconf->input.speech_input == SP_RAWFILE) { setup_output_file(recog, NULL); } else { fprintf(stderr, "Warning: -outfile works only for file input, disabled now\n"); outfile_enabled = FALSE; } } /* setup recording if option was specified */ record_setup(recog, NULL); /* on module connect with client */ if (is_module_mode()) module_server(); /* initialize and standby the specified audio input source */ /* for microphone or other threaded input, ad-in thread starts here */ if (j_adin_init(recog) == FALSE) return; /* output system information to log */ j_recog_info(recog); #ifdef VISUALIZE /* Visualize: initialize GTK */ visual_init(recog); callback_add(recog, CALLBACK_EVENT_RECOGNITION_END, visual_show, NULL); callback_add(recog, CALLBACK_EVENT_PASS2_BEGIN, visual2_init, NULL); callback_add(recog, CALLBACK_DEBUG_PASS2_POP, visual2_popped, NULL); callback_add(recog, CALLBACK_DEBUG_PASS2_PUSH, visual2_next_word, NULL); /* below should be called at result */ visual2_best(now, winfo); /* 音声取り込みはコールバックで新規作成 */ /* 第2パスで認識結果出力時に以下を実行 */ visual2_best(now, recog->model->winfo); #endif /* if no grammar specified on startup, start with pause status */ { RecogProcess *r; boolean ok_p; ok_p = TRUE; for(r=recog->process_list;r;r=r->next) { if (r->lmtype == LM_DFA) { if (r->lm->winfo == NULL) { /* stop when no grammar found */ j_request_pause(recog); } } } } /* enter recongnition loop */ main_recognition_stream_loop(recog); /* end proc */ if (is_module_mode()) module_disconnect(); /* release all */ j_recog_free(recog); if (logfile) fclose(fp); return(0); }
/* Creates the rubinius object universe from scratch. */ void cpu_bootstrap(STATE) { OBJECT cls, obj, tmp, tmp2; int i; /* Class is created first by hand, and twittle to setup the internal recursion. */ cls = NEW_OBJECT(Qnil, CLASS_FIELDS); cls->klass = cls; class_set_instance_fields(cls, I2N(CLASS_FIELDS)); class_set_has_ivars(cls, Qtrue); class_set_object_type(cls, I2N(ClassType)); cls->obj_type = ClassType; BC(class) = cls; obj = _object_basic_class(state, Qnil); BC(object) = obj; BC(module) = _module_basic_class(state, obj); class_set_superclass(cls, BC(module)); BC(metaclass) = _metaclass_basic_class(state, cls); class_set_object_type(BC(metaclass), I2N(MetaclassType)); BC(tuple) = _tuple_basic_class(state, obj); BC(hash) = _hash_basic_class(state, obj); BC(lookuptable) = _lookuptable_basic_class(state, obj); BC(methtbl) = _methtbl_basic_class(state, BC(lookuptable)); object_create_metaclass(state, obj, cls); object_create_metaclass(state, BC(module), object_metaclass(state, obj)); object_create_metaclass(state, BC(class), object_metaclass(state, BC(module))); object_create_metaclass(state, BC(tuple), (OBJECT)0); object_create_metaclass(state, BC(hash), (OBJECT)0); object_create_metaclass(state, BC(lookuptable), (OBJECT)0); object_create_metaclass(state, BC(methtbl), (OBJECT)0); module_setup_fields(state, object_metaclass(state, obj)); module_setup_fields(state, object_metaclass(state, BC(module))); module_setup_fields(state, object_metaclass(state, BC(class))); module_setup_fields(state, object_metaclass(state, BC(tuple))); module_setup_fields(state, object_metaclass(state, BC(hash))); module_setup_fields(state, object_metaclass(state, BC(lookuptable))); module_setup_fields(state, object_metaclass(state, BC(methtbl))); BC(symbol) = _symbol_class(state, obj); BC(array) = _array_class(state, obj); BC(bytearray) = _bytearray_class(state, obj); BC(string) = _string_class(state, obj); BC(symtbl) = _symtbl_class(state, obj); BC(cmethod) = _cmethod_class(state, obj); BC(io) = _io_class(state, obj); BC(blokenv) = _blokenv_class(state, obj); BC(icache) = _icache_class(state, obj); BC(staticscope) = _staticscope_class(state, obj); class_set_object_type(BC(bytearray), I2N(ByteArrayType)); class_set_object_type(BC(string), I2N(StringType)); class_set_object_type(BC(methtbl), I2N(MTType)); class_set_object_type(BC(tuple), I2N(TupleType)); class_set_object_type(BC(hash), I2N(HashType)); class_set_object_type(BC(lookuptable), I2N(LookupTableType)); /* The symbol table */ state->global->symbols = symtbl_new(state); module_setup(state, obj, "Object"); module_setup(state, cls, "Class"); module_setup(state, BC(module), "Module"); module_setup(state, BC(metaclass), "MetaClass"); module_setup(state, BC(symbol), "Symbol"); module_setup(state, BC(tuple), "Tuple"); module_setup(state, BC(array), "Array"); module_setup(state, BC(bytearray), "ByteArray"); module_setup(state, BC(hash), "Hash"); module_setup(state, BC(lookuptable), "LookupTable"); module_setup(state, BC(string), "String"); module_setup(state, BC(symtbl), "SymbolTable"); module_setup(state, BC(methtbl), "MethodTable"); module_setup(state, BC(cmethod), "CompiledMethod"); module_setup(state, BC(io), "IO"); module_setup(state, BC(blokenv), "BlockEnvironment"); module_setup(state, BC(icache), "InlineCache"); module_setup(state, BC(staticscope), "StaticScope"); class_set_object_type(BC(array), I2N(ArrayType)); class_set_object_type(BC(cmethod), I2N(CMethodType)); class_set_object_type(BC(blokenv), I2N(BlockEnvType)); rbs_const_set(state, obj, "Symbols", state->global->symbols); BC(nil_class) = rbs_class_new(state, "NilClass", 0, obj); BC(true_class) = rbs_class_new(state, "TrueClass", 0, obj); BC(false_class) = rbs_class_new(state, "FalseClass", 0, obj); tmp = rbs_class_new(state, "Numeric", 0, obj); tmp2 = rbs_class_new(state, "Integer", 0, tmp); BC(fixnum_class) = rbs_class_new(state, "Fixnum", 0, tmp2); class_set_object_type(BC(fixnum_class), I2N(FixnumType)); BC(bignum) = rbs_class_new(state, "Bignum", 0, tmp2); class_set_object_type(BC(bignum), I2N(BignumType)); bignum_init(state); BC(floatpoint) = rbs_class_new(state, "Float", 0, tmp); class_set_object_type(BC(floatpoint), I2N(FloatType)); BC(undef_class) = rbs_class_new(state, "UndefClass", 0, obj); BC(fastctx) = rbs_class_new(state, "MethodContext", 0, obj); BC(methctx) = BC(fastctx); BC(blokctx) = rbs_class_new(state, "BlockContext", 0, BC(fastctx)); BC(task) = rbs_class_new(state, "Task", 0, obj); class_set_object_type(BC(task), I2N(TaskType)); BC(iseq) = rbs_class_new(state, "InstructionSequence", 0, BC(bytearray)); class_set_object_type(BC(iseq), I2N(ISeqType)); #define bcs(name, sup, string) BC(name) = _ ## name ## _class(state, sup); \ module_setup(state, BC(name), string); /* the special_classes C array is use do quickly calculate the class of an immediate by just indexing into the array using (obj & 0x1f) */ /* fixnum, symbol, and custom can have a number of patterns below 0x1f, so we fill them all. */ for(i = 0; i < SPECIAL_CLASS_SIZE; i += 4) { state->global->special_classes[i + 0] = Qnil; state->global->special_classes[i + 1] = BC(fixnum_class); state->global->special_classes[i + 2] = Qnil; if(((i + 3) & 0x7) == 0x3) { state->global->special_classes[i + 3] = BC(symbol); } else { state->global->special_classes[i + 3] = CUSTOM_CLASS; } } /* These only have one value, so they only need one spot in the array */ state->global->special_classes[(intptr_t)Qundef] = BC(undef_class); state->global->special_classes[(intptr_t)Qfalse] = BC(false_class); state->global->special_classes[(intptr_t)Qnil ] = BC(nil_class); state->global->special_classes[(intptr_t)Qtrue ] = BC(true_class); bcs(regexp, obj, "Regexp"); class_set_object_type(BC(regexp), I2N(RegexpType)); bcs(regexpdata, obj, "RegexpData"); class_set_object_type(BC(regexpdata), I2N(RegexpDataType)); bcs(matchdata, obj, "MatchData"); cpu_bootstrap_exceptions(state); rbs_module_new(state, "Rubinius", BC(object)); Init_list(state); Init_cpu_task(state); Init_ffi(state); regexp_init(state); selector_init(state); send_site_init(state); rbs_const_set(state, rbs_const_get(state, BASIC_CLASS(object), "Rubinius"), "Primitives", cpu_populate_prim_names(state)); state->global->external_ivars = lookuptable_new(state); }
PyMODINIT_FUNC init_GPIO(void) #endif { PyObject *module = NULL; #if PY_MAJOR_VERSION > 2 if ((module = PyModule_Create(&rpigpiomodule)) == NULL) goto exit; #else if ((module = Py_InitModule("_GPIO", rpi_gpio_methods)) == NULL) goto exit; #endif WrongDirectionException = PyErr_NewException("RPIO.Exceptions.WrongDirectionException", NULL, NULL); PyModule_AddObject(module, "WrongDirectionException", WrongDirectionException); InvalidModeException = PyErr_NewException("RPIO.Exceptions.InvalidModeException", NULL, NULL); PyModule_AddObject(module, "InvalidModeException", InvalidModeException); InvalidDirectionException = PyErr_NewException("RPIO.Exceptions.InvalidDirectionException", NULL, NULL); PyModule_AddObject(module, "InvalidDirectionException", InvalidDirectionException); InvalidChannelException = PyErr_NewException("RPIO.Exceptions.InvalidChannelException", NULL, NULL); PyModule_AddObject(module, "InvalidChannelException", InvalidChannelException); InvalidPullException = PyErr_NewException("RPIO.Exceptions.InvalidPullException", NULL, NULL); PyModule_AddObject(module, "InvalidPullException", InvalidPullException); ModeNotSetException = PyErr_NewException("RPIO.Exceptions.ModeNotSetException", NULL, NULL); PyModule_AddObject(module, "ModeNotSetException", ModeNotSetException); high = Py_BuildValue("i", HIGH); PyModule_AddObject(module, "HIGH", high); low = Py_BuildValue("i", LOW); PyModule_AddObject(module, "LOW", low); output = Py_BuildValue("i", OUTPUT); PyModule_AddObject(module, "OUT", output); input = Py_BuildValue("i", INPUT); PyModule_AddObject(module, "IN", input); alt0 = Py_BuildValue("i", ALT0); PyModule_AddObject(module, "ALT0", alt0); board = Py_BuildValue("i", BOARD); PyModule_AddObject(module, "BOARD", board); bcm = Py_BuildValue("i", BCM); PyModule_AddObject(module, "BCM", bcm); pud_off = Py_BuildValue("i", PUD_OFF); PyModule_AddObject(module, "PUD_OFF", pud_off); pud_up = Py_BuildValue("i", PUD_UP); PyModule_AddObject(module, "PUD_UP", pud_up); pud_down = Py_BuildValue("i", PUD_DOWN); PyModule_AddObject(module, "PUD_DOWN", pud_down); // detect board revision and set up accordingly cache_rpi_revision(); if (revision_int < 1) { PyErr_SetString(PyExc_SystemError, "This module can only be run on a Raspberry Pi!"); #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif } else if (revision_int == 1) { pin_to_gpio = &pin_to_gpio_rev1; gpio_to_pin = &gpio_to_pin_rev1; } else { // assume revision 2 pin_to_gpio = &pin_to_gpio_rev2; gpio_to_pin = &gpio_to_pin_rev2; } rpi_revision = Py_BuildValue("i", revision_int); PyModule_AddObject(module, "RPI_REVISION", rpi_revision); rpi_revision_hex = Py_BuildValue("s", revision_hex); PyModule_AddObject(module, "RPI_REVISION_HEX", rpi_revision_hex); version = Py_BuildValue("s", "0.10.1/0.4.2a"); PyModule_AddObject(module, "VERSION_GPIO", version); // set up mmaped areas if (module_setup() != SETUP_OK ) { #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif } if (Py_AtExit(cleanup) != 0) { cleanup(); #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif } exit: #if PY_MAJOR_VERSION > 2 return module; #else return; #endif }
static int riva_load(module_t *Module, const char *FileName) { riva_t *Riva = unew(riva_t); // This really should be new... module_setup(Module, Riva, (module_importer)riva_import); gzFile File = gzopen(FileName, "rb"); char *LoadPath; for (int I = strlen(FileName) - 1; I >= 0; --I) { if (FileName[I] == PATHCHR) { strncpy(LoadPath = (char *)GC_malloc_atomic(I + 2), FileName, I + 1); break; }; }; module_set_path(Module, LoadPath); uint32_t Magic; gzread(File, &Magic, 4); if (Magic != 0x41564952) { log_errorf("Error: %s is not a valid riva module\n", FileName); return 0; }; uint32_t NoOfSections; gzread(File, &NoOfSections, 4); uint32_t NoOfExports; gzread(File, &NoOfExports, 4); uint32_t NoOfRequires; gzread(File, &NoOfRequires, 4); jmp_buf OnError[1]; if (setjmp(OnError)) return 0; section_t **Sections = (Riva->Sections = (section_t **)GC_malloc(NoOfSections * sizeof(section_t *))); for (int I = 0; I < NoOfSections; ++I) Sections[I] = new(section_t); for (int I = 0; I < NoOfSections; ++I) { section_t *Section = Sections[I]; uint8_t Type; gzread(File, &Type, 1); switch (Type) { case SECT_CODE: { Section->Fixup = fixup_code_section; gzread(File, &Section->Flags, 1); uint32_t Length; gzread(File, &Length, 4); uint32_t NoOfRelocs; gzread(File, &NoOfRelocs, 4); Section->NoOfRelocs = NoOfRelocs; reloc_t *Relocs = (Section->Relocs = (reloc_t *)GC_malloc_uncollectable(NoOfRelocs * sizeof(reloc_t))); if (Section->Flags & FLAG_GC) { Section->Data = GC_malloc_uncollectable(Length); } else { Section->Data = GC_malloc_atomic_uncollectable(Length); }; gzread(File, Section->Data, Length); for (int J = 0; J < NoOfRelocs; ++J) { reloc_t *Reloc = &Relocs[J]; gzread(File, &Reloc->Size, 1); gzread(File, &Reloc->Flags, 1); gzread(File, &Reloc->Position, 4); uint32_t Index; gzread(File, &Index, 4); Reloc->Section = Sections[Index]; }; break;}; case SECT_LIBRARY: { Section->Fixup = fixup_library_section; gzread(File, &Section->Flags, 1); uint32_t Length; gzread(File, &Length, 4); gzread(File, Section->Name = (char *)GC_malloc_atomic(Length + 1), Length); Section->Name[Length] = 0; if (Section->Flags == LIBRARY_ABS) { Section->Path = 0; } else if (Section->Flags == LIBRARY_REL) { Section->Path = LoadPath; }; for (char *P = Section->Name; *P; ++P) if (*P == '/') *P = PATHCHR; break;}; case SECT_IMPORT: { Section->Fixup = fixup_import_section; gzread(File, &Section->Flags, 1); uint32_t Index; gzread(File, &Index, 4); Section->Library = Sections[Index]; uint32_t Length; gzread(File, &Length, 4); gzread(File, Section->Name = (char *)GC_malloc_atomic(Length + 1), Length); Section->Name[Length] = 0; break;}; case SECT_BSS: { Section->Fixup = fixup_bss_section; gzread(File, &Section->Flags, 1); uint32_t Size; gzread(File, &Size, 4); Section->Data = (uint8_t *)GC_malloc(Size); break;}; case SECT_SYMBOL: { Section->Fixup = fixup_symbol_section; gzread(File, &Section->Flags, 1); uint32_t Length; gzread(File, &Length, 4); gzread(File, Section->Name = (char *)GC_malloc_atomic(Length + 1), Length); Section->Name[Length] = 0; break;}; }; }; for (int I = 0; I < NoOfExports; ++I) { export_t *Export = new(export_t); gzread(File, &Export->Flags, 1); uint32_t Index; gzread(File, &Index, 4); Export->Section = Sections[Index]; gzread(File, &Export->Offset, 4); uint32_t Length; gzread(File, &Length, 4); char *Name = (char *)GC_malloc_atomic(Length + 1); gzread(File, Name, Length); Name[Length] = 0; stringtable_put(Riva->Exports, Name, Export); }; for (int I = 0; I < NoOfRequires; ++I) { uint8_t Flags; gzread(File, &Flags, 1); uint32_t Length; gzread(File, &Length, 4); char *Name = (char *)GC_malloc_atomic(Length + 1); char *Path = 0; gzread(File, Name, Length); Name[Length] = 0; if (Flags == LIBRARY_REL) Path = LoadPath; for (char *P = Name; *P; ++P) if (*P == '/') *P = PATHCHR; module_load(Path, Name); }; gzclose(File); void (*__init)(module_t *) = check_import(Riva, "__init", OnError); if (__init) __init(Module); void *Methods = check_import(Riva, "__methods", OnError); if (Methods) add_methods(Methods); return 1; };
void symbol_init(void) { Symbol = module_alias("Riva/Symbol"); module_setup(Symbol, 0, symbol_import0); };
PyMODINIT_FUNC initGPIO(void) #endif { PyObject *module = NULL; int revision = -1; #if PY_MAJOR_VERSION > 2 if ((module = PyModule_Create(&rpigpiomodule)) == NULL) return NULL; #else if ((module = Py_InitModule3("RPi.GPIO", rpi_gpio_methods, moduledocstring)) == NULL) return; #endif define_exceptions(module); define_constants(module); // detect board revision and set up accordingly revision = get_rpi_revision(); if (revision == -1) { PyErr_SetString(PyExc_RuntimeError, "This module can only be run on a Raspberry Pi!"); setup_error = 1; #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif } else if (revision == 1) { pin_to_gpio = &pin_to_gpio_rev1; } else { // assume revision 2 pin_to_gpio = &pin_to_gpio_rev2; } rpi_revision = Py_BuildValue("i", revision); PyModule_AddObject(module, "RPI_REVISION", rpi_revision); // set up mmaped areas if (module_setup() != SETUP_OK ) { setup_error = 1; #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif } // Add PWM class if (PWM_init_PWMType() == NULL) #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif Py_INCREF(&PWMType); PyModule_AddObject(module, "PWM", (PyObject*)&PWMType); // initialise events event_initialise(); if (!PyEval_ThreadsInitialized()) PyEval_InitThreads(); // register exit functions - last declared is called first if (Py_AtExit(cleanup) != 0) { setup_error = 1; cleanup(); #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif } if (Py_AtExit(event_cleanup) != 0) { setup_error = 1; cleanup(); #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif } #if PY_MAJOR_VERSION > 2 return module; #else return; #endif }
PyMODINIT_FUNC initGPIO(void) #endif { PyObject *module = NULL; #if PY_MAJOR_VERSION > 2 if ((module = PyModule_Create(&rpigpiomodule)) == NULL) goto exit; #else if ((module = Py_InitModule("Ox.GPIO", rpi_gpio_methods)) == NULL) goto exit; #endif WrongDirectionException = PyErr_NewException("Ox.GPIO.WrongDirectionException", NULL, NULL); PyModule_AddObject(module, "WrongDirectionException", WrongDirectionException); InvalidModeException = PyErr_NewException("Ox.GPIO.InvalidModeException", NULL, NULL); PyModule_AddObject(module, "InvalidModeException", InvalidModeException); InvalidDirectionException = PyErr_NewException("Ox.GPIO.InvalidDirectionException", NULL, NULL); PyModule_AddObject(module, "InvalidDirectionException", InvalidDirectionException); InvalidChannelException = PyErr_NewException("Ox.GPIO.InvalidChannelException", NULL, NULL); PyModule_AddObject(module, "InvalidChannelException", InvalidChannelException); InvalidPullException = PyErr_NewException("Ox.GPIO.InvalidPullException", NULL, NULL); PyModule_AddObject(module, "InvalidPullException", InvalidPullException); ModeNotSetException = PyErr_NewException("Ox.GPIO.ModeNotSetException", NULL, NULL); PyModule_AddObject(module, "ModeNotSetException", ModeNotSetException); SetupException = PyErr_NewException("Ox.GPIO.SetupException", NULL, NULL); PyModule_AddObject(module, "SetupException", SetupException); high = Py_BuildValue("i", HIGH); PyModule_AddObject(module, "HIGH", high); low = Py_BuildValue("i", LOW); PyModule_AddObject(module, "LOW", low); output = Py_BuildValue("i", OUTPUT); PyModule_AddObject(module, "OUT", output); input = Py_BuildValue("i", INPUT); PyModule_AddObject(module, "IN", input); version = Py_BuildValue("s", "0.4.1a"); PyModule_AddObject(module, "VERSION", version); // set up mmaped areas if (module_setup() != SETUP_OK ) { #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif } if (Py_AtExit(gpio_close) != 0) { gpio_close(); #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif } exit: #if PY_MAJOR_VERSION > 2 return module; #else return; #endif }