Exemple #1
0
static void comparator_cb(void *param)
{
	struct td_device *dev = (struct td_device *)param;
	struct apds9190_info *ir_dev = (struct apds9190_info *)dev->priv;

	/* Disable comparator */
	comp_disable(ir_dev->comp_pin);

	/* Update sensor state */
	ir_dev->prox = !ir_dev->prox;

	/* Update thresholds */
	uint16_t l, h;
	if (ir_dev->prox) {
		l = ir_dev->pilt;
		h = 0xFFFF;
	} else {
		l = 0;
		h = ir_dev->piht;
	}

	ir_dev->irq_tx_buff[1] = l;
	ir_dev->irq_tx_buff[2] = l >> 8;
	ir_dev->irq_tx_buff[3] = h;
	ir_dev->irq_tx_buff[4] = h >> 8;
	ir_dev->irq_tx_buff[0] = COMMAND_ENABLE | COMMAND_AI | REG_PILT;
	ir_dev->irq_req.callback = apds_update_threshold_callback;
	ir_dev->irq_req.tx_len = 5;
	sba_exec_dev_request((struct sba_device *)dev, &ir_dev->irq_req);

	/* Call user callback */
	if (ir_dev->cb) {
		ir_dev->cb(ir_dev->prox, ir_dev->cb_data);
	}
}
void comp_isr()
{
	struct cmp_cb *cmp_cb_tmp ;
	struct device* comparator_dev = &pf_device_soc_comparator;
	int i;
	cmp_cb_tmp = (struct cmp_cb*)(comparator_dev->priv);

	for (i = 0; i < CMP_COUNT; i++) {
		if (MMIO_REG_VAL(CMP_STAT_CLR) & (1 << i)) {
			comp_disable(i);
			if (cmp_cb_tmp[i].cb != NULL) {
				cmp_cb_tmp[i].cb(cmp_cb_tmp[i].cb_data);
			} else {
				pr_debug(LOG_MODULE_DRV,
					 "Unexpected comparator interrupt: %d",
					 i);
			}
			// Clear interrupt status to process next IRQ
			MMIO_REG_VAL(CMP_STAT_CLR) |= (1 << i);
		}
	}
}
Exemple #3
0
uint8_t http_process_url(char* first_char, uint8_t length, void* jsonvoid) {
    char temp[80];
    Json* json = (Json*) jsonvoid;
    uint8_t temp_len = length;
    
    HttpApiInfo api_info;
    http_api_info_ctor(&api_info);
    
    strncpy(temp, first_char, 80);
    
    if(!strncmp(temp, "/a/", 3)) {
        //ok, we have an api command
        advance_string(temp, &temp_len, 3);
        //!printf("we have a web API command: leftover %s\n", temp);
        
        if( ((temp[0] == 'o') || (temp[0] == 'i')) && (temp[1] == '/') ) {
            //we have an input or an output being specified
            //!printf("input/output status: %c\n", temp[0]);
            http_api_info_set_io(&api_info, ( (temp[0] == 'i') ? INPUT : OUTPUT ));
            
            advance_string(temp, &temp_len, 2);
            //!printf("%s\n",temp);
            //now we need to find the channel number
            uint8_t testnum = get_channel_number(temp,&temp_len);
            Io_enum io = (Io_enum) http_api_info_get_io(&api_info);
            
            if ( (testnum > 0) && (http_api_info_set_chan_num(&api_info, testnum) > 0) ) {
                Channel* tempchan = get_channel_from_memory(io, testnum);
                
                //make sure a channel according to those specifications exists.  if not, return no match.	
                if ( tempchan == NULL )	return 0;
                
                if (!strncmp(temp, "eqparams", 7)) {
                	json_encode_eq(tempchan, json);
                    //!printf("eqparams!!\n");
                    return 1;
                } else if(!strncmp(temp,"modeq",5)) {
                	advance_string(temp, &temp_len, 5);
                    extract_query_params(temp, &temp_len, http_api_info_get_params(&api_info));
                    float band_num = map_get_value_by_key(http_api_info_get_params(&api_info),"b");
                    float eq_type = map_get_value_by_key(http_api_info_get_params(&api_info),"t");
                    float eq_q = map_get_value_by_key(http_api_info_get_params(&api_info),"q");
                    float eq_freq = map_get_value_by_key(http_api_info_get_params(&api_info),"f");
                    float eq_gain = map_get_value_by_key(http_api_info_get_params(&api_info),"g");
                    float eq_enable = map_get_value_by_key(http_api_info_get_params(&api_info),"e");
                    
                    if( (band_num >= 1) && (band_num <= 4 ) ) {
                    	//EqBand* temp_eq_band = channel_get_eqband(tempchan, (uint8_t) band_num);
                    	
                    	//eqband_set_type(temp_eq_band, (Eq_type_enum)(eq_type));
                    	//eqband_set_bw(temp_eq_band, eq_q);
                    	//eqband_set_freq(temp_eq_band, eq_freq);
                    	//eqband_set_gain(temp_eq_band, eq_gain);
                    	//( (uint8_t)eq_enable == ENABLED) ? eqband_enable(temp_eq_band) : eqband_disable(temp_eq_band);
                    	
                    	Api_set_eqband_type(tempchan, (uint8_t) band_num, (Eq_type_enum)(eq_type));
                    	Api_set_eqband_bw(tempchan, (uint8_t) band_num, eq_q);
                    	Api_set_eqband_freq(tempchan, (uint8_t)band_num, eq_freq);
                    	Api_set_eqband_gain(tempchan, (uint8_t)band_num, eq_gain);
                    	( (uint8_t)eq_enable == ENABLED) ? Api_enable_eqband(tempchan, (uint8_t)band_num) : Api_disable_eqband(tempchan, (uint8_t)band_num);
                    	
                    	
                    	
                    	json_encode_ok(json);
                    	return 1;
                    } else return 0;
                    
                	
                } else if (!strncmp(temp, "compparams", 9)) {
                	json_encode_comp(tempchan, json);
                    //!printf("compparams!!\n");
                    return 1;
                } else if (!strncmp(temp,"modcomp",7)) {
                	//!printf("modcomp!\n");
                	advance_string(temp, &temp_len, 7);
                	
                    extract_query_params(temp, &temp_len, http_api_info_get_params(&api_info));
                    float ratio = map_get_value_by_key(http_api_info_get_params(&api_info),"r");
                    float threshold = map_get_value_by_key(http_api_info_get_params(&api_info),"t");
                    float attack = map_get_value_by_key(http_api_info_get_params(&api_info),"a");
                    float release = map_get_value_by_key(http_api_info_get_params(&api_info),"rls");
                    float gain = map_get_value_by_key(http_api_info_get_params(&api_info),"g");
                    float enable = map_get_value_by_key(http_api_info_get_params(&api_info),"e");

					Comp* temp_comp = channel_get_comp(tempchan);
                    comp_set_ratio(temp_comp, ratio);
                    comp_set_threshold(temp_comp,threshold);
                    comp_set_attack(temp_comp,attack);
                    comp_set_release(temp_comp,release);
                    comp_set_gain(temp_comp, gain);
                    ( (uint8_t)enable == ENABLED) ? comp_enable(temp_comp) : comp_disable(temp_comp);
                    	
                    json_encode_ok(json);
                    return 1;
                } else if (!strncmp(temp,"rename?name=",12)) {
                    //!printf("rename channel!!!");
                    advance_string(temp, &temp_len, 12);
                	//!printf("\nname: %s\n", temp);
                	
                	char ts[20];
                	strcpy(ts, temp);
                	
                	//allow A-Z, a-z, 0-9, -, _
                	//convert + to space
                	uint8_t j = 0;
                	uint8_t good_length = 0;
                	for(j=0; j < strlen(ts); j++) {
                		if ( ( (ts[j] <= 0x39) && (ts[j] >= 0x30) ) || 
                			 ( (ts[j] <= 0x5A) && (ts[j] >= 0x41) ) ||
                			 ( (ts[j] <= 0x7A) && (ts[j] >= 0x61) ) ||
                			 (ts[j] == 0x20) || (ts[j] == 0x5F) ||
                			 (ts[j] == 0x2D) || (ts[j] == 0x2B)
                			) {
                				if ( ts[j] == 0x2B ) ts[j] = 0x20;
                				good_length++;
                		} else break;
                	}
                	                    
                    channel_set_name(tempchan, ts);
                    json_encode_ok(json);
                    return 1;
                    
                } else {
                    //ERROR
                    //!printf("ERROR: not eqparams, compparams, or rename\n");
                }
                
            } else if (!strncmp(temp, "chanlist", 8)) {
                //return a list of channel data
                if ( io == INPUT) {
                	json_encode_channels(INPUT,NUM_INPUT_CHANNELS, json);
                	return 1;
                } else if ( io == OUTPUT) {
                	json_encode_channels(OUTPUT,NUM_OUTPUT_CHANNELS,json);
                	return 1;
                } else return 0;
                
            } else {
                //ERROR
                //!printf("ERROR: what error is this?\n");
            }
            
        } else if (temp[0] == 's') {
            //!printf("we are requesting a status\n");
            advance_string(temp, &temp_len, 2);
            if(!strncmp(temp,"bob",3)) {
                //!printf("return the bob status info\n");
            } else if(!strncmp(temp,"clip",4)) {
                //!printf("return clip information\n");
            } else {
                //!printf("no matching status api command\n");
            }
            
            
        } else if(temp[0] == 'm' && temp[1] == '/') {
            advance_string(temp, &temp_len, 2);
            //!printf("we are requesting routing matrix\n");
            if ( (http_api_info_set_chan_num(&api_info, get_channel_number(temp, &temp_len))) > 0) {
                //!printf("matrix output chan number: %d \n", http_api_info_get_chan_num(&api_info));
                
                if(!strncmp(temp, "modroute", 8)) {
                    //!printf("now we're modifying a route\n");
                    advance_string(temp, &temp_len, 8);
                    extract_query_params(temp, &temp_len, http_api_info_get_params(&api_info));
                    map_get_value_by_key(http_api_info_get_params(&api_info),"i");
                    char test[5];
                    strncpy(test, "blah",4);
                    map_get_value_by_key(http_api_info_get_params(&api_info), test);
                }
                
            }
            
        } else {
            //ERROR
            //!printf("ERROR: incorrect api command identifier\n");
            return 0;
        }
    } else {
        //printf("we don't have a web API command\n");
        return 0;
        //we don't have an API command... send it to the filesystem
    }
    //!printf("channel number: %d\n\n\n", http_api_info_get_chan_num(&api_info));
    return 0;
}