How can I print on this POS using Flutter - flutter

I try this function but doesn't work
Future<void> _connect(BluetoothDevice device) async {
if (device == null) {
show('No device selected.');
} else {
bluetooth.isConnected.then((isConnected) {
if (!isConnected!) {
bluetooth.printCustom("thermal pinter", 0, 1);
for (int i = 0; i < 2; i++) {
bluetooth.printCustom("Welcome", 0, 1);
bluetooth.printNewLine();
}
}
});
}
}

Hello and welcome on SO!
I don't know much about bluetooth printing or if the methods you're using exists and are used correctly, but at least I can notice that your code is sending the order to print when the printer is NOT connected.
See here:
if (!isConnected!) {
//the code below is executed only if isConnected is false, but seems like you want it to be the opposite
bluetooth.printCustom("thermal pinter", 0, 1);
for (int i = 0; i < 2; i++) {
bluetooth.printCustom("Welcome", 0, 1);
bluetooth.printNewLine();
}
}
Taking for granted that the code is correct, the line if (!isConnected!) will perform the code in the {} that follows only when the printer is not connected. Try removing the ! before isConnected and see if it works. Again, this is simply a wild guess judging on your variables name and such, I can't really say that the problem lies there.

Related

ESP32-CAM buffer

When I initialize the camera I use this:
#include "esp_camera.h"
bool initCamera(){
Serial.print("Iniciando Cámara ...");
camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = Y2_GPIO_NUM;
...
...
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
config.frame_size = FRAMESIZE_XGA;
config.jpeg_quality = 8;
config.fb_count = 1;
config.grab_mode = CAMERA_GRAB_LATEST; <<<<<<<
// camera init
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK){
Serial.printf("... error 0x%x", err);
return false;
}
sensor_t *s = esp_camera_sensor_get();
Serial.println("... OK");
CAMARA_OK = true;
return true;
}
But when I ask for a capture:
static esp_err_t capture_handler(httpd_req_t *req){
cambiosConfiguracion(req);
camera_fb_t *fb = NULL;
esp_err_t res = ESP_OK;
fb = esp_camera_fb_get();
if (!fb){
Serial.println("Camera capture failed");
httpd_resp_send_500(req);
return ESP_FAIL;
}
...
the image it shows me is from before, it takes a delayed capture.
I want that when I ask for a capture, it gives me the one from that moment, not the one stored in the buffer
I have the same problem, I've been looking for the solution for days and although it seems to be fine, it doesn't do what it's supposed to do.
At the moment I am using this "trick":
fb = esp_camera_fb_get();
esp_camera_fb_return(fb);
fb = esp_camera_fb_get();
I ask for a capture, I discard it and then I ask for another one, which is current

Limit on the number of NPCs

Such an idea, for which I don't even have any ideas how to do it right. In general, the thought is:
There are, say, three NPCs on the stage (Conditionally), and there is also one building (Conditionally). Each NPC has its own task, but I do not know how to take an NPC who does not have a task and send one NPC to work in the building, and not several at once. Namely, each NPC has work statuses, and there is also a status 0, meaning that the NPC is not busy, there may be several such "free" ones, and if one is assigned the status of work - go to the building, then everyone who has this status will go, but how can we make sure that only one free NPC is taken and sent there?
I know the question is as incomprehensible and terrible as possible, but maybe someone will understand...
I made, so, to begin with, the code:
File WorkingPlace:
public static bool SignalFreeNPCPoint = false;
public static int WorkingPlaceNPC = 0;
public void ProductBoardNPC()
{
SignalFreeNPCPoint = true;
WorkingPlaceNPC += 1;
}
public void ProductBoard_Stop()
{
WorkingPlaceNPC -= 1;
SignalFreeNPCPoint = true;
}
This "ProductBoardNPC()" and "ProductBoard_Stop()" method's for button in Unity.
File NPCSctipt:
public List<GameObject> ListGM = new List<GameObject>();
public int TaskNumber = 0;
void Update()
{
TaskManager();
LogicNPC();
}
private void TaskManager()
{
switch (TaskNumber)
{
case 0:
//You code
break;
case 1:
ListGM.Remove(gameObject);
break;
case 2:
ListGM.Remove(gameObject);
break;
case 3:
ListGM.Remove(gameObject);
break;
case 4:
ListGM.Remove(gameObject);
break;
}
}
private void LogicNPC()
{
if (WorkingPlace.SignalFreeNPCPoint == true)
{
if (TaskNumber == 0 & WorkingPlace.WorkingPlaceNPC == 1)
{
ListGM.Add(gameObject);
TaskNumber = 4;
}
if (TaskNumber == 4 & WorkingPlace.WorkingPlaceNPC == 0)
{
TaskNumber = 0;
}
WorkingPlace.SignalFreeNPCPoint = false;
}
}
How the code works:
When you click on the button, an NPC with the status 0 is searched, the last NPC with this status is taken and entered into the array, after which it is given a different status to perform "work", after which it is removed from the array to make room for another NPC.
In this case, the array is a buffer and is simply necessary. If you have better ideas than mine, I will be happy to listen)
The implementation is a clean bike made of crutches, but it works flawlessly. Yes, about FPS drawdowns, it doesn't seem to load the system much, if there are drawdowns, then write what to fix.

Toggle GPIO in Netdevice

Hy i wanted to toggle a GPIO pin always when i send a package. But I have a weird behafure sometimes my pin gets toggled and sometimes not. I checked my Kernel logs and there is no Information that the pin could not be toggled.
My Ops look like this:
static const struct net_device_ops stmuart_netdev_ops = {
.ndo_init = stmuart_netdev_init,
.ndo_uninit = stmuart_netdev_uninit,
.ndo_open = stmuart_netdev_open,
.ndo_stop = stmuart_netdev_close,
.ndo_start_xmit = stmuart_netdev_xmit,
.ndo_set_mac_address = eth_mac_addr,
.ndo_tx_timeout = stmuart_netdev_tx_timeout,
.ndo_validate_addr = eth_validate_addr,
};
So as far as i know the ndo_start_xmit method is called as soon as i want to send a package. so i only toggle my pin when this method is called. But when i look on my Oscilloscope i can see that the pin is only sometimes toggled.
My method for sending looks like this:
static netdev_tx_t
stmuart_netdev_xmit(struct sk_buff *skb, struct net_device *dev)
{
struct net_device_stats *n_stats = &dev->stats;
struct stmuart *stm = netdev_priv(dev);
u8 pad_len = 0;
int written;
u8 *pos;
spin_lock(&stm->lock);
gpiod_set_value(stm->rts_gpio, 1);
WARN_ON(stm->tx_left);
if (!netif_running(dev)) {
spin_unlock(&stm->lock);
netdev_warn(stm->net_dev, "xmit: iface is down\n");
goto out;
}
pos = stm->tx_buffer;
if (skb->len < STMFRM_MIN_LEN)
pad_len = STMFRM_MIN_LEN - skb->len;
pos += stmfrm_create_header(pos, skb->len + pad_len);
memcpy(pos, skb->data, skb->len);
pos += skb->len;
if (pad_len) {
memset(pos, 0, pad_len);
pos += pad_len;
}
pos += stmfrm_create_footer(pos);
netif_stop_queue(stm->net_dev);
written = serdev_device_write_buf(stm->serdev, stm->tx_buffer,
pos - stm->tx_buffer);
if (written > 0) {
stm->tx_left = (pos - stm->tx_buffer) - written;
stm->tx_head = stm->tx_buffer + written;
n_stats->tx_bytes += written;
}
spin_unlock(&stm->lock);
out:
gpiod_set_value(stm->rts_gpio, 0);
netif_trans_update(dev);
dev_kfree_skb_any(skb);
return NETDEV_TX_OK;
}
So i checked the netdevice.h but there i did not saw another method that gets called when the net device wants to send a package.
It seems to me like always when the netdevice sends a ARP-Request the pin gets not toggled.

I have two i2c devices. Both alone work well, but when I read from one, and then write to the other, the second one is not an ancknowledging

I have two devices MPU6050 and EEPROM 24C256. I can write and read from both alone. But when I try to read from MPU6050 and than write data to EEPROM in the same session, the EEPROM does not respond. I am using mbed OS libraries. And my question is.. Is it library, code or hardware problem?
MPU6050 read sequence:
enter image description here
EEPROM write page sequance:
enter image description here
//CODE
const char imuAddress = 0x68<<1;
const char imuDataAddress = 0x3B;
const char eepAddress = 0xA0;
const char data[3] = {1.1, 2.2, 3.3};
char acc[3];
//reading acceleration data from IMU
while(true){
i2c.start();
if(i2c.write(imuAddress) != 1){
i2c.stop();
continue;
}
if(i2c.write(imuDataAddress) != 1){
i2c.stop();
continue;
}
i2c.start();
if(i2c.write(imuAddress | 0x01) != 1){
i2c.stop();
continue;
}
for (int i = 0; i < 2; i++){
i2c.read(1); //read and respond ACK to continue
}
i2c.read(0); //read and respond NACK to stop reading
i2c.stop();
break;
}
//write data to EEPROM
while(true){
i2c.start();
if(i2c.write(eepAddress) != 1){ //here is the problem (EEPROM does not respond)
i2c.stop();
continue;
}
if(i2c.write(0x00) != 1){
i2c.stop();
continue;
}
if(i2c.write(0x00) != 1){
i2c.stop();
continue;
}
bool ack = true;
for(int i = 0; i < 3; i++){
if(i2c.write(data[i]) != 1){
i2c.stop();
ack = false;
break;
}
}
if (ack == true){
i2c.stop();
break;
}
}
I have a couple initial thoughts, but do you have access to an oscilloscope? It is odd that each one works individually. This makes me think that it may be an issue between the transition. (Possibly try a delay between each one? Also, possibly remove the stops in the initial read as they aren't necessary)
I think the best way to figure this out is to post a scope trace of the messaging for each one running individually and a trace of them running back to back.

Stdout redirection not working in iOS without debugger

I am trying to redirect output so I can send it over the network. For some reason if you run the code while debugger attached it works perfectly. Once you start the application in normal way the code freezes on the read function and never returns. If someone has any pointers I will highly appreciate it.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^(void) {
static int pipePair[2];
if ( pipe(pipePair) != 0) {
return;
}
dup2(pipePair[1],STDOUT_FILENO);
while (true) {
char * buffer = calloc(sizeof(char), 1024);
ssize_t readCount = read(pipePair[0],buffer,1023);
if (readCount > 0) {
buffer[readCount] = 0;
NSString * log = [NSString stringWithCString:buffer encoding:NSUTF8StringEncoding];
//sent it over network
}
if (readCount == -1) {
return;
}
}
});
Apparently in iOS 5.1 writing to stdout was disallowed. http://spouliot.wordpress.com/2012/03/13/ios-5-1-vs-stdout/