ET_API int EiLoadPlugin(const char *lib) { void *handle; int *pluginType; //char *name; bool (*load)(int i, EtPlugin *); char *error; handle = dlopen (lib, RTLD_LAZY); if (!handle) { fputs (dlerror(), stderr); exit(1); } else { load = dlsym(handle, "load"); EtPlugin *plugin = (EtPlugin *) malloc(sizeof(EtPlugin)); int i; load(i,plugin); printf("Loaded %s\n",plugin->name); buf_push(EtPluginRegistry.names, plugin->name); buf_push(EtPluginRegistry.plugins, *plugin); } if ((error = dlerror()) != NULL) { fputs(error, stderr); //printf("\nBar\n"); exit(1); } //dlclose(handle); }
int main(){ buf_initialise(9); //queue_clear(); buf_push(8); buf_pop_front(); buf_push(9); buf_push(10); buf_push(11); buf_pop_back(); buf_pop_front(); buf_deact(); return 0; }
void mesh_add_index(struct mesh *mesh, int vi, int ni) { struct idx idx; idx.vi = vi; idx.ni = ni; buf_push(mesh->ibuf, idx); }
/** Send a byte to the I2C partner. \param data The byte to be buffered/sent. \param last_byte Wether this is the last byte of a transmission. This implementation assumes to talk to mostly one communications client. To set the target, or to change it between transmissions, call i2c_init(). Unlike many other protocols (serial, SPI), I2C has an explicite transmission start and transmission end. Invoking code has to tell wether the given byte is the last byte of a transmission, so sending code can properly end it. This function has been tested to properly distinguish between individual transmissions separated by last_byte. Other than setting this flag, invoking code doesn't have to care about distinction, but may experience substantial delays (up to several milliseconds) if the bus is already busy with a distinct previous transmission. Data is buffered, so this returns quickly for small amounts of data. Large amounts don't get lost, but this function has to wait until sufficient previous data was sent. To avoid unexpected delays, invoking code can check for bus availability with i2c_busy(). Note that calling code has to send bytes quickly enough to not drain the buffer. It looks like the I2C protocol doesn't, unlike e.g. SPI, allow to pause sending without dropping the transmission. Positive of this limitation is, one can end a transmisson by simply not writing for a while, until it's sure the buffer became empty. */ void i2c_write(uint8_t data, uint8_t last_byte) { // Drop characters until transmission end. Transmissions to the display // start with a command byte, so sending truncated transmissions is harmful. if (i2c_state & I2C_ERROR) { if (last_byte) { i2c_state &= ~I2C_ERROR; } return; } while (i2c_should_end || ! buf_canwrite(send)) { delay_us(10); } if ( ! (i2c_state & I2C_MODE_BUSY)) { // No transmission ongoing, start one. i2c_state = I2C_MODE_SAWP; TWCR = (1<<TWINT)|(0<<TWEA)|(1<<TWSTA)|(0<<TWSTO)|(1<<TWEN)|(1<<TWIE); i2c_state |= I2C_MODE_BUSY; } ATOMIC_START buf_push(send, data); i2c_should_end = last_byte; ATOMIC_END }
/************************************** ********* Public Functions *********** *************************************/ EtNode EiNode(const EtChar *name) { EtNode *temp = malloc(sizeof(EtNode)); temp->params = NULL; temp->data = NULL; // the default name should be the name of the plugin plus a random hash temp->name = name; // get the plugin EtPlugin *plugin = EiGetPlugin(name); // if plugin is null then throw an execption and kill the program. plugin->mtds->dmethods->setParams(temp); plugin->mtds->dmethods->init(plugin); // initialize the data int i; for (i=0; i < buf_len(temp->params); i++) { buf_push(temp->data,temp->params[i].def); } /* switch (plugin->pluginType) { case EI_PLUGIN_CAMERA : { EtCameraData *camd = (EtCameraData*)plugin->data; temp->data = camd; break; } } */ return *temp; }
/// send one character void serial_writechar(uint8_t data) { // check if interrupts are enabled if (SREG & MASK(SREG_I)) { // if they are, we should be ok to block since the tx buffer is emptied from an interrupt for (;buf_canwrite(tx) == 0;); buf_push(tx, data); } else { // interrupts are disabled- maybe we're in one? // anyway, instead of blocking, only write if we have room if (buf_canwrite(tx)) buf_push(tx, data); } // enable TX interrupt so we can send this character UCSR0B |= MASK(UDRIE0); }
/** Prints a character at the current cursor position. \param data The character to be displayed. This code is identical for all display buses and display types, because it just queues up the character. In case the buffer is full already it waits for a millisecond to allow data to be sent to the display, then it tries again. If it still fails then, it drops the character. This way we're fairly protected against data loss, still we guarantee to not hang forever. */ void display_writechar(uint8_t data) { if ( ! buf_canwrite(display)) { delay_ms(1); } if (buf_canwrite(display)) { buf_push(display, data); } }
int main(int argc, char* argv[]){ buf_initialise(atoi(argv[1]),atoi(argv[2])); srand(time(NULL)); queue_clear(); while(1){ buf_push(1000*(rand()%100)); } return 0; }
int request_body(http_parser* parser, char *at, size_t length){ struct session * s = parser->data; if(config.catch_post_len>0){ if(s->request_multipart == IS_MULTIPART){ debug("multipart"); }else{ char *p = 0; if(s->post_buf_len>0){ int last_post_buf_len = s->post_buf_len; buf_push(s, at, length); p = parse_string('&', s->post_buf, s->post_buf_len, T_POST, config.catch_post, config.catch_post_len, s, 0); if(p > s->post_buf){ int next = p - s->post_buf - last_post_buf_len; at += next; length -= next; s->post_buf_len = 0; }else if(p==0){ s->post_buf_len = 0; } } if(s->post_buf_len == 0){ p = parse_string('&', at, length, T_POST, config.catch_post, config.catch_post_len, s, 0); if(p){ int more = length-(p-at); if(more<POST_BUF_LENGTH){ buf_push(s, p, more); } } } } } return 0; }
void mesh_begin_face(struct mesh *mesh) { buf_push(mesh->faces, buf_len(mesh->ibuf)); }
void mesh_add_normal(struct mesh *mesh, const float *n) { buf_push(mesh->nbuf, n[0]); buf_push(mesh->nbuf, n[1]); buf_push(mesh->nbuf, n[2]); }
void mesh_add_vertex(struct mesh *mesh, const float *v) { buf_push(mesh->vbuf, v[0]); buf_push(mesh->vbuf, v[1]); buf_push(mesh->vbuf, v[2]); }