static int bq27541_resume(struct device *dev) { struct bq27541_chip *chip = dev_get_drvdata(dev); disable_irq_wake(chip->low_bat_irq); get_battery_info(chip); schedule_delayed_work(&chip->battery_dwork, REFRESH_POLL); return 0; }
static void battery_work(struct work_struct *work) { struct bq27541_chip *chip = container_of(work, struct bq27541_chip, battery_dwork.work); get_battery_info(chip); power_supply_changed(&chip->fuelgauge); if(!delayed_work_pending(&chip->battery_dwork)) schedule_delayed_work(&chip->battery_dwork, REFRESH_POLL); }
static int __devinit bq27541_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); struct bq27541_platform_data *pdata = client->dev.platform_data; struct bq27541_chip *chip; int ret; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) return -EIO; chip = kzalloc(sizeof(*chip), GFP_KERNEL); if (!chip) return -ENOMEM; chip->bat_info.health = POWER_SUPPLY_HEALTH_GOOD; chip->debug = 0; chip->client = client; chip->low_bat_gpio = pdata->low_bat_gpio; chip->wakeup = pdata->wakeup; i2c_set_clientdata(client, chip); chip->fuelgauge.name = "fuelgauge"; chip->fuelgauge.type = POWER_SUPPLY_TYPE_BATTERY; chip->fuelgauge.get_property= bq27541_get_property; chip->fuelgauge.properties = bq27541_battery_props; chip->fuelgauge.num_properties = ARRAY_SIZE(bq27541_battery_props); ret = power_supply_register(&client->dev, &chip->fuelgauge); if (ret) { dev_err(&client->dev, "failed: power supply register\n"); goto err_free; } /* initialize fuel gauge registers */ ret = i2c_smbus_write_word_data(client, bq27541CMD_AR_LSB, AVERAGE_DISCHARGE_CURRENT_MA); if (ret) { dev_err(&client->dev, "failed: initial fuel gauge\n"); goto err_init; } INIT_DELAYED_WORK(&chip->battery_dwork, battery_work); chip->low_bat_irq = ret = gpio_to_irq(chip->low_bat_gpio); if (ret < 0) { dev_err(&client->dev, "failed: get irq number\n"); goto err_init; } ret = request_threaded_irq(chip->low_bat_irq, NULL, lowbat_irq_thread, IRQF_TRIGGER_FALLING|IRQF_ONESHOT, "low_bat", chip); if (ret < 0) { dev_err(&client->dev, "failed: request irq%d\n", chip->low_bat_irq); goto err_init; } ret = device_create_file(chip->fuelgauge.dev, &dev_attr_debug); if (ret) { dev_err(&client->dev, "failed: device_create_file\n"); goto err_irq; } #ifdef LOG do { create_proc_read_entry("fuelgauge_info", 0, NULL, fg_proc_read, NULL); battery_log_head = kzalloc(sizeof(struct battery_log) * LOG_SIZE, GFP_KERNEL); if(battery_log_head == NULL) goto err_irq; log_index = 0; } while(0); #endif get_battery_info(chip); schedule_delayed_work(&chip->battery_dwork, REFRESH_POLL); ret = device_init_wakeup(&client->dev, chip->wakeup); if (ret < 0) { dev_err(&client->dev, "failed: device_init_wakeup\n"); goto err_irq; } return 0; err_irq: free_irq(chip->low_bat_irq, chip); err_init: power_supply_unregister(&chip->fuelgauge); err_free: kfree(chip); return ret; }
int main(int argc, char** argv) { const uint8_t MAGIC_BYTE = 0x11; const uint8_t VERSION = 0x02; struct sockaddr_in saddr; int status; char hostname[255]; parse_options(argc, argv); if(gethostname(hostname, sizeof(hostname))) { perror("Infocast: gethostname"); exit(1); } int hlen = strlen(hostname) + 1; int len = 512; char* message = (char*)malloc(len); while(1) { unsigned char lanMacAddress[6]; unsigned char wifiMacAddress[6]; uint32_t ipLan, ipWLan; int8_t bat = (int8_t)(get_battery_info() * 100); uint8_t wifiStrength = get_wifi_quality(); uint8_t cpuTemp = get_cpu_temperature(); get_ip_address("eth0", ipLan, lanMacAddress); get_ip_address("wlan0", ipWLan, wifiMacAddress); char* start = message; *start = MAGIC_BYTE; start++; *start = VERSION; start++; WRITE(&ipLan, sizeof(ipLan)); WRITE(&ipWLan, sizeof(ipWLan)); WRITE(&bat, sizeof(bat)); WRITE(&cpuTemp, sizeof(cpuTemp)); WRITE(&wifiStrength, sizeof(wifiStrength)); WRITE(lanMacAddress, sizeof(lanMacAddress)); WRITE(wifiMacAddress, sizeof(wifiMacAddress)); memcpy(start, hostname, hlen); start += hlen; /* * We have to do this every iteration because we want see the Nao also * when a new interface becomes ready. For example eth0 gets an IP address * This should be no problem. Creating a socket is cheap. */ std::list<int> sockList = open_send_multicast_socket(saddr, multicast_ip.c_str(), multicast_port); for(std::list<int>::iterator it = sockList.begin(); it != sockList.end(); ++it) { int sock = *it; status = sendto(sock, message, start - message, 0, (struct sockaddr*)&saddr,sizeof(saddr)); close(sock); if(status < 0) perror("Infocast: sendto"); } sleep(5); } }